MCPServer: public hooks for tool input schemas, capabilities and handler removal

オープン
#3,933 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
43/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

Start with MCPServer in mcp.server.mcpserver and Server in mcp.server.lowlevel, then inspect ServerSession and the existing middleware hook. Check the guard tests mentioned in the issue and run the relevant tests before trying a branch. Done means the four requested hooks or public APIs are available and tested, including stable connection identity.

索引モデルが issue の本文から書いたものです。

説明

Description

We build an MCP server framework on mcp 2.x's MCPServer (mcp.server.mcpserver). It owns its own tool registry, so it overrides list_tools and call_tool, and it needs four more things the SDK only offers through private attributes. Each one ties us to a single 2.x minor, because a rename in a minor release silently changes what our users' clients see.

  1. Tool input schemas for Mcp-Param header validation. The low-level Server takes get_tool_input_schema, but MCPServer always passes its own _tool_input_schema, which reads _tool_manager. A subclass that answers tools/list and tools/call itself has to override the private _tool_input_schema (or fill _tool_manager._tools with hand-built Tool objects). Ask: accept get_tool_input_schema= in the MCPServer constructor, or make the method a documented, overridable public one.

  2. Adjusting advertised capabilities. We must report capabilities.tools.listChanged: false (we never send notifications/tools/list_changed) and declare an extension only to some callers. Today that means reaching MCPServer._lowlevel_server and replacing get_capabilities on the instance. Ask: a public way to post-process ServerCapabilities per request (a constructor callback such as capabilities=lambda ctx, caps: caps), and a public accessor for the low-level server (MCPServer.lowlevel).

  3. Removing a default handler. MCPServer registers prompts/list, prompts/get and the resource handlers by default, and capabilities are derived from which handlers exist. Server has add_request_handler and get_request_handler but no remove_request_handler, so we pop from the private _request_handlers. Ask: Server.remove_request_handler(method), or constructor flags to leave prompts and resources out.

  4. A stable identity for a 2025-era connection. 2.x builds a ServerSession per request; the only stable identity of a client connection is the private ServerSession._connection. We key per-connection state (an "active context" a client enters and leaves) on it. Ask: a public, hashable connection identity on the request context (for example ctx.connection_id), documented as stable for the life of a 2025-era connection.

MCPServer.middleware (documented as provisional) already covers the one other hook we needed. We have guard tests for each of the above and can test a branch.

References
  • Observed on mcp 2.3.0 and 2.4.0 (mcp.server.mcpserver.MCPServer, mcp.server.lowlevel.Server, ServerSession).
主要言語
Python
スター
25k
フォーク
4.2k
平均マージ
10分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。