Context.request_id stringifies integer request IDs and None, corrupting related_request_id correlation
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
src/mcp/server/mcpserver/context.py の Context.request_id と、elicit()、elicit_url()、log() での使用箇所から始めてください。関連するリクエスト ID の型と、これらのメソッドの既存テストを確認し、整数 ID と欠落した ID のテストを追加してください。元の ID の型が保持され、欠落した ID が文字列化されない状態になれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 25k
- フォーク
- 4.2k
- 平均マージ
- 10分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/python-sdk のほかの issue
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
modelcontextprotocol/python-sdk#3978 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Client serves cached tools after its context exits with an exception対応中かも @jonxsong が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
modelcontextprotocol/python-sdk#3968 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelcontextprotocol/python-sdk#3957 ·
メンテナーはふだん 1 日以内に返信
-
v2
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
modelcontextprotocol/python-sdk#3934 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug v1
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
modelcontextprotocol/python-sdk#3929 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/python-sdk の issue をすべて見る
似ている issue
-
auto-reported bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
backend bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
nolte/kamerplanter#3193 ·
メンテナーはふだん 1 日以内に返信
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise対応中かも @abdulwaarith0 が今日担当しました。 オープンneeds-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
MakazhanAlpamys/Soup#3690 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信