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

StructuredContent Is Dropped From IsError=True Tool Results In Langchain-Mcp-Adapters

The langchain-mcp-adapters library discards structuredContent when an MCP tool returns isError=True. It raises _MCPToolExecutionError before reading the field and never attaches it to the resulting error ToolMessage, unlike the success path. This causes loss of machine-readable error payloads and leaves only a placeholder text when content is empty.

highConfidence 95%LangChainVector StoresEmbeddingsRetrieversAffected V0.3.2

Origin Analysis

In _convert_call_tool_result, the isError branch raises _MCPToolExecutionError(tool_content) before the structuredContent field is extracted into MCPToolArtifact. _MCPToolExecutionError stores only tool_content, and _handle_mcp_tool_error builds the ToolMessage without artifact, so structuredContent never reaches the model on error.
1. Set up an in-memory MCP server with a tool that returns CallToolResult(content=[], structuredContent={'code':'RATE_LIMITED','retry_after':30}, isError=True). 2. Load the tool via load_mcp_tools. 3. Invoke the tool with a tool_call input. 4. Observe that msg.status is 'error', msg.artifact is None, and msg.content is the placeholder 'MCP tool returned an error with empty content.' The same structuredContent appears as artifact when isError=False.

Fixing Code Block

Edge Case Audit

This change may expose artifact on error messages where downstream code previously expected None; update any such assumptions. Rollback by restoring the original three function definitions. Ensure the installed langchain-core version supports the artifact parameter on ToolMessage (the success path already uses it, so likely safe). Large structured error bodies could bloat messages; consider trimming in production if needed.

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