feat: add PoC of stateless HTTP transport #24
+415
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an implementation of a stateless transport over HTTP for MCP. It's not part of the official spec, but something similar will probably be added in the future.
Functionally, it just presents a single HTTP endpoint (conventionally at
/mcp
) that accepts JSONRPC messages as POST bodies, and returns JSONRPC messages as responses.Each inbound message is validated and gets its own 'server' instance. The handler then takes care of initializing the server (which in a stateless protocol is the responsibility of the client), then forwards the inbound message to the server, and returns the server's response.
We could easily add middleware for things like authentication, similar to in #21.
This also comes with a 'client' implementation which is similar to the stdio and sse clients in the official SDK and returns a pair of read/write streams for use with a
ClientSession
. This is useful for testing or writing example MCP clients.The idea is that this transport will be compatible with the HTTP transport in the unofficial Go SDK, so we can start building examples of usage. Notably this client also supports custom headers, which will be useful for authentication.
You can test this out locally by running it like this:
uvx --with-editable . mcp-grafana --transport http
Then calling it like this: