AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Missing Output_schema Propagation From MCP Tool In Langchain-Mcp-Adapters

convert_mcp_tool_to_langchain_tool currently creates a StructuredTool using only the MCP tool's inputSchema for args_schema, but it never sets output_schema from tool.outputSchema. This silently drops the structured output contract advertised by the MCP server, preventing downstream structured output validation and forcing agents to treat tool results as opaque content.

highConfidence 85%LangchainMemoryAgentsRetrievers

Origin Analysis

The adapter function at tools.py#L426 passes args_schema but omits the corresponding output_schema parameter when constructing the StructuredTool. The MCP tool.outputSchema JSON Schema is therefore never converted into a Pydantic model and never attached to the LangChain tool, so LangChain has no way to know the expected response shape.
1. Define an MCP tool that declares an outputSchema (e.g., {'type':'object','properties':{'answer':{'type':'string'}}}). 2. Call convert_mcp_tool_to_langchain_tool(session, tool) from langchain_mcp_adapters. 3. Inspect the returned StructuredTool: tool.output_schema is None. 4. Use the tool in an agent with structured output expectations; the returned value is not validated or parsed according to the MCP outputSchema.

Fixing Code Block

Edge Case Audit

This change assumes that the installed langchain-core version includes an output_schema field on BaseTool/StructuredTool. Older versions will raise TypeError: unexpected keyword argument 'output_schema'. Verify support before deploying; if unsupported, pin a compatible version or fallback to manual validation. Additionally, if tool.outputSchema is not a valid JSON Schema or references unsupported types, create_pydantic_model_from_schema may throw, causing tool conversion to fail. Rollback by removing the output_schema assignment and the output_schema parameter from StructuredTool if any regression appears.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state