Skip to content

[Bug]: Authorization header not sent to MCP server despite configuration #19341

Description

@pavianogiacomo

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

LiteLLM does not send the configured Authorization header when connecting to an MCP server, causing 401 Unauthorized errors even though the header is properly specified in config.yaml.

Steps to Reproduce

  1. Configure an MCP server in config.yaml like this:
mcp_servers:
 name:
    url: "https://name.example.com"
    alias: NAME
    spec_path: "/app/name.json"
    auth_type: "none"
    static_headers: 
      Authorization: "STATIC <YOUR_TOKEN>"
  1. Start LiteLLM and try to list MCP tools:
POST /mcp-rest/test/tools/list

Expected behavior

LiteLLM should include the Authorization: STATIC <YOUR_TOKEN> header in requests to the MCP server, and the server should respond with 200 OK and the list of tools.

Actual behavior

LiteLLM fails with 401 Unauthorized:
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://name.example.com'

Logs show:

LiteLLM:WARNING: MCP client run_with_session failed
LiteLLM:ERROR: unhandled errors in a TaskGroup

Environment
LiteLLM version: 1.80.15
Python version: 3.13
OS: Linux (Docker container)

docker compose config

services:
litellm:
image: ghcr.io/berriai/litellm:main-v1.80.15-stable
container_name: litellm
networks:
- default
- caddy
labels:
caddy: api.dev.name.com
caddy.import: tls_route53
caddy.reverse_proxy: "{{upstreams 4000}}"
volumes:
- ./config.yaml:/app/config.yaml:ro
- ./name.json:/app/name.json:ro
command:
- "--config=config.yaml"
environment:
- LITELLM_MASTER_KEY=<MASTER_KEY>
- DATABASE_URL=postgresql://litellm:@postgres:5432/litellm
- STORE_MODEL_IN_DB=True
restart: unless-stopped

postgres:
image: docker.io/postgres:${POSTGRES_VERSION:-latest}
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U litellm"]
interval: 3s
timeout: 3s
retries: 10
environment:
POSTGRES_USER: litellm
POSTGRES_PASSWORD:
POSTGRES_DB: litellm
ports:
- 5433:5432
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata:

networks:
default:
caddy:
external: true

## Additional Info
The header works correctly with curl:
curl -H "Authorization: STATIC <YOUR_TOKEN>" https://name.example.com/path

The issue seems related to static_headers not being forwarded during session.initialize() and tool discovery.
Currently, a reverse proxy can be used to inject the header until LiteLLM fixes the bug.

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.80.15

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingproxy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions