Skip to content

Conversation

ln-12
Copy link
Contributor

@ln-12 ln-12 commented Jul 23, 2025

When the client lost the connection to the mcp server or the mcp server runs on distributed nodes (e.g. behind a loadbalancer), it can be desired to run the server in stateless mode. When doing so, the Mcp-Session-Id should not generated or verified to allow the execution of methods without prior initialization.

Or would it be better to still generate the session id and send the Mcp-Session-Id but just not validate it?

The Rust sdk, mcp-go and the typescript sdk also support it for example. Additionally, this mode is mentioned in the typescript documentation although the official documentation does not seem to contain any information about it.

Fixes #148

When the client lost the connection to the mcp server or the mcp server runs on distributed nodes (e.g. behind a loadbalancer), it can be desired to run the server in stateless mode. When doing so, the Mcp-Session-Id should not generated or verified to allow the execution of methods without prior initialization.

Fixes modelcontextprotocol#148
# Conflicts:
#	mcp/server.go
#	mcp/streamable.go
@ln-12
Copy link
Contributor Author

ln-12 commented Jul 24, 2025

One issue I found so far is that for example sending log messages from the server to the client is not working as the session id is needed for that. So maybe it would be better to still generate and send the session id but simply not validate it like I tested on this branch.

Please let me know what you think about it.

# Conflicts:
#	mcp/streamable.go
@findleyr
Copy link
Contributor

findleyr commented Aug 9, 2025

Thanks for this! I implemented stateless mode slightly differently in #277, because in the context of #148 we're talking about APIs for loading and initializing sessions, for which a 'stateless session' is just a special case. I also went the route of the typescript SDK and triggered stateless mode whenever a new user-provided GetSessionID function returns the empty string.

However, I used your test, and your logic was very helpful. I added you as a Co-Author on that commit.

@ln-12
Copy link
Contributor Author

ln-12 commented Aug 12, 2025

Thanks for implementing it, I will then close this one.

@ln-12 ln-12 closed this Aug 12, 2025
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.

Proposal: Session recovery / shared session storage for distributed MCP env
2 participants