Repository navigation
Streaming responses for extensions and trusted functions, and the opt-in MCP streaming transport (#659, #626) - #796
Merged
Merged
Conversation
…nctions on node/vercel, refused elsewhere (#659) HandlerResult gains `stream` (AsyncIterable<string | Uint8Array>), exclusive with `body`. A trusted function route opts in with `stream: true` (its Response body is handed on unread); an extension registration opts in with `streams: true`. Any other streamed result is the generic 502, logged as `stream_refused`. `stream: true` needs `function` and is refused with `sandbox: true`; the sandbox stays buffered and unchanged. The self-hosted server (native) and the Vercel adapter (delegated) write streams through a shared StreamHost: runtime decoration, no Content-Length, chunked, head committed on the first chunk, backpressure, HEAD never pulls, cancellation through iterator return() and an AbortSignal handed to extensions (request.signal) and trusted functions (context.signal), and operator limits separate from short-request admission (--max-streams, --stream-idle-timeout-ms, --stream-max-duration-ms, --stream-max-bytes). Shutdown ends streams at the close deadline; a retired dev-reload runtime closes after its last stream. AWS, Cloudflare and static refuse streaming before serving through the new `streaming` capability, and prepareExtensions refuses a `streams: true` registration outside node/vercel. Cache and compression bypass streams explicitly. Each ended stream logs a `stream` record with bytes, duration and end reason. Adds RIM-STREAM-001, specification/extension/operations/capability docs, the streaming-progress recipe and real-socket tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
… stream and Last-Event-ID replay (#659, #626) The optional parts of the MCP Streamable HTTP transport, enabled only by the operator: mcp({ streaming: true }) or bounded options (maxSessions 1000, sessionIdleTimeoutMs 1800000, keepAliveMs 15000, replayMaxEvents 64, replayMaxBytes 65536). Off by default: the registration then does not declare streams and every response is unchanged on every target, aws included. On, the registration declares streams: true (core refuses aws before activation; activation refuses vercel, whose instances do not share the in-memory session table): - initialize issues a 32-byte random base64url Mcp-Session-Id; later requests without it answer 400, an unknown/ended/expired/evicted one 404, DELETE ends it. A session is bound to the creating principal; another principal's use answers 404. The table is bounded (LRU eviction, idle expiry) and lives in memory, so a restart means 404 and re-initialize. - a tools/call with _meta.progressToken and an SSE Accept answers notifications/progress then the response as SSE; tools report through context.progress, and every handler gets context.signal (client disconnect, notifications/cancelled, session end, stream limits). - GET opens the session's server stream: keep-alive comments, consecutive event ids, a bounded replay buffer and Last-Event-ID replay; a newer GET replaces the open one. Nothing sends server-initiated messages yet; the plumbing is exercised by a test-only trigger. Real-socket tests in packages/mcp/test/streaming.test.ts. README, SECURITY, llms, CHANGELOG, EXTENSIONS/FRAMEWORK/OPERATIONS docs and urlcode.json updated; the mcp unpacked-size budget is raised to 160 KiB. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
… report (#659, #792) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
jimhoyd
added a commit
that referenced
this pull request
Sep 26, 2026
Resolves runtime.ts/server.ts/extensions.ts and the RIM table. One rule now covers both features: an admitted stream holds its runtime's extensions, so a handoff release waits for open streams as well as buffered requests, and a dev reload of a project declaring extensions first ends open streams with the new end reason `reload` (clients resume, e.g. MCP Last-Event-ID) rather than being refused for as long as a client stays connected. A project declaring no extensions has nothing to hand over and keeps #796's behavior: streams run on the retired runtime. handle() keeps its request counted until a stream is admitted, so no release or close runs between dispatch settling and tracking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem and change
Every URLCode response was a single buffered
{status, headers, body}, so nothing could send progress or keep a connection open. The MCP extension could not implement the optional Streamable HTTP pieces: POST replies as SSE, the GET server stream, and session resumption. This PR adds a generic core capability and then the MCP use of it.Core (
feat(core)), a generic streaming response.HandlerResult.stream?: AsyncIterable<string | Uint8Array>, exclusive withbody/contentLength.RuntimeExtension.streams: true. Trustedfunctionroutes opt in with route YAMLstream: true; it requiresfunctionand is refused withsandbox: true.ExtensionRequest.signaland the functioncontext.signalabort on client disconnect, on a limit, or at shutdown.native. vercel isdelegated(extensions only; Vercel controls delivery). aws, cloudflare and static refuse a declared stream before serving, andcapabilities.tsreports the newstreamingcapability in those terms.''to flush), chunked, with backpressure.stream_refusedlog record.--max-streams32,--stream-idle-timeout-ms30000,--stream-max-duration-ms300000,--stream-max-bytes16 MiB, pluscreateVercelHandler({streams}). A stream leavesmaxInFlightRequestsonce its handler returns.--close-timeout-ms, and a retired dev-reload runtime waits for its streams.requestis logged at headers andstreamat the end, with bytes, duration and end reason.RIM-STREAM-001card; SPECIFICATION "Streamed responses", EXTENSIONS, CAPABILITIES, OPERATIONS, HTTP, MONITORING/OBSERVABILITY and YAML reference updates; a newrecipes/streaming-progress;test/streaming.test.ts(23 tests on real sockets).MCP (
feat(mcp)), an opt-in streaming transport, off by default.mcp({ streaming: true | {maxSessions, sessionIdleTimeoutMs, keepAliveMs, replayMaxEvents, replayMaxBytes} }), with defaults 1000 / 30 min / 15 s / 64 / 64 KiB. Invalid options throw at creation.tools/callwith aprogressTokenand an SSE Accept header streamsnotifications/progress, then the result.notifications/cancelledis handled.initializeissues a randomMcp-Session-Idbound to the creating principal. Unknown or foreign ids get 404, a missing id gets 400, DELETE answers 204, and eviction is bounded by LRU./mcpopens one SSE server stream per session, with keep-alive comments and integer event ids.Last-Event-IDreplays from a bounded per-session buffer; a second GET replaces the first.packages/mcp/test/streaming.test.tshas 15 real-socket tests, including a real disconnect, then reconnect withLast-Event-IDreceiving exactly the missed events in order, and restart gives 404.Package budgets:
Closes #659. Closes #626.
Verification
All runs used Node 26.10.0.
npm run check,npm run audit:packagesandnpm run verifypassed (exit 0);checkpass;audit:packagespasses after the budget raise;npm run test:package: 795236 packed / 3184374 unpacked bytes, 471 files; the packed install and starter/cookbook checks passed.Compatibility and security
Additive. Buffered responses are unchanged, and nothing streams unless a route or extension declares it. MCP streaming is off unless the operator enables it.
sandbox: trueisolation is unchanged; a sandboxed route cannot stream.MCP sessions:
Not verified: HTTP/2, real Vercel delivery, and buffering proxies (documented: use
proxy_buffering off/X-Accel-Buffering: no). This is real-socket testing only, not a security review or a deployment/soak test.Not implemented: server-initiated messages from real tools (the plumbing is there, but no tool sends one yet, and
listChangedstays false), the 2025-11-25 SSE polling behavior, and persisted sessions.Changes match the documented portable contract; docs/examples are updated where needed.
Relevant tests and package checks pass, or limitations are explained above.
No credentials, customer data or private project material are included.
Runtime/starter changes remain aligned where applicable.
🤖 Generated with Claude Code
https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
Generated by Claude Code