Skip to content

Add stateless feature to Streamable HTTP protocol #101

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bigH
Copy link

@bigH bigH commented Jul 31, 2025

See: #99

Currently, this implementation of MCP requires that sessions are held in memory for Server-Sent Events (SSEs). The session data maps an ID to a live IO stream. This doesn't work for Chime for a few reasons:

  • We run >1 replica, so in-memory storage of session state is not going to work
  • When contacting a backend with no knowledge of a given session, the server responds with an error, breaking downstream agent functionality
  • Chime's default configuration doesn't allow for long-lived connections and connections are terminated forcibly after a timeout

So, here we add tests and validate that stateless configuration behaves according to spec. In situations where the spec is unclear about something, we defer to the Python SDK.

@koic
Copy link
Member

koic commented Aug 1, 2025

Does handle_post method need to handle the case for stateless?

@bigH
Copy link
Author

bigH commented Aug 1, 2025

Does handle_post method need to handle the case for stateless?

My understanding is that it does not. handle_post calls handle_regular_request, which only uses SSE if a stream exists.

I've tested this against my own service and it works properly. What would it take to get this merged?

@koic
Copy link
Member

koic commented Aug 2, 2025

Ah, I see. Thank you for the explanation. Can you squash your commits into one?

@bigH
Copy link
Author

bigH commented Aug 5, 2025

Happy to.

@bigH bigH force-pushed the stateless branch 2 times, most recently from a2c47d2 to ca3537e Compare August 5, 2025 17:32
@bigH
Copy link
Author

bigH commented Aug 5, 2025

Rebased on to latest main and squashed my commits.

koic
koic previously approved these changes Aug 6, 2025
- Create failing tests for `stateless` mode
- Implement `stateless` mode by turning of SSE in Streamable HTTP,
  making the interaction a standard HTTP Req/Resp
@bigH
Copy link
Author

bigH commented Aug 6, 2025

Bump @koic. I think this is good to review/merge.

Comment on lines +671 to +677
assert_raises(RuntimeError, "Stateless mode does not support notifications") do
stateless_transport.send_notification(
"test_notification",
{ message: "Hello" },
session_id: "some_session_id",
)
end
Copy link
Member

Choose a reason for hiding this comment

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

If my understanding is correct, it would be as follows.

Suggested change
assert_raises(RuntimeError, "Stateless mode does not support notifications") do
stateless_transport.send_notification(
"test_notification",
{ message: "Hello" },
session_id: "some_session_id",
)
end
e = assert_raises(RuntimeError) do
stateless_transport.send_notification(
"test_notification",
{ message: "Hello" },
session_id: "some_session_id",
)
end
assert_equal("Stateless mode does not support notifications", e.message)

assert_equal({ "Content-Type" => "application/json" }, response[1])

body = response[2][0]
assert body.blank?
Copy link
Member

Choose a reason for hiding this comment

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

That's just my two cents.

Suggested change
assert body.blank?
assert_nil(body)

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