-
Notifications
You must be signed in to change notification settings - Fork 394
Pass session id's to MCP endpoints. #466
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
Pass session id's to MCP endpoints. #466
Conversation
src/ModelContextProtocol/Server/StreamableHttpServerTransport.cs
Outdated
Show resolved
Hide resolved
tests/ModelContextProtocol.AspNetCore.Tests/HttpServerIntegrationTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than exposing the SessionId, is there any other reason we want to expose the ITransport on the IMcpEndpoint? If not, should we start with exposing just the SessionId and not the entire ITransport?
I'd also consider just telling people to use IHttpContextAccessor to read the mcp-session-id response header inside their tools and other handlers if they care. It should be just as reliable without mucking up our core interfaces like ITransport and IMcpEndpoint with stuff that isn't that relevant to non-HTTP transports. This is more discoverable though for people creating their own logs, so I see the appeal there, but maybe we could just add documentation and hold off on the API change.
I think this would be more valuable if we included the session id in all the logs that can realistically have them similar to what we do for Kestrel with connection IDs and request IDs.
tests/ModelContextProtocol.AspNetCore.Tests/HttpServerIntegrationTests.cs
Show resolved
Hide resolved
Exposing the transport seems like the reasonable thing to do given that each MCP endpoint corresponds to one instance. What are some of the drawbacks of doing it? Lack of encapsulation? I have no strong opinions on the matter.
Sure, but this only works provided that you only use your tools with streamable http exclusively. If your tool is invoked via legacy sse there is no |
35fd9a3
to
ff9421a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are some of the drawbacks of doing it? Lack of encapsulation? I have no strong opinions on the matter.
Mostly the lack of encapsulation. We can always update this later, but I'd prefer to just expose the string? SessionId on the IMcpEndpoint for now.
My two cents: If a user implementation of an MCP server has no business sending JSON-RPC messages or other functionality exposed by |
Co-authored-by: Stephen Halter <[email protected]>
Co-authored-by: Stephen Halter <[email protected]>
ff9421a
to
0176c6c
Compare
I've updated |
d7d9eab
into
modelcontextprotocol:main
Ensures that MCP servers and clients have access to the underlying session id (typically the value of the
Mcp-Session-Id
header in streamable http). It does so by making the following (breaking) API changes:SessionId
property to theITransport
interface.Transport
property to theIMcpEndpoint
interface.This lets consumers of
IMcpServer
andIMcpClient
obtain the underlying session id by evaluatingendpoint.Transport.SessionId
. Note that the session id can be null if