Skip to content

Protect MCP continuation state - #10446

Open
nmnmcc wants to merge 22 commits into
Effect-TS:v4/next-minorfrom
nmnmcc:codex/mcp-core-state
Open

nmnmcc wants to merge 22 commits into
Effect-TS:v4/next-minorfrom
nmnmcc:codex/mcp-core-state

Conversation

@nmnmcc

@nmnmcc nmnmcc commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

MCP continuation state was returned to clients unchanged, so altered or unrelated strings could reach handlers. This protects modern requestState with authenticated encryption, expiry, and binding to the method, semantic parameters, and caller identity. Handlers keep their original strings; clients receive opaque tokens.

RequestStateOptions and constructor requestState options configure shared keys, rotation, and expiry. Defaults use an endpoint-lived XChaCha20-Poly1305 key and five-minute TTL, including across request-scoped HTTP calls. Verification runs inside authentication and before handler factories, following the MRTR state requirements.

Migration: previously issued raw state is rejected. Restart those operations and echo new tokens unchanged. Configure requestState.keys for retries across restarts or instances, and provide RequestStatePrincipal from authentication middleware for authenticated users. Token verification does not replace authorization, input-response validation, or application checks for single use. Replacing a registration under the same name does not revoke its unexpired tokens; applications that change continuation semantics should version their state or rotate keys. .changeset/mcp-request-state.md declares an effect minor release.

This preserves next-minor's one-argument Toolkit support for explicitly declared InputRequired failures in both failure modes and its validating tagged schema. These continuations receive the same state protection and legacy input handling.

Regression coverage: tests exposed raw state and accepted tampered or mismatched continuations. Both declared Toolkit failure modes also leaked raw state on the current prerequisite base. Tests now verify rejection before handlers, valid resumption, identity/expiry/rotation, transport coverage, and continuation cache suppression.

Dependencies: #10444, #10443. The upstream diff includes these prerequisites; focused comparison.

Verification

Target: Effect-TS/effect:v4/next-minor. Head: b362369476bf3a658efef8e3752abe39dbddab2b.

  • pnpm check, pnpm check-tsc, lint, JSDoc checks, the full Tstyche and doctest suites, circular checks, AI-doc generation, package build with stripInternal: true, and distribution-type checks: passed.
  • Full configured Node suite: Test Files 622 passed | 1 skipped (623); Tests 17651 passed | 15 expected fail | 108 skipped (17774).
  • Runtime: Node 26.12.1 / pnpm 11.20.0; four workers; database integration tests enabled. MSSQL is disabled as in CI; the opt-in cluster suite is excluded. Runtime-specific hosted CI results are separate.
  • Full tests and doctests used --run with explicit file lists. Generated docs remained unchanged and the temporary build configuration was restored.

@changeset-bot

changeset-bot Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b362369

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

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest 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/platform-browser Minor
@effect/platform-bun 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

@github-actions

github-actions Bot commented Nov 7, 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 39.65 KB 39.65 KB 0.00 KB (0.00%)
basic.ts 7.34 KB 7.34 KB 0.00 KB (0.00%)
batching.ts 11.20 KB 11.20 KB 0.00 KB (0.00%)
brand.ts 6.97 KB 6.97 KB 0.00 KB (0.00%)
cache.ts 11.70 KB 11.70 KB 0.00 KB (0.00%)
config.ts 23.07 KB 23.07 KB 0.00 KB (0.00%)
differ.ts 22.22 KB 22.22 KB 0.00 KB (0.00%)
http-client.ts 27.33 KB 27.33 KB 0.00 KB (0.00%)
http-router.ts 37.21 KB 37.21 KB 0.00 KB (0.00%)
logger.ts 12.16 KB 12.16 KB 0.00 KB (0.00%)
metric.ts 9.63 KB 9.63 KB 0.00 KB (0.00%)
optic.ts 7.17 KB 7.17 KB 0.00 KB (0.00%)
pubsub.ts 16.21 KB 16.21 KB 0.00 KB (0.00%)
queue.ts 13.08 KB 13.08 KB 0.00 KB (0.00%)
schedule.ts 11.95 KB 11.95 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.27 KB 14.27 KB 0.00 KB (0.00%)
schema-binary.ts 42.27 KB 42.27 KB 0.00 KB (0.00%)
schema-class.ts 21.98 KB 21.98 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.93 KB 29.93 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.23 KB 28.23 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.53 KB 15.53 KB 0.00 KB (0.00%)
schema-string.ts 12.47 KB 12.47 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.43 KB 16.43 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.19 KB 39.19 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.38 KB 26.38 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.13 KB 21.13 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.30 KB 21.30 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.39 KB 21.39 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.40 KB 26.40 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.47 KB 21.47 KB 0.00 KB (0.00%)
schema.ts 21.07 KB 21.07 KB 0.00 KB (0.00%)
stm.ts 14.37 KB 14.37 KB 0.00 KB (0.00%)
stream.ts 10.53 KB 10.53 KB 0.00 KB (0.00%)
supervisor.ts 11.48 KB 11.48 KB 0.00 KB (0.00%)

effect-bot and others added 15 commits November 7, 2026 09:24
Preserve the tested dependency tree while retaining the new upstream Request equality fix.
@RhysSullivan

Copy link
Copy Markdown
Contributor

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.

I need elicitation on 2026-07-28 in tool handlers, and I carry a patch whose request-state sealing is this PR's design: effect/crypto/Aead, the token format and key ring, the exact-encoding check, principal and credential as distinct identities, rejection with InvalidParams, the five-minute default and the same option names. I would much rather use this PR than keep a parallel version, so here is what my use needed beyond it, in case any of it belongs here or in a follow-up.

Additions to the sealing

  1. The server's name in the authenticated data, beside the key id, method, tool name, canonical arguments and caller. Several servers can share one key ring, and a token from one should not open on another.
  2. An expiry kept across rounds. The state expires ttl after the call first paused, and later rounds keep that expiry instead of extending it, so a client cannot keep a pause alive forever by answering.
  3. requirePrincipal. With it, a call without a RequestStatePrincipal cannot pause (-32603) or continue (-32602). A multi-tenant host wants that rather than falling back to the authorization header.
  4. AES-256-GCM keys beside XChaCha20-Poly1305, with an AES-256-GCM default key made on the first seal, so a server that never pauses bundles no cipher. A token sealed with an XChaCha20-Poly1305 key has exactly this PR's format; one sealed with AES-256-GCM differs only in its 12-byte nonce.

McpServer.elicit itself on 2026-07-28

This PR's docs say elicit is not available on 2026-07-28, and handlers return McpSchema.InputRequired instead. I need the existing elicit call to work there, so the same handler code runs on every revision:

  • On 2026-07-28, an unanswered elicit records its question and never returns. The server runs the handler in a child fiber, lets its other branches reach their own questions, then interrupts it from outside (so code after an unanswered elicit never runs that round) and answers input_required with every question of the round. On the retry the handler runs again from the start, and each elicit returns its answer.
  • A question's key is the SHA-256 of the whole question plus how many times the call asked it before, so an answer counts only for the question it was given for. The state holds answers by key, never question text.
  • Limits are reported as errors with data.reason (more than 64 questions in one call; the same question asked twice at once), so a client can tell them apart from a crash.
  • On 2025 revisions, elicit is unchanged.

I have this working with tests against Effect 4.1.4. If you would take it, I am glad to rebase it onto this branch once it lands, or to open it as a follow-up PR against your branch now, @nmnmcc, whichever you prefer. Separately, a small fix I found on the way is #10952 (2025-06-18 elicitation schemas dropped enum values).

Sent from my Claude

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.

10 participants