Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of genkit-ai/genkit#6903 (still open upstream), adapted to this repo's
ToolAPI.Why
An MCP server can declare an
outputSchema, atitleandannotationsfor a tool. Here, handles fromget_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_actionsets the server'soutputSchemaas the tool'smodel_output_schema, so both paths send it. Tools without one still send none.mcp_tools_to_handlesonly existed to add that schema to handles, so it is removed andget_active_tools()usesmcp_tools_to_actions.metadata['mcp']also holds the tool'stitleandannotations. 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
metadata[ORIGINAL_OUTPUT_SCHEMA_KEY]directly. Here themodel_output_schemasetter writes the same key, and also onto thetool.v2wire action.tool.metadata['mcp'], because a localToolis itself the action (upstream:tool.action().metadata['mcp']).Known gap: Gemini and
$refThe Gemini plugin rejects the whole request when a tool's output schema has a
$refoutside$defs(e.g.#/properties/afrom 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.to_tool_definitionwith and without a declared schema, title/annotations kept or left out,generatethrough a selector and throughget_active_tools()checking the request forfake_bad_output(declared schema) andfake_echo(none), and a stdio test that a selected tool and a listed handle both carry the fake server's title and annotations.