Skip to content

Conversation

@zmofei
Copy link
Member

@zmofei zmofei commented Aug 5, 2025

Summary

This PR adds support for passing authentication tokens to Mapbox API tools through the MCP protocol, enabling Bearer token authentication as an alternative to environment variables.

Changes

  • Added support for receiving authentication tokens via the MCP request context
  • Modified BaseTool to accept and pass through authentication tokens from the request
  • Updated all Mapbox API tools to use the provided token or fall back to environment variable
  • Updated tool templates to support the new authentication pattern
  • Fixed failing tests related to token validation

How it works

Tools now support two authentication methods:

  1. Bearer token via MCP (preferred): Pass token through the authentication context
  2. Environment variable (fallback): Use MAPBOX_ACCESS_TOKEN environment variable

This enables more flexible authentication when using the tools through MCP clients that support Bearer authentication.

@zmofei zmofei changed the title Fix failing tests for token validation Add authentication token support for Mapbox API tools Aug 5, 2025
@zmofei zmofei changed the title Add authentication token support for Mapbox API tools Support authentication token parameter for Mapbox API tools Aug 5, 2025
- Add support for passing authentication tokens via MCP request context
- Modified BaseTool to accept and pass through authentication tokens
- Update all Mapbox API tools to use provided token or fall back to env variable
- Fix failing tests related to token validation
- Simplify execute method signature by removing unused extra parameter
@zmofei zmofei marked this pull request as ready for review August 5, 2025 12:17
@zmofei zmofei requested a review from a team as a code owner August 5, 2025 12:17
async run(rawInput: unknown): Promise<z.infer<typeof OutputSchema>> {
async run(
rawInput: unknown,
extra?: RequestHandlerExtra<any, any>
Copy link

@ivan-yankavets ivan-yankavets Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zmofei , can we have this somehow in the base class so that we don't need to pass it to every tool?
this supposed to remove some code duplication.

run could store token in a property and exec simply use it as it was with MAPBOX_ACCESS_TOKEN

Copy link

@ivan-yankavets ivan-yankavets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to move some of the code to the base method,
but i'm good with everything else.

ivan-yankavets
ivan-yankavets approved these changes Aug 7, 2025
@zmofei zmofei merged commit 9d0d66a into main Aug 7, 2025
1 check passed
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.

2 participants