-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Addition of client request headers to MCP tools #674
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
Comments
that's amazing, I just spend the whole day debugging the sdk to see if there was a way to get the request headers inside the tool that I was not seen it. This would really be useful to implement multi-tenant based on tokens (where the MCP server itself is not validating the tokens but only forwarding them). |
@rusenbb it seems there is a PR already #380, but it's under review for over a month and it seems there is a bigger problem preventing it to be merged. At this point I'm considering switching to https://gofastmcp.com/, at least documentation is better and features like this one are present, which are the very least for production grade usage. |
You can do it by contextvar @robertofalk |
Thanks! This was helpful. |
Is your feature request related to a problem? Please describe.
Currently, the MCP Python SDK does not expose client request headers to MCP tools. This makes it difficult to implement user-specific access controls or contextual logic within a single server, especially for database queries where permissions are critical. As a result, we’re forced to consider inefficient solutions like deploying separate MCP instances for different clients.
Describe the solution you'd like
Expose client request headers to MCP tools (through the Context object maybe?) so that logic can be adjusted based on user context (e.g., access tokens, roles, tenant IDs). This would allow a single MCP server to securely handle multiple clients and enforce proper access control directly within the tools.
Describe alternatives you've considered
Additional context
This feature would improve multi-tenant support and align with standard API practices for handling authentication and authorization.
The text was updated successfully, but these errors were encountered: