Skip to content

fix(agentgateway): preserve MCP outputSchema through to the LLM tool definition - #384

Merged
NicoleMGomes merged 2 commits into
SAP:mainfrom
prashantrakheja:feat/agw-output-schema
Oct 13, 2026
Merged

NicoleMGomes merged 2 commits into
SAP:mainfrom
prashantrakheja:feat/agw-output-schema

Conversation

@prashantrakheja

Copy link
Copy Markdown
Contributor

What

MCP tools discovered via Agent Gateway (e.g. MCP Builder-generated tools) advertise an
outputSchema describing the shape of their structured result. The SDK was dropping it:
MCPTool had no field for it, so it never survived discovery and never reached the
LangChain tool definition handed to the LLM.

This change carries outputSchema from the MCP tools/list response all the way to the
LLM-facing tool description.

Why

An agent built on LangChain + the Cloud SDK received a correct tools/list result but
produced 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_langchain appends a pretty-printed Output schema (JSON): block to the tool
description. This is the only channel LangChain serializes into the tool spec sent to the
LLM (metadata/extras are client-side only), so folding it into the description is the
reliable way to surface it. Tools without an output schema are unchanged.

…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.
@prashantrakheja
prashantrakheja requested a review from a team as a code owner October 12, 2026 20:18
@NicoleMGomes
NicoleMGomes merged commit f3319fd into SAP:main Oct 13, 2026
10 checks passed
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.

2 participants