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

Include AuthInfo from Bearer Validation in Server Request Handler #166

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

Conversation

allenzhou101
Copy link

@allenzhou101 allenzhou101 commented Feb 28, 2025

Includes the req.auth AuthInfo that's set by the MCP Server bearer auth middleware in the server request handler via SSE Transport, allowing for distinguishing of users in requests (eg. tool use).

Motivation and Context

When an MCP Server makes a tool call it may need to validate that a particular user has the authorization necessary to access a particular resource. For instance, the MCP Client could give any email it would like to the MCP Server, say to fetch audit logs of a project, but the Server should verify that the user has access to that particular project, which has to happen at the tool call level in the server.

This PR allows the developer to access the auth info not only in the initial /sse or /message route handlers but in the server request handler (eg. tool call) itself.

How Has This Been Tested?

Running an authenticated MCP Client session with a Server and validating that the extra param appears in the tool call with auth info.

Breaking Changes

None.

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

This allows for simpler access of auth data than simply including the session id in the transport since you'd have to handle mapping in that case: #158

@allenzhou101 allenzhou101 changed the title Include AuthInfo from bearer validation in transport request handler Include AuthInfo from Bearer Validation in Server Request Handler Feb 28, 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.

1 participant