Skip to content

Support request-scoped MCP tool sources - #10981

Open
effect-bot wants to merge 5 commits into
v4/next-minorfrom
agent/effect-bot/bb789e024884
Open

effect-bot wants to merge 5 commits into
v4/next-minorfrom
agent/effect-bot/bb789e024884

Conversation

@effect-bot

Copy link
Copy Markdown
Contributor

Summary

Adds McpServer.toolSource and McpServer.registerToolSource to resolve and dispatch MCP tools per request without mutating server-wide registrations.

Behavior

  • Per-request resolution: list runs on every tools/list without caching between requests, and call dispatches unregistered tool names matching owns (default: all unregistered names) without requiring a prior tools/list.
  • Static precedence & owns consistency: statically registered tools always take precedence over sourced tools (even when hidden by visibility), and a sourced tool is listed only from the first source whose owns accepts its name.
  • Middleware, visibility, and request-level dependencies: services read by list and call (other than McpRequestContext) are lifted to McpRequest<"Requires", ...>. Non-visibility middleware wraps list with target: "", and per-tool visibility filters the returned tools by name so allowlist visibilities never hide an entire source.
  • Error mapping: list failures propagate as JSON-RPC errors; call failures map like addTool, with Cause.NoSuchElementError mapped to ToolNotFound (-32602) without falling through to later sources.
  • No schema validation: because the server has no input schema at call time, argument validation and 2026-07-28 parameter-header checks are skipped for sourced tools.
  • Non-breaking service shape: implemented via McpServer internal state (matching registerSkill / skill and middleware.layerGlobal), keeping hand-written McpServer services and mocks compatible.

Verification

  • pnpm vitest run across all 15 Node MCP test suites (McpClient, McpSchema, and all McpServer/* Node suites): 1199 passed (50 skipped)
  • pnpm tstyche packages/effect/typetest/ai/McpServer.tst.ts: 39 passed (92 assertions)
  • pnpm exec oxlint on all modified files: 0 warnings, 0 errors
  • pnpm --filter effect check (tsc -b tsconfig.json): passed

Closes #10946
Closes EFF-4372

Co-authored-by: Rhys Sullivan 39114868+RhysSullivan@users.noreply.github.com

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0e38a87

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-amazon-bedrock Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/chat-discord Minor
@effect/chat-slack Minor
@effect/chat-teams Minor
@effect/chat-telegram Minor
@effect/chat-whatsapp Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-cloudflare Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

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

@effect-bot
effect-bot force-pushed the v4/next-minor branch 3 times, most recently from f596d89 to ffb3789 Compare November 27, 2026 02:04
@effect-bot
effect-bot force-pushed the agent/effect-bot/bb789e024884 branch 2 times, most recently from 5ce45c9 to 72dd3e9 Compare November 27, 2026 02:05
@effect-bot
effect-bot force-pushed the v4/next-minor branch 2 times, most recently from 0abe933 to 7fef40f Compare November 27, 2026 02:06
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.28 KB 40.28 KB 0.00 KB (0.00%)
basic.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
batching.ts 11.65 KB 11.65 KB 0.00 KB (0.00%)
brand.ts 7.17 KB 7.17 KB 0.00 KB (0.00%)
cache.ts 11.83 KB 11.83 KB 0.00 KB (0.00%)
config.ts 23.75 KB 23.75 KB 0.00 KB (0.00%)
differ.ts 22.55 KB 22.55 KB 0.00 KB (0.00%)
http-client.ts 28.40 KB 28.40 KB 0.00 KB (0.00%)
http-router.ts 39.10 KB 39.10 KB 0.00 KB (0.00%)
logger.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
metric.ts 9.91 KB 9.91 KB 0.00 KB (0.00%)
optic.ts 7.43 KB 7.43 KB 0.00 KB (0.00%)
pubsub.ts 16.55 KB 16.55 KB 0.00 KB (0.00%)
queue.ts 13.44 KB 13.44 KB 0.00 KB (0.00%)
schedule.ts 12.27 KB 12.27 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.32 KB 14.32 KB 0.00 KB (0.00%)
schema-binary.ts 43.17 KB 43.17 KB 0.00 KB (0.00%)
schema-class.ts 22.31 KB 22.31 KB 0.00 KB (0.00%)
schema-codegen.ts 33.66 KB 33.66 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.76 KB 30.76 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.49 KB 28.49 KB 0.00 KB (0.00%)
schema-string-transformation.ts 16.06 KB 16.06 KB 0.00 KB (0.00%)
schema-string.ts 12.60 KB 12.60 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.62 KB 16.62 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.82 KB 39.82 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.44 KB 21.44 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.62 KB 21.62 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.71 KB 21.71 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.75 KB 26.75 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.77 KB 21.77 KB 0.00 KB (0.00%)
schema.ts 21.41 KB 21.41 KB 0.00 KB (0.00%)
stm.ts 14.77 KB 14.77 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)
supervisor.ts 11.85 KB 11.85 KB 0.00 KB (0.00%)

@effect-bot
effect-bot force-pushed the agent/effect-bot/bb789e024884 branch from 8f59cc4 to 53d5db6 Compare November 27, 2026 03:35
@effect-bot
effect-bot force-pushed the agent/effect-bot/bb789e024884 branch from 53d5db6 to eeaf7b2 Compare November 27, 2026 03:59
@effect-bot
effect-bot force-pushed the v4/next-minor branch 2 times, most recently from 70f8345 to 33352ec Compare November 27, 2026 10:13
effect-bot and others added 5 commits November 28, 2026 04:05
Co-authored-by: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com>
- Route list and call through one `toolSource` lookup in mcpCore and
  merge source lists without the index bookkeeping.
- Share the captured-services merge and the title fallback instead of
  repeating them, and drop the unreachable `Hidden` recovery.
- Infer only the services of a tool source; its error types are fixed.
- Fix the tool source tests under `pnpm check` and apply dprint.

Co-authored-by: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com>
- Translate a source's `NoSuchElementError` inside the middleware
  boundary, so middleware sees an MCP error with code -32602 as it does
  for a hidden tool.
- Shadow sourced tools against the registry as it was when the list
  started, so a tool registered during discovery is not dropped.
- List each sourced name once.
- Correct the middleware and visibility docs for tool source lists.

Co-authored-by: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com>
@effect-bot
effect-bot force-pushed the agent/effect-bot/bb789e024884 branch from eeaf7b2 to 0e38a87 Compare November 28, 2026 04:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant