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

Aperta
#3,933 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
43/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).
Lingua principale
Python
Stelle
25k
Fork
4.2k
Merge medio
10m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/python-sdk

Tutte le issue di modelcontextprotocol/python-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.