Skip to content

Make docs MCP HTTP transport stateless#18

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/stateless-http-transport
Jul 12, 2026
Merged

Make docs MCP HTTP transport stateless#18
ChiragAgg5k merged 3 commits into
mainfrom
fix/stateless-http-transport

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

Makes the hosted Streamable HTTP transport stateless so requests can be routed to any replica without producing Session not found errors.

The bundled mcp-framework exposes session.enabled but did not implement the disabled path. The patch now creates a request-scoped SDK transport with no session ID and routes responses through async request context. Cross-instance regression tests cover initialization on one replica followed by tools/list on another.

This also restores the existing content-download CI step by sourcing versioned SDK examples from their new canonical repository, appwrite/specs, and runs the regression tests in CI.

How was it tested?

  • bun install --force --frozen-lockfile
  • bun run test
  • bun run build
  • bun run download-content
  • git diff --check

Related issues

No linked issue. This fixes the production multi-replica MCP session routing failure observed with Cursor and mcp-remote.

@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes the hosted Streamable HTTP transport fully stateless so any replica can handle any request, fixing Session not found errors behind a load balancer. It patches mcp-framework to add a handleStatelessRequest path (per-request StreamableHTTPServerTransport routed via AsyncLocalStorage), a port getter for port:0 support, and session last-activity tracking with a cleanup interval. Supporting changes include cross-replica regression tests, a CI test step, and updated example download paths.

  • Patch (mcp-framework+0.2.18.patch): adds handleStatelessRequest and send() routing through AsyncLocalStorage; fixes port || 8080port ?? 8080 so port:0 works; starts a session cleanup interval unconditionally (harmless in stateless mode due to .unref() and empty _sessionLastActivity).
  • Tests (tests/http-stateless.test.mjs): two cross-replica scenarios — one low-level transport test and one full MCPServer test — both using port:0 for race-free port assignment.
  • CI / scripts: restores the download-content step by pointing at appwrite/specs, and adds bun run test before build.

Confidence Score: 5/5

Safe to merge. The stateless path is well-isolated and AsyncLocalStorage correctly scopes each per-request transport to its HTTP response.

The core mechanism is sound, the port:0 fix is correct, and the regression tests directly cover the production failure scenario.

The patch file deserves a second look if session-based mode is ever re-enabled, given the broadcast error log demotion to debug.

Important Files Changed

Filename Overview
patches/mcp-framework+0.2.18.patch Core of the change: adds handleStatelessRequest (per-request transport via AsyncLocalStorage), port getter for port:0 support, ?? fix for port 0, session last-activity tracking, and cleanup interval. Session broadcast error level demoted from error to debug.
src/index.ts Switches to session.enabled: false and removes Mcp-Session-Id from exposeHeaders. Clean and correct.
tests/http-stateless.test.mjs Adds two regression tests: low-level transport cross-replica routing and full MCPServer cross-replica scenario. Uses port: 0 for race-free port assignment.
.github/workflows/ci.yml Adds bun run test step before build, restoring CI coverage for the new regression tests.
scripts/download-content.ts Updates example download source from appwrite/appwrite to appwrite/specs, restoring the CI download step.
tests/fixtures/tools/ping.tool.js Minimal test fixture tool used by the MCPServer regression test to verify tools/list across replicas.
package.json Adds "test": "node --test tests/*.test.mjs" script wiring the new regression tests into the standard build workflow.

Reviews (2): Last reviewed commit: "fix: address Greptile review feedback" | Re-trigger Greptile

Comment thread tests/http-stateless.test.mjs Outdated
@ChiragAgg5k
ChiragAgg5k merged commit 0942651 into main Jul 12, 2026
2 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/stateless-http-transport branch July 12, 2026 15:51
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