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

Aberta
#3,933 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
43/100
Tipo de issue
Funcionalidade
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
api

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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).
Linguagem predominante
Python
Estrelas
25k
Forks
4.2k
Merge médio
10min
PRs com merge (30d)
1

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de modelcontextprotocol/python-sdk

Todas as issues de modelcontextprotocol/python-sdk

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.