Context.request_id stringifies integer request IDs and None, corrupting related_request_id correlation
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đá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
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu tại src/mcp/server/mcpserver/context.py, ở Context.request_id và các chỗ sử dụng thuộc tính này trong elicit(), elicit_url() và log(). Kiểm tra các kiểu ID yêu cầu liên quan và các bài kiểm thử hiện có cho những phương thức này, sau đó bổ sung kiểm thử cho ID kiểu số nguyên và ID bị thiếu. Hoàn tất khi kiểu ID ban đầu được giữ nguyên và ID bị thiếu không bị chuyển thành chuỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Release Line
2.x (main branch)
Problem Description
In JSON-RPC 2.0 and the MCP specification, RequestId is defined as str | int.
In src/mcp/server/mcpserver/context.py:299-301, Context.request_id is defined as:
@property
def request_id(self) -> str:
"""Get the unique ID for this request."""
return str(self.request_context.request_id)
And in ctx.elicit(), ctx.elicit_url(), and ctx.log() (lines 226, 261, 285):
related_request_id=self.request_id
This causes two bugs:
- Integer request ID corruption: When an incoming JSON-RPC request uses an integer ID (e.g.,
42),ctx.request_idcoerces it to"42". Downstream notifications and elicitation messages carryrelated_request_id: "42"instead of42, breaking correlation on clients that distinguish numeric and string IDs. Nonecoerced to string"None": When a handler runs in a context without a request ID (e.g., notification handlers or server-initiated tasks whererequest_context.request_idisNone),str(None)evaluates to the string"None". As a result, the server sendsrelated_request_id: "None"over the wire rather thanNoneor omitting the field.
Minimal Reproduction Code
from mcp.server.context import ServerRequestContext
from mcp.server.mcpserver.context import Context
# 1. Integer Request ID
req_ctx_int = ServerRequestContext(
session=None,
lifespan_context={},
method="tools/call",
request_id=42,
protocol_version="2026-07-28",
)
ctx_int = Context(request_context=req_ctx_int)
print(f"Integer ID result: {ctx_int.request_id!r} (type: {type(ctx_int.request_id).__name__})")
assert ctx_int.request_id == 42, f"Expected 42 (int), got {ctx_int.request_id!r}"
# 2. None Request ID (e.g. notifications)
req_ctx_none = ServerRequestContext(
session=None,
lifespan_context={},
method="notifications/message",
request_id=None,
protocol_version="2026-07-28",
)
ctx_none = Context(request_context=req_ctx_none)
print(f"None ID result: {ctx_none.request_id!r} (type: {type(ctx_none.request_id).__name__})")
assert ctx_none.request_id is None, f"Expected None, got {ctx_none.request_id!r}"
Actual Output
Integer ID result: '42' (type: str)
AssertionError: Expected 42 (int), got '42'
None ID result: 'None' (type: str)
AssertionError: Expected None, got 'None'
Expected Output
Context.request_id should return RequestId | None preserving the original type (int, str, or None).
Proposed Fix
Update Context.request_id in src/mcp/server/mcpserver/context.py:
@property
def request_id(self) -> RequestId | None:
"""Get the unique ID for this request."""
if self._request_context is None:
return None
return self._request_context.request_id
and ensure related_request_id in elicit(), elicit_url(), and log() passes the optional RequestId.
I would be happy to submit a PR with test coverage if assigned.
Assisted by AI; reviewed and verified with reproduction script.
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
modelcontextprotocol/python-sdk#3978 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Client serves cached tools after its context exits with an exceptionCó thể đã có người làm @jonxsong đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
modelcontextprotocol/python-sdk#3968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3934 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
modelcontextprotocol/python-sdk#3929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwiseCó thể đã có người làm @abdulwaarith0 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
MakazhanAlpamys/Soup#3690 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug data-types native-format
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ClickHouse/clickhouse-connect#1320 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Public benchmark import end-to-end test fails when the test stack's worker runs the parity jobĐang mởaccepted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
future-agi/future-agi#6392 ·
Maintainer thường phản hồi trong vòng 1 ngày