Emit MCP operation and session duration metrics (OTel semantic conventions)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 56/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start with src/mcp/server/_otel.py and src/mcp/shared/_otel.py to follow the existing tracing setup, then inspect the dispatcher and session start/end paths mentioned in the proposal. Compare metric names and attributes with the referenced semantic conventions and scenario. Done means client and server operation and session durations are recorded with the specified attributes, while remaining no-op without a configured MeterProvider.
索引モデルが issue の本文から書いたものです。
説明
Description
The SDK already creates OpenTelemetry spans by default (OpenTelemetryMiddleware on the server, a CLIENT span per outbound request in the dispatcher), but it doesn't record any metrics. There's no meter in src/mcp today.
The OTel GenAI semantic conventions define four MCP histograms (all in development status):
- mcp.client.operation.duration (s)
- mcp.server.operation.duration (s)
- mcp.client.session.duration (s)
- mcp.server.session.duration (s)
Right now these only show up through the reference scenario in the semconv repo (reference/scenarios/mcp/scenario.py), which builds the histograms itself and patches serve_connection. Users running the SDK don't get them.
Use case: I run MCP servers in production and send telemetry to Splunk through the OTel Collector. Spans are useful for debugging one request, but for dashboards and alerts (p95 tool-call latency, error rate per method, session length) I need metrics. Deriving them from spans is expensive and breaks when traces are sampled.
Proposal:
- Use opentelemetry-api's get_meter("mcp-python-sdk"), same pattern as the existing tracer, so it's a no-op unless the app configures a MeterProvider.
- Record server operation duration in OpenTelemetryMiddleware, reusing the attributes it already sets (mcp.method.name, gen_ai.tool.name, error.type, etc.).
- Record client operation duration around the existing span in the dispatcher.
- Record session durations at session start/end, with the negotiated protocol version.
- No new dependency and no behavior change without a configured MeterProvider.
Questions before I start:
- Is this something you'd accept?
- Should the client-side metric wait for the outbound middleware mentioned in the TODO in jsonrpc_dispatcher.py, or is it fine to add next to the current span?
- Since the conventions are still in development, do you want this behind an opt-in flag?
Happy to send a PR if the direction looks right.
References
- MCP semantic conventions (metrics): https://github.com/open-telemetry/semantic-conventions-genai/blob/main/model/mcp/metrics.yaml
- Reference scenario that currently produces these metrics: https://github.com/open-telemetry/semantic-conventions-genai/tree/main/reference/scenarios/mcp
- Existing tracing in the SDK: src/mcp/server/_otel.py, src/mcp/shared/_otel.py, docs/run/opentelemetry.md
- SEP-414 (trace context propagation): https://github.com/modelcontextprotocol/modelcontextprotocol/pull/414
- 主要言語
- 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
-
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 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug data-types native-format
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
ClickHouse/clickhouse-connect#1320 ·
メンテナーはふだん 1 日以内に返信
-
accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
future-agi/future-agi#6392 ·
メンテナーはふだん 1 日以内に返信