Skip to content

Conversation

@elijahdev0
Copy link
Owner

This PR implements authentication support for FastAPI-MCP as discussed in issue tadata-org#10.

Features added:

  • Authentication module with support for:
    • Bearer token authentication
    • API key authentication (in header or query)
    • Custom authentication functions
  • Added auth_config parameter to add_mcp_server and mount_mcp_server functions
  • Authentication is applied to both the SSE connection endpoint and message endpoint
  • Updated documentation in README
  • Added examples:
    • authenticated_server.py - JWT authentication example
    • simple_bearer_auth.py - Simple bearer token example

This implementation follows the MCP authentication specification, which recommends using bearer tokens in the Authorization header.

How to use:

from fastapi import FastAPI
from fastapi_mcp import add_mcp_server, AuthConfig

app = FastAPI()

# Configure authentication
auth_config = AuthConfig(
    enabled=True,
    bearer_token="your-secret-token"
)

# Add MCP server with authentication
mcp_server = add_mcp_server(
    app,
    mount_path="/mcp",
    auth_config=auth_config
)

For more complex authentication scenarios, custom authentication functions are supported.

Fixes tadata-org#10

@shahar4499
Copy link

@elijahdev0 Hey, thank you! Looks promising. I will review this PR, but you need to open it in the original repo for it to be mergeable. Right now it's open only in your fork :)

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.

Support Authentication According to Current MCP Spec

3 participants