Skip to content

refactor: flatten tool args, keep responses as pydantic models#47

Merged
lorr1 merged 1 commit into
mainfrom
refactor/flatten-tool-args
Apr 23, 2026
Merged

refactor: flatten tool args, keep responses as pydantic models#47
lorr1 merged 1 commit into
mainfrom
refactor/flatten-tool-args

Conversation

@lorr1
Copy link
Copy Markdown
Collaborator

@lorr1 lorr1 commented Apr 23, 2026

Summary

MCP tools take flat arguments (e.g. name: str) instead of a single wrapper Pydantic model (request: HelloRequest). Responses are still Pydantic models so the output schema stays explicit and typed.

Why

Flat args surface each parameter as its own field in the MCP tool schema, which is how clients expect to call tools. A single wrapper model nests everything under a request field, which is noisier for callers and less idiomatic for MCP.

Changes

  • Drop HelloRequest from api/models.py; keep HelloResponse.
  • hello() in api/tools.py now takes name: str directly.
  • Update the Implementing New Tools README example to match, with a Key Points note spelling out the convention.

Test plan

  • task lint
  • task typecheck
  • task test — 11 unit tests pass, 3 integration tests skipped

MCP tool methods now take their arguments as flat parameters
(e.g. name: str) rather than a single wrapper Pydantic model
(request: HelloRequest). Responses stay as Pydantic models so the
tool still exposes an explicit typed output schema.

Flat args surface each parameter as its own field in the MCP tool
schema, which is how clients expect to call tools. Wrapping args
in a single request model nests everything under a "request"
field, which is noisier for callers and less idiomatic for MCP.

- Drop HelloRequest from api/models.py; keep HelloResponse.
- Update hello() in api/tools.py to take name: str directly.
- Update the Implementing New Tools README example to match, and
  add a Key Points note spelling out the flat-args / pydantic-
  response convention.
@lorr1 lorr1 merged commit 5f87402 into main Apr 23, 2026
6 checks passed
@lorr1 lorr1 deleted the refactor/flatten-tool-args branch April 23, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants