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

オープン
#10,946 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
21時間 22分
マージ済み PR(30日)
486

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。