Skip to content
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

Add sessionID to RequestHandlerExtra type for tool invocations so multi-user services can distinguish users #158

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jwvictor
Copy link

Added a sessionID field to the RequestHandlerExtra data that gets passed to tool callbacks, and wired it through from the transport session ID. Exposed the sessionID field on the abstract Transport interface.

Motivation and Context

This allows multi-user SSE-based MCP servers distinguish which user is invoking the tool based on their session ID (which in turn can be mapped to any data derived from the authentication token passed in HTTP headers).

Without this change, tool callbacks being served over SSE can't tell which user is making the request.

How Has This Been Tested?

Made a test service and tested it with Inspector. The tool callback was able to resolve the user ID associated with the requester's API key by using a map from session ID to user ID.

Breaking Changes

No.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

N/A

Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

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

Thanks, good idea! Just the one comment. If you're able to add a test for this as well, that would be stellar—but not a blocker.

@@ -41,4 +41,6 @@ export interface Transport {
* Callback for when a message (request or response) is received over the connection.
*/
onmessage?: (message: JSONRPCMessage) => void;

sessionId?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a docstring here?

Copy link
Author

Choose a reason for hiding this comment

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

You bet, I'll take a look this afternoon

Copy link
Author

Choose a reason for hiding this comment

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

Hey sir - added a test and a doc string, let me know if you need anything else!

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.

3 participants