Skip to content

fix(mcp): carry each MCP tool's output schema, title and annotations - #97

Closed
hilariie wants to merge 1 commit into
mainfrom
claude/port-monorepo-pr-8f979a
Closed

hilariie wants to merge 1 commit into
mainfrom
claude/port-monorepo-pr-8f979a

Conversation

@hilariie

Copy link
Copy Markdown
Contributor

Port of genkit-ai/genkit#6903 (still open upstream), adapted to this repo's Tool API.

Why

An MCP server can declare an outputSchema, a title and annotations for a tool. Here, handles from get_active_tools() already sent the output schema to the model, but <client>:tool/* selectors did not, and the title and annotations were dropped on both paths.

Changes

  • mcp_tool_to_action sets the server's outputSchema as the tool's model_output_schema, so both paths send it. Tools without one still send none.
  • mcp_tools_to_handles only existed to add that schema to handles, so it is removed and get_active_tools() uses mcp_tools_to_actions.
  • metadata['mcp'] also holds the tool's title and annotations. Hints the server left out stay absent, and unknown keys are kept as sent. Neither is sent to the model.

How this differs from upstream

  • Upstream writes metadata[ORIGINAL_OUTPUT_SCHEMA_KEY] directly. Here the model_output_schema setter writes the same key, and also onto the tool.v2 wire action.
  • The README and the new client test read tool.metadata['mcp'], because a local Tool is itself the action (upstream: tool.action().metadata['mcp']).

Known gap: Gemini and $ref

The Gemini plugin rejects the whole request when a tool's output schema has a $ref outside $defs (e.g. #/properties/a from zod-to-json-schema, or draft-07 #/definitions/X). get_active_tools() handles and input schemas already hit this. This PR exposes selectors to it too. The fix is #90, which upstream #6903 calls "fixed separately"; ideally it lands first or alongside this.

Verification

  • uv run pytest packages/genkit-mcp: 263 passed. Ruff, ty and pyright clean.
  • All of upstream's new tests are ported: to_tool_definition with and without a declared schema, title/annotations kept or left out, generate through a selector and through get_active_tools() checking the request for fake_bad_output (declared schema) and fake_echo (none), and a stdio test that a selected tool and a listed handle both carry the fake server's title and annotations.
  • Reverting the schema line fails 5 tests; reverting the title/annotations lines fails 4.

Port of genkit-ai/genkit#6903, adapted to this repo's Tool API.

mcp_tool_to_action now sets the server's outputSchema as the tool's
model_output_schema, so <client>:tool/* selectors send it to the model
as get_active_tools() handles already did. mcp_tools_to_handles only
existed to add that schema, so it is removed. metadata['mcp'] also
keeps the tool's title and annotations, leaving out what the server
did not send.

Upstream-Commit: genkit-ai/genkit@6606da9
Upstream-PR: genkit-ai/genkit#6903
@hilariie hilariie closed this Nov 11, 2026
@hilariie
hilariie deleted the claude/port-monorepo-pr-8f979a branch November 11, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant