Skip to content

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

Open
@alexander-zuev

Description

@alexander-zuev

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions