Skip to content

Feat: Add stateless mode for StreamableHttpServerTransport #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2025

Conversation

CodeWithKyrian
Copy link
Contributor

This PR adds stateless mode support to StreamableHttpServerTransport to handle clients that have issues with persistent session management.

What changed:

  • Added stateless parameter to StreamableHttpServerTransport constructor
  • Modified Protocol::processMessage to auto-initialize sessions in stateless contexts
  • Updated test infrastructure to support stateless mode testing
  • Added comprehensive test coverage for stateless behavior

Why it's needed:
OpenAI's MCP implementation terminates sessions after the initial tool discovery phase when running in "never require approval" mode. This causes subsequent tool calls to fail with session validation errors.

In stateless mode:

  • Session IDs are generated internally but not exposed to clients
  • Each request is treated as independent
  • Sessions are auto-initialized for non-initialize requests
  • No session persistence between requests

The other transport types (StdioServerTransport, HttpServerTransport) are unaffected since they have different session requirements.

OpenAI's MCP implementation terminates sessions after tool discovery in "never require approval" mode, causing subsequent tool calls to fail. This adds a stateless mode where each request is independent and sessions are auto-initialized when needed.
@CodeWithKyrian CodeWithKyrian merged commit 2accc57 into main Jul 12, 2025
@CodeWithKyrian CodeWithKyrian deleted the feat/stateless-mode-streamable-transport branch July 12, 2025 21:26
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