Skip to content

forward HTTP headers (eg X-API-Key) on tool use #186

@erpic

Description

@erpic

Is your feature request related to a problem? Please describe.

Some fastapi applications are secured with an API Key passed in HTTP headers (eg X-API-Key).
However currently these headers are stripped on tool use. Only "Authorization" is forwarded.

Describe the solution you'd like

Upon construction, headers to be preserved should be passed to FastApiMCP.

Proposing pull request...

Describe alternatives you've considered

Workaround is to use "Authorization" instead of "X-API-Key" in the fastapi application.

Additional context

The MCP server can be created like so:

mcp = FastApiMCP(
    app,
    auth_config=AuthConfig(
        dependencies=[Depends(get_user)]
    ),
    http_headers=["X-API-Key"],
    include_operations=["say_hello"]
)

The MCP server can then be added to a client like so:

{
  "mcpServers": {
    "local-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:8000/mcp",
        "--header",
        "X-API-Key:${API_KEY}"
      ],
      "env": {
        "API_KEY": "xxx"
      }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions