Skip to content

fix(smolagents): surface MCP tool execution errors with structured output - #96

Open
syf2211 wants to merge 1 commit into
grll:mainfrom
syf2211:fix/smolagents-structured-output-iserror
Open

syf2211 wants to merge 1 commit into
grll:mainfrom
syf2211:fix/smolagents-structured-output-iserror

Conversation

@syf2211

@syf2211 syf2211 commented Oct 13, 2026

Copy link
Copy Markdown

Summary

When SmolAgentsAdapter(structured_output=True) is used, failed MCP tool calls (isError=True) are no longer masked by returning structuredContent that looks like a successful result.

Motivation

Fixes #94. MCP distinguishes tool execution errors via isError and expects clients to surface those errors. The adapter returned structuredContent before checking isError, so an error with structuredContent={"results": []} was indistinguishable from a successful empty lookup.

Changes

  • Add _tool_execution_error_message() to collect TextContent text, or fall back to structuredContent / a generic message.
  • In MCPAdaptTool.forward(), raise ValueError when isError is set, before the structured-content fast path.
  • Add a regression test mirroring the issue reproduction.

Tests

  • python3 -m pytest tests/test_smolagents_adapter.py::test_structured_output_raises_on_tool_execution_error -q → 1 passed

Notes

Uses ValueError to match existing adapter error handling; smolagents wraps tool exceptions at the agent layer. Composer 2.5 review: APPROVE.

…tput

When structured_output is enabled, structuredContent was returned before
checking CallToolResult.isError, so failures could look like successful
empty results. Raise ValueError with text or structured error details
before returning structured payloads.

Fixes grll#94

This branch has not been deployed

No deployments
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.

SmolAgentsAdapter structured_output=True drops isError and the error text

1 participant