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

Aperta
#10,946 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

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.

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

Descrizione

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.

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
21h 22m
PR unite (30g)
486

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.