Skip to content

langchain-mcp-adapters ignores structuredContent field from MCP tool responses #283

@lzago

Description

@lzago

Bug Description

Hi,
I think langchain-mcp-adapters library is ignoring the structuredContent field from MCP CallToolResult responses, causing loss of
structured data that MCP servers provide. This violates the MCP specification (6/18/2025 MCP spec) and prevents LangChain applications from accessing structured data from MCP tools.

Current Behavior

The _convert_call_tool_result() function in langchain_mcp_adapters/tools.py only processes the content field from CallToolResult and
completely ignores the structuredContent field:

     def _convert_call_tool_result(
         call_tool_result: CallToolResult,
     ) -> tuple[str | list[str], list[NonTextContent] | None]:
         text_contents: list[str] = []
         non_text_contents: list[NonTextContent] = []

         # Only iterates through content, never touches structuredContent
         for content in call_tool_result.content:
             if isinstance(content, TextContent):
                 text_contents.append(content.text)
             # ... rest of processing

Expected Behavior

According to the MCP specification, CallToolResult includes both fields:
- content: list[ContentBlock] - Human-readable content
- structuredContent: dict[str, Any] | None - Machine-readable structured data

Reproduction Steps

  1. Create an MCP server that returns structured content:
     from fastmcp import FastMCP
     from mcp.types import CallToolResult, TextContent

     mcp = FastMCP("TestServer")

     @mcp.tool(output_schema={
         "type": "object",
         "properties": {
             "results": {"type": "array"},
             "count": {"type": "integer"}
         }
     })
     async def search(query: str) -> dict:
         results = [
             {"title": "Result 1", "url": "https://example.com/1"},
             {"title": "Result 2", "url": "https://example.com/2"}
         ]
         # This returns both content and structuredContent in MCP
         return {"results": results, "count": 2}
  1. Use langchain-mcp-adapters to call the tool:
    from langchain_mcp_adapters import load_mcp_tools

    async def test():
        tools = await load_mcp_tools(server_params)
        result = await tools[0].ainvoke({"query": "test"})
        print(result)  # Only contains text content, no structured data!
  1. Observe that the structured content ({"results": [...], "count": 2}) is completely lost.

Root Cause

The issue is in langchain_mcp_adapters/tools.py, specifically in:

  1. _convert_call_tool_result() function - Only processes content field
  2. MCPTool._arun() method - Only returns converted content, not structured data
  3. Return type is tuple[str | list[str], list[NonTextContent] | None] which has no place for structured content

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions