Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug/Documentation Improvement] - How to pass authentication context into tool calls #397

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
alexander-zuev opened this issue Apr 24, 2025 · 4 comments

Comments

@alexander-zuev
Copy link

Hi,

Context

  • I am working on a Cloudflare Worker-based MCP which natively provides authentication context through it's own McpAgent this.props. This is obviously super useful for implementing user-based logic in tool calls.
  • What I want is a clean way to access this info during tool calls, I have read the docs but could find anything remotely relevant in this regard
  • RequestHandlerExtra has a conveniently named AuthInfo which is empty (perhaps it's not set by the workers oauth provider and should be set manually (?)
Image

Question:

  1. Is there an intended clean way to pass auth context to tool calls?
  2. How would you recommend this is done?

I am currently passing the props directly into tool handler which obviously breaks it interface

 for (const tool of allTools) {
            console.log(`Registering tool: ${tool.name}`);
            this.server.tool(tool.name, tool.description, tool.paramsSchema, (params, extra) => {
                return tool.handler(params, extra, this.props);
            });

Am I doing something wrong?

@its-nikhil
Copy link
Contributor

does #399 PR address this issue?

@alexander-zuev
Copy link
Author

I can test - but looks like it? I am not sure workers oauth provider library would do that by default (or does it), but seems like it - @its-nikhil

@pcan
Copy link

pcan commented May 21, 2025

Hi @alexander-zuev, did you manage to make Cloudflare McpAgent work with authInfo? I'm using this.props too, and after looking at the McpAgent source code, it seems there's no way to hook into the invocation of the tool callback to set authInfo 😢

@alexander-zuev
Copy link
Author

Yep, I think they've (SDK devs) actually added a direct way to hook into auth context - I think I have seen it buried somewhere in the release notes.

Otherwise feel free to check out my source code to see how I've done it https://github.com/alexander-zuev/kollektiv-mcp

If I recall I modified the extra interface which is passed with every tool call, but since I did this recently I distinctly remember that I've seen somewhere in SDK notes that there is a more natural way to do that

My approach is not ideal since I had to modify the types which led to a lot of mortal kombat with TS errors

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