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%LangChainAffected 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