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

Ouverte
#3,933 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
43/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
api

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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).
Langage dominant
Python
Étoiles
25k
Forks
4.2k
Merge moyen
10 min
PR mergées (30 j)
1

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/python-sdk

Toutes les issues de modelcontextprotocol/python-sdk

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.