modelcontextprotocol / modelcontextprotocol/python-sdk

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

Đang mở
#2,429 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug fix proposed P2 ready for work
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Đọc trình xử lý decorator call_tool trong src/mcp/server/lowlevel/server.py quanh các dòng 560 và 575, sau đó so sánh bản sửa tương ứng của TypeScript SDK trong modelcontextprotocol/typescript-sdk#654 / PR #655. Xác nhận rằng nhánh lỗi tránh việc xác thực outputSchema và giữ nguyên phản hồi isError cho các lỗi công cụ không có cấu trúc, kèm theo một kiểm tra hồi quy cho ví dụ đã được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, backend-api-design
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
70/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.