Skip to content

fix: switch public MCP server to stateless transport#30

Merged
fbsobreira merged 2 commits intodevelopfrom
fix/stateless-mcp-transport
Feb 20, 2026
Merged

fix: switch public MCP server to stateless transport#30
fbsobreira merged 2 commits intodevelopfrom
fix/stateless-mcp-transport

Conversation

@fbsobreira
Copy link
Copy Markdown
Member

Summary

  • Switch public MCP server from stateful session-based transport to stateless per-request transport (sessionIdGenerator: undefined)
  • Eliminates "Session not found" errors caused by container restarts, Watchtower redeployments, and 30-min session TTL expiry
  • Each POST to /mcp now creates its own transport+server, making requests fully self-contained with no in-memory session state to lose
  • GET and DELETE on /mcp now return 405 (not applicable in stateless mode)
  • Removes ~70 lines of session tracking, cleanup interval, and shutdown logic

Test plan

  • pnpm run build passes
  • All 131 tests pass
  • pnpm run lint clean
  • Security review: no vulnerabilities found
  • Deploy to staging and verify MCP clients can call tools without session errors
  • Verify health endpoint no longer reports activeSessions

Replace stateful session-based transport with stateless per-request
transport to eliminate "Session not found" errors caused by container
restarts, Watchtower redeployments, and session TTL expiry.

Each POST to /mcp now creates its own transport and server instance,
making requests fully self-contained with no in-memory session state
to lose.
Copilot AI review requested due to automatic review settings February 20, 2026 02:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Switches the public MCP HTTP endpoint from session-based (stateful) transport to stateless per-request handling to eliminate “Session not found” errors caused by restarts/TTL expiry.

Changes:

  • Replaced session-tracked /mcp handling with a stateless POST /mcp that creates a transport+server per request.
  • Added explicit 405 responses for GET /mcp and DELETE /mcp in stateless mode and removed activeSessions from /health.
  • Updated .gitignore to exclude local MCP publisher registry/login artifacts.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/index.ts Implements stateless MCP transport per POST request; removes session tracking/cleanup and updates health + shutdown behavior.
.gitignore Ignores .mcpregistry* files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Register res.on('close') before awaiting handleRequest to ensure
  transport cleanup even if handleRequest throws mid-response
- Add mcpLimiter to GET and DELETE /mcp routes for consistency
- Exit process inside server.close() callback for truly graceful shutdown
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fbsobreira fbsobreira merged commit 1949803 into develop Feb 20, 2026
7 checks passed
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.

2 participants