Skip to content

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

Open
rusenbb opened this issue May 9, 2025 · 4 comments
Open

Addition of client request headers to MCP tools #674

rusenbb opened this issue May 9, 2025 · 4 comments

Comments

@rusenbb
Copy link

rusenbb commented May 9, 2025

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

  • Running separate MCP servers per client (inefficient and hard to scale).
  • Passing user data through request bodies (insecure because of LLM interference risk).
  • Adding custom middleware outside of MCP (adds unnecessary complexity, and still not accessible within tools).

Additional context
This feature would improve multi-tenant support and align with standard API practices for handling authentication and authorization.

@robertofalk
Copy link

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).

@robertofalk
Copy link

@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.

@sidey
Copy link

sidey commented May 10, 2025

You can do it by contextvar @robertofalk

@rusenbb
Copy link
Author

rusenbb commented May 16, 2025

@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.

Thanks! This was helpful.

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

No branches or pull requests

3 participants