Repository navigation
fix(agentgateway): preserve MCP outputSchema through to the LLM tool definition - #384
Merged
Merged
Conversation
…definition MCP tools (e.g. MCP Builder-generated) advertise an outputSchema describing their structured result. The SDK dropped it: MCPTool had no field for it, so it never survived discovery nor reached the LangChain tool definition handed to the LLM. - _models.py: add optional MCPTool.output_schema - _compat.py: add mcp_output_schema() helper (snake/camel across mcp versions) - _lob.py / _customer.py: populate output_schema at both construction sites - converters.py: mcp_tool_to_langchain appends a pretty-printed 'Output schema (JSON):' block to the tool description (the only channel LangChain serializes into the LLM tool spec); tools without an output schema are unchanged.
NicoleMGomes
approved these changes
Oct 13, 2026
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.
What
MCP tools discovered via Agent Gateway (e.g. MCP Builder-generated tools) advertise an
outputSchemadescribing the shape of their structured result. The SDK was dropping it:MCPToolhad no field for it, so it never survived discovery and never reached theLangChain tool definition handed to the LLM.
This change carries
outputSchemafrom the MCPtools/listresponse all the way to theLLM-facing tool description.
Why
An agent built on LangChain + the Cloud SDK received a correct
tools/listresult butproduced an impoverished tool definition for the LLM, missing the tool's
outputSchema.Without it, the model has no description of the result shape it will get back.
mcp_tool_to_langchainappends a pretty-printedOutput schema (JSON):block to the tooldescription. This is the only channel LangChain serializes into the tool spec sent to the
LLM (
metadata/extrasare client-side only), so folding it into the description is thereliable way to surface it. Tools without an output schema are unchanged.