Repository navigation
Add request-aware visibility to McpServer - #9661
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: fec3794 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
effect-bot
force-pushed
the
agent/nelson/f3776b531b6f
branch
2 times, most recently
from
October 21, 2026 09:57
feda373 to
99158a7
Compare
tim-smart
force-pushed
the
v4/next-minor
branch
from
October 21, 2026 10:33
61c98df to
eb3722d
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
4 times, most recently
from
October 21, 2026 20:33
36cf926 to
dbca9bc
Compare
tim-smart
force-pushed
the
agent/nelson/f3776b531b6f
branch
from
October 21, 2026 21:03
99158a7 to
2f58e6a
Compare
tim-smart
force-pushed
the
v4/next-minor
branch
4 times, most recently
from
October 21, 2026 22:39
8e6e2e0 to
005c3dd
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
15 times, most recently
from
October 21, 2026 23:56
5a41feb to
ccbffaa
Compare
effect-bot
force-pushed
the
agent/nelson/f3776b531b6f
branch
from
October 22, 2026 02:36
30bcb15 to
fec3794
Compare
Merged
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
tim-smart
added a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
tim-smart
added a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
effect-bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
This was referenced Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
McpServer.visibility, which hides tools, resources and prompts per request based on services that MCP middleware provides, for example aCurrentUser.EnabledWhenstays as it is; it can only see client capabilities.Behaviour
visibilityreturns an ordinaryMiddleware, so.layer,.layerGlobal,.combineand{ global: true }work as they do formiddleware. The check receivesMiddlewareOptionsand returnsEffect<boolean, E extends McpErrorBase, R>.Rmust come from middleware combined outside it, or from the transport; otherwise.layerisMissingRequestDependencies.tools/list,resources/list,resources/templates/listandprompts/list, only the middleware outside the innermost visibility runs, once for each registration. Soaudit.combine(adminOnly)keepsauditoff list requests, and a stack with no visibility never runs on list. Expensive lookups such as resolving the user from a token are expected to be cached by the middleware.MiddlewareOptionskeeps its flat shape.MiddlewareMethodgains the four list methods; on list requeststargetis the registration's name, URI or URI template, andpayloadisundefined. None of this has shipped yet.Tool 'x' not found,Resource 'x' not found,Prompt 'x' not found,Unknown completion reference or argument). This also coversinput_requiredcontinuation rounds, which return not-found rather thanInvalidToolContinuation.ResourceNotFound. It doesn't fall through to a template that also matches its URI.makeInvokeconcatenated the two stacks without deduping.tools/callheader mirroring looks up the descriptor with the syncEnabledWhencheck only. A hidden tool with anx-mcp-headerparameter can therefore answer a mismatched header with 400 before not-found, as agreed in the design.list_changednotifications are unchanged. Clients see visibility changes on their next list request.Implementation
mcpCore.ts) list methods take theMcpInvocationand can fail withRequestRejected. Each registration has an optionalvisibleeffect, and the core filters theisVisiblecandidates with it, in registration order.WeakSet.makeInvokereturnsinvokeandvisible.visibleruns the middleware from the innermost gate outwards aroundEffect.void, through the same path asinvoke, and mapsHiddentofalse.Hiddenerror, whichmakeInvokerecognises byinstanceofbefore it checks the handler-failure annotation and replaces with the method's not-found error.Hiddenhas an MCP error shape, because middleware outside the gate sees it.listForClienthelper.MCP.mdhas a new "Per-request visibility" section.Testing
Each behaviour change landed as tests first, in separate commits, and the implementations didn't change their assertions.
pnpm vitest run packages/effect/test/ai: 1610 passed.pnpm tstyche --target '>=5.9' packages/effect/typetest/ai/: 184 passed on both targets.pnpm lint,pnpm jsdocs --checkandpnpm circularpass.pnpm ai-docgenproduces no changes.tscis clean onpackages/effect/srcplus the MCP tests. I didn't run the repo-widepnpm check; CI will.Typed tool-selector options are out of scope.
Closes EFF-2132