Skip to content

Add McpTest in-memory client for McpServer registrations - #9657

Merged
tim-smart merged 6 commits into
v4/next-minorfrom
agent/nelson/bbf7978d0011
Oct 21, 2026
Merged

tim-smart merged 6 commits into
v4/next-minorfrom
agent/nelson/bbf7978d0011

Conversation

@tim-smart

@tim-smart tim-smart commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Adds effect/ai/McpTest, an in-memory client for testing McpServer registrations without opening a transport.

const client = yield* McpTest.makeClient(registrations, {
  protocols: [McpProtocol.v2025_11_25]
})
const result = yield* client.callTool({ name: "WhoAmI" })

makeClient builds McpServer.layer over an in-memory RpcServer.Protocol. Both directions go through RpcSerialization.jsonRpc(), so requests, results and MCP errors take the same JSON-RPC encoding as stdio and HTTP. For stateful protocols the client sends initialize and notifications/initialized before it returns. For v2026_07_28 it attaches the request metadata to every request instead.

Transport built-ins are discharged the same way as layerStdio. McpRequestContext is always provided, and McpServerClient only when every configured adapter is stateful. Other request markers still have to come from MCP middleware.

The client has typed listTools / callTool / readResource / getPrompt / complete (plus the rest of ClientRequestRpcs except initialize). It also exposes a notifications queue in wire encoding and the running McpServer service. Interrupting a call sends notifications/cancelled. Server-to-client requests such as elicitation or sampling are answered with method-not-found, so a handler that sends one doesn't hang.

Behaviour worth knowing:

  • A stateful session only receives list-change notifications for changes made after the server handled its initialize. Each session records the server's list-change revision when it initializes, and delivery skips older revisions. This applies to stdio, HTTP (keyed by Mcp-Session-Id) and custom transports. Before, a registration-time list_changed could race the handshake and reach the client.
  • resources/updated is only delivered to clients subscribed to that URI, as on the real transports.

Tests

McpTest.test.ts covers a negotiated tool call through middleware, a middleware MCP error, subscribed notifications, startup ordering with McpServer's dispatcher held until after the handshake, and a capability-enabled reverse request getting method-not-found. McpServer.test.ts adds HTTP regressions for the initialize boundary: post-initialize changes reach every session, and pre-initialize changes don't.

Programmatic registration tests now use McpTest instead of hand-building a client:

  • makeToolkitTestClient (16 registerToolkit tests) drops its HTTP harness, RpcClient and manual initialize.
  • The registerToolkit effect-form tests for non-strict parameter errors, declared Error failures and failure origins no longer provide McpServerClient by hand.
  • RequestDependencies.test.ts drops its hand-built McpServerClient.
  • The two notifyElicitationComplete return tests no longer use the stdio harness.

These stay on their existing setup on purpose:

  • The stdio and HTTP harnesses, the conformance suites, and the batching, framing, lifecycle, header and routing tests, since they assert raw wire behaviour.
  • The direct service tests and the remaining McpServer.make tests, since they test the McpServer service API itself, including identity of typed failures and string structuredContent, which a wire round-trip can't keep.
  • Reverse-request tests that need a real answer (elicitation, sampling, roots) and the 2026 subscriptions/listen tests, since McpTest.Client doesn't support either.

Closes EFF-2137

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9d948d7

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

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

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

@github-actions

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 39.16 KB 39.16 KB 0.00 KB (0.00%)
basic.ts 7.07 KB 7.07 KB 0.00 KB (0.00%)
batching.ts 10.93 KB 10.93 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.37 KB 11.37 KB 0.00 KB (0.00%)
config.ts 22.53 KB 22.53 KB 0.00 KB (0.00%)
differ.ts 21.68 KB 21.68 KB 0.00 KB (0.00%)
http-client.ts 24.59 KB 24.59 KB 0.00 KB (0.00%)
http-router.ts 35.72 KB 35.72 KB 0.00 KB (0.00%)
logger.ts 11.71 KB 11.71 KB 0.00 KB (0.00%)
metric.ts 9.30 KB 9.30 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.81 KB 15.81 KB 0.00 KB (0.00%)
queue.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
schedule.ts 11.61 KB 11.61 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.87 KB 13.87 KB 0.00 KB (0.00%)
schema-binary.ts 40.65 KB 40.65 KB 0.00 KB (0.00%)
schema-class.ts 21.39 KB 21.39 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.35 KB 32.35 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.55 KB 27.55 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.11 KB 15.11 KB 0.00 KB (0.00%)
schema-string.ts 12.13 KB 12.13 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.05 KB 16.05 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.68 KB 38.68 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.73 KB 25.73 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.61 KB 20.61 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.80 KB 20.80 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.54 KB 25.54 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema.ts 20.57 KB 20.57 KB 0.00 KB (0.00%)
stm.ts 13.91 KB 13.91 KB 0.00 KB (0.00%)
stream.ts 10.16 KB 10.16 KB 0.00 KB (0.00%)

@effect-bot
effect-bot force-pushed the agent/nelson/bbf7978d0011 branch from 4122181 to 9d948d7 Compare October 21, 2026 08:16
@tim-smart
tim-smart merged commit 61c98df into v4/next-minor Oct 21, 2026
9 checks passed
@tim-smart
tim-smart deleted the agent/nelson/bbf7978d0011 branch October 21, 2026 09:56
@effect-bot effect-bot mentioned this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
effect-bot pushed a commit to lloydrichards/open_effect that referenced this pull request Oct 21, 2026
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