McpServer: dynamic registration per request (tools known only when a request arrives, and different for each caller)

Abierto
#10,946 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Read the McpServer registration and request handling code, then compare the proposed behavior with #10442, #10444, and #10880. The issue reports a working implementation and tests against Effect's source, but leaves the API shape and how it fits the registry open for discussion. Start by following the maintainer decision on those questions; done means an agreed design and a pull request that supports per-request, caller-specific tool listing and calls.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Note: everything below was written by an AI agent working on the author's behalf and may not have been reviewed by a human.

This is AI-generated; I don't have strong opinions on the API or developer experience and am glad to take whatever shape you prefer, but I do need the functionality.

The problem: dynamic registration

McpServer serves what was registered with addTool or a toolkit. That fits a server whose tools are known when it is built. I am building servers whose tools are not:

  • A proxy. A server that serves another MCP server's tools again, reached with the caller's own credential. The upstream's tools can only be listed as that caller, and they change between requests.
  • Tools derived from a document. A server that turns an API description fetched at run time into tools.
  • Tools that depend on the caller. Two callers of the same server see different tools.

All three are the same problem: what the server has registered is not fixed, and it is not even one set. MCP middleware and visibility (from #9610) can hide registered tools from a caller, but they cannot add tools the server never registered.

#10442 ("Support dynamic MCP registrations") solves the first half of this. With removeTool and its siblings, declaredFeatures and list-change notifications, a running server can change its own registered set. What it leaves open is the second half: the set is still the server's, one set for every caller. To serve a caller's own tools with it, a server has to add and remove registrations around each request. On a server shared by concurrent callers that makes one caller's tools visible to another, and a large upstream list is registered and withdrawn again on every request.

So the question I am raising is how dynamic registration should work when the registrations are computed per request, for the caller making it.

One possible shape

A registration whose tools are computed on each request, beside the fixed ones:

const server = yield* McpServer.McpServer

yield* server.addToolSource({
  // Runs on every `tools/list`, inside the request's middleware, so it can read the caller.
  list: upstream.listTools,
  // Runs for a `tools/call` whose name no registered tool has.
  call: (name, payload) => upstream.callTool(name, payload),
  // Optional: which names this registration answers for, when there are several.
  owns: (name) => name.startsWith("upstream_")
})
  • list returns the tools, or { tools, ttlMs?, cacheScope?, _meta? }, which is merged into the tools/list result and its cache hint on 2026-07-28.
  • call returns a CallToolResult (or InputRequired on 2026-07-28). Its failures map as addTool's do.
  • A fixed registration shadows a per-request tool of the same name. A per-request tool is listed only from the registration its calls would go to.
  • Nothing is kept between requests: the server holds no copy of what a request listed.
  • The server has no input schema for such a tool, so it does not validate arguments; the registration does.

I have this working against Effect's source, with tests: per-request listing, routing with owns, middleware and visibility, errors, two concurrent callers on layerHttpRequestScoped, and per-caller sessions on layerHttp.

I am not attached to the name or to it being a separate method. If per-request registration belongs inside #10442's registry, for example as a registration whose tools are an Effect, I would rather build that. I did not want to open a competing pull request against a design in review.

#10444 lets the server's static cacheHints.tools be "public". If that lands, how a per-request registration's hint combines with the server's static one is the one place the two meet.

Questions

  1. Is per-request registration part of what dynamic registration in McpServer should cover, or should a proxy be built another way?
  2. If yes: should it be its own registration (addToolSource({ list, call, owns? })), or part of #10442's registry?
  3. Should other registrations get the same? I also need it for skills (details in a comment below) and for MCP Events, where #10880 registers event types when the server is built. Resources and prompts I have not needed.

I am happy to open a pull request, rebased onto whichever of main or v4/next-minor you prefer, once the shape is agreed.

Lenguaje dominante
TypeScript
Estrellas
16.7k
Forks
808
Merge medio
21 h 22 min
PR fusionados (30 d)
486

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Effect-TS/effect

Todos los issues de Effect-TS/effect

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.