Skip to content

fix(mcp): preserve structured results and textless tool errors - #932

Open
rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-tool-result-envelope
Open

rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/mcp-tool-result-envelope

Conversation

@rudycelekli

Copy link
Copy Markdown

What changed

MCP tool results can carry structuredContent or flag isError without a text block. The client treated both as empty successes. Preserve errors regardless of content, and serialize structured content when there is no text for existing callers.

Protocol contract: https://modelcontextprotocol.io/specification/2025-11-25/server/tools

Validation

Two synthetic HTTP MCP regressions reproduce empty success on main. The complete mcpclient package tests and vet pass. Full platform and public browser tests were not run.

@Yanami-2K Yanami-2K left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对照 MCP tools 规范核对了 internal/mcpclient/client.go 的 CallToolContext:isError=true 无论有无文本都返回错误(无文本时用固定说明),不再被当成空成功;只有 structuredContent 没有 text 时把原始 JSON 作为结果返回,有 text 的旧调用方行为不变。错误文案从「只取第一个 content」变成「拼接所有 text 块」,属于合理增强。两个假 HTTP MCP 测试分别断言了错误和返回的 JSON 内容。提示:下一轮待审的 #935/#936/#939/#940 也在改 internal/mcpclient,先后合入可能需要 rebase。本 PR 只跑了开源扫描,合入前建议触发一次完整 CI。

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.

2 participants