Sampling tool_result validation skips all but the last message

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

Maintainer thường phản hồi trong vòng 1 ngày

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

  • #3946 của @adityajai119 — đã đóng, không merge
  • #3948 của @adityajai119 — đã đóng, không merge

Đánh giá

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

Hướng nghiên cứu

Start with mcp.server.validation.validate_tool_use_result_messages and inspect its callers in ServerSession.create_message and the FastMCP sampling path. Reproduce the reported case, then check every message containing tool_result for purity, a preceding tool_use, and matching IDs. Done means the reproduction and equivalent intermediate-message cases raise validation errors; valid tool-result messages still pass.

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

Mô tả

What happened

validate_tool_use_result_messages() only checks the final two messages of a sampling request. A tool_result content block in an earlier message is not validated at all.

Reproduction

from mcp.server.validation import validate_tool_use_result_messages
from mcp_types import SamplingMessage, TextContent, ToolResultContent, ToolUseContent

messages = [
    SamplingMessage(role="assistant", content=ToolUseContent(type="tool_use", id="t1", name="tool", input={})),
    SamplingMessage(role="user", content=[ToolResultContent(type="tool_result", tool_use_id="t1"), TextContent(type="text", text="extra")]),
    SamplingMessage(role="assistant", content=TextContent(type="text", text="done")),
]
validate_tool_use_result_messages(messages)  # returns: no error

The second message mixes tool_result with text even though SEP-1577 requires a tool-result message to contain only tool_result blocks. A mismatched intermediate tool_use_id is likewise accepted.

Expected behavior

Every message carrying tool_result content is checked for content purity, a preceding tool_use message, and matching IDs — not just the last message.

Environment

Current main (77001c9), mcp.server.validation.validate_tool_use_result_messages. Affects both ServerSession.create_message and the FastMCP sampling path.

Ngôn ngữ chính
Python
Star
25k
Fork
4.2k
Merge trung bình
10 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

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.

Issue khác của modelcontextprotocol/python-sdk

Tất cả issue của modelcontextprotocol/python-sdk

Issue tương tự

Thêm issue về Python

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.