modelcontextprotocol / modelcontextprotocol/python-sdk

[v1.x] Server-side outputSchema validation blocks tool error reporting (isError: true)

未關閉
#2,429 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug fix proposed P2 ready for work
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Initial Checks
Description

When a tool handler returns unstructured content for an error case, the low-level server's call_tool decorator validates the output against outputSchema before checking if the response is an error.

This prevents tools with outputSchema from reporting errors via isError: true, as the validation fails with "outputSchema defined but no structured output returned", replacing the original error message.

This was already fixed in the TypeScript SDK via modelcontextprotocol/typescript-sdk#654 / PR #655 (2025-06-24), but the equivalent fix has not been applied to the Python SDK v1.x branch.

The issue is in src/mcp/server/lowlevel/server.py, the call_tool decorator handler:

  1. Line ~560: outputSchema validation runs unconditionally — should skip when the result is an error
  2. Line ~575: isError=False is hardcoded — there is no path for the handler to signal an error through unstructured content while outputSchema is defined
Example Code
from mcp.server.lowlevel import Server
from mcp import types

server = Server("test")

@server.call_tool()
async def call_tool(name: str, arguments: dict):
    # Tool has outputSchema but needs to return an error
    # This gets blocked by outputSchema validation
    return [types.TextContent(type="text", text="Resource not found")]
Python & MCP Python SDK
- Python: 3.11 / 3.12
- MCP SDK: v1.26.0+ (v1.x branch)

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

閱讀 src/mcp/server/lowlevel/server.py 約第 560 和 575 行附近的 call_tool decorator handler,然後比對 modelcontextprotocol/typescript-sdk#654 / PR #655 中對應的 TypeScript SDK 修正。確認錯誤路徑會略過 outputSchema validation,並為非結構化工具錯誤保留 isError response,同時針對回報的範例加入 regression check。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api, backend-api-design
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
描述清楚
新手友好度
70/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。