Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the mcp_tool_to_action function to propagate the server's output schema to the model by setting the ORIGINAL_OUTPUT_SCHEMA_KEY metadata key on the generated action. It also includes updates to existing tests and a new test case to verify that the output schema is correctly passed. There are no review comments, so I have no feedback to provide.
d535af1 to
9ae52c1
Compare
huangjeff5
left a comment
There was a problem hiding this comment.
heads up: feat/py-mcp-host got rebased onto main today, so GitHub shows the whole genkit-mcp package as added and this conflicts. The real change is git diff d535af1cc..HEAD; that is what I reviewed. Conflicts are in _tools.py and mcp_tools_test.py.
Verified with a scripted model: last_request.tools[*].output_schema now carries the server schema on both <client>:tool/* and get_active_tools(), and the Dev UI shows originalOutputSchema and metadata.mcp. One thing I would want handled before merge is the Gemini $ref case below.
Side note, not asking for a change: JS types MCP outputs as z.any() and Go sets no output schema, so Python becomes the only runtime that hands the model the server output schema. Worth a line in the description so nobody aligns it back by accident.
huangjeff5
left a comment
There was a problem hiding this comment.
Approving so the stack can land on feat/py-mcp-host once it's rebased. The Gemini $ref comment still stands; fine as a follow-up on the feature branch, but I'd want it fixed before feat/py-mcp-host goes to main. When resolving the conflict, watch the strict=True zip against the base's collision skipping.
9ae52c1 to
e9ca2fe
Compare
f739cdb to
6606da9
Compare
There was a problem hiding this comment.
Re-checked on main: the threads hold (title/annotations left out when absent, no zip). Approving to land after #6969. At this head alone, a #/definitions/Item output schema fails Gemini with INVALID_ARGUMENT; with #6969 merged in, it converts.
Forwarding the server's outputSchema makes sense to me. The MCP spec intends it as a hint for clients and models, the tool output we send is structuredContent (which the spec says conforms to it), and native Python tools already send their output schema as Gemini FunctionDeclaration.response. So MCP tools now match native ones. Gemini is the only Python model plugin that reads ToolDefinition.output_schema; anthropic, compat-oai, ollama and bedrock ignore it.
For the description: the cross-SDK gap is in the Gemini plugin, not MCP. JS and Go never send a tool response to Gemini, even for native tools. Worth a line so nobody "aligns" the MCP side alone. ai.lookup_tool(...) also returns the schema now.
py/packages/genkit-mcp/src/genkit_mcp/_tools.py:319: nit: line 253 now stores the schema ataction.metadata[ORIGINAL_OUTPUT_SCHEMA_KEY], soby_nameis a second source for the same value. Reading it back from the action (aslookup_tooldoes) would let this drop the map.
| tools = await client.get_active_tools() | ||
| for tool in tools: | ||
| print(tool.name, tool.description) | ||
| # The server's display title and behaviour hints, when it sent them. |
There was a problem hiding this comment.
nit: this prints the whole metadata['mcp'], so prefix, tool and _meta too. Either print .get('title') / .get('annotations') or reword the comment.
|
Closing here as Python SDK development has moved to https://github.com/genkit-ai/genkit-python and this PR has already been re-opened there as genkit-ai/genkit-python#99. |
Why
An MCP server can declare an
outputSchema, atitleandannotationsfor a tool, but the client kept only the name, description and input schema. The model never saw the output schema:to_tool_definitionreads it from the action'soriginalOutputSchemametadata, and the MCP actions were built withgenkit.tool(), which leaves itNone. This applied to both<client>:tool/*selectors and the handles fromget_active_tools(). The title and the behaviour hints were dropped entirely. Part of #6194Changes
mcp_tool_to_actionstores the server'soutputSchemaunder the action'soriginalOutputSchemametadata, so both paths send it to the model. Tools without one still send none.metadata['mcp']now also holds the tool'stitleandannotations, with hints the server left out kept absent and unknown keys kept as sent. Neither is sent to the model.$refoutside$defs(#/definitions/...,#/properties/...), as it already does for input schemas. That is fixed separately in the Gemini plugin.Verification
to_tool_definitionfor an MCP action with and without a declared schema, and on the title and annotations it keeps.generatetests through a selector and throughget_active_tools()check the model request forfake_bad_output(declared schema) andfake_echo(none).