Skip to content

Key auth support for MCP Servers - closes #1580#2194

Merged
crivetimihai merged 9 commits intomainfrom
key-auth
Jan 19, 2026
Merged

Key auth support for MCP Servers - closes #1580#2194
crivetimihai merged 9 commits intomainfrom
key-auth

Conversation

@crivetimihai
Copy link
Copy Markdown
Member

@crivetimihai crivetimihai commented Jan 19, 2026

Summary

Add support for API key authentication via URL query parameters for upstream MCP servers that require this method (e.g., Tavily MCP).

This feature is disabled by default and requires explicit opt-in due to the inherent security risks of exposing API keys in URLs (CWE-598).

Motivation

Some MCP servers (such as Tavily) require API key authentication via URL query parameters rather than HTTP headers. The existing authentication mechanisms (Basic, Bearer, OAuth, Custom Headers) all work through HTTP headers, making it impossible to connect to these services without this feature.

Closes #1580

Changes

Database & Schema

  • Add auth_query_params JSON column to gateways table (Alembic migration)
  • Add auth_query_param_key and auth_query_param_value fields to GatewayCreate/Update schemas
  • Add auth_query_param_key and auth_query_param_value_masked fields to GatewayRead schema
  • Add Pydantic validators for feature flag and host allowlist enforcement

Configuration

  • Add INSECURE_ALLOW_QUERYPARAM_AUTH feature flag (default: false)
  • Add INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS allowlist (default: [])
  • Update .env.example with documentation
  • Update Helm chart values.yaml

Services

  • GatewayService: Handle query_param auth in register/update, apply to SSE/StreamableHTTP connections
  • ToolService: Decrypt and apply query params to URL during tool invocation
  • ResourceService: Apply query params to URL during resource fetch
  • ExportService: Include auth_query_params in gateway exports
  • ImportService: Handle auth_query_params in gateway imports

Utilities

  • Create mcpgateway/utils/url_auth.py with:
    • apply_query_param_auth(): Append decrypted auth params to URLs
    • sanitize_url_for_logging(): Redact sensitive params before logging
    • STATIC_SENSITIVE_PARAMS: FrozenSet of known sensitive parameter names

Admin UI

  • Add "Query Parameter (INSECURE)" option to auth type dropdown
  • Add security warning banner when selected
  • Add input fields for parameter name and API key value
  • Handle display of masked values when editing existing gateways

Documentation

  • Add ADR-035: Query Parameter Authentication for Gateway Peers
  • Add usage guide: docs/docs/using/query-param-auth.md
  • Update README.md with new environment variables
  • Update CLAUDE.md with Alembic migration guidance

Security Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     Security Controls                           │
├─────────────────────────────────────────────────────────────────┤
│  Layer 1: Feature Flag (INSECURE_ALLOW_QUERYPARAM_AUTH)         │
│           └─ Disabled by default, requires explicit opt-in      │
├─────────────────────────────────────────────────────────────────┤
│  Layer 2: Host Allowlist (INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS)│
│           └─ Empty = any host, Non-empty = strict allowlist     │
├─────────────────────────────────────────────────────────────────┤
│  Layer 3: Encrypted Storage (AUTH_ENCRYPTION_SECRET)            │
│           └─ API keys encrypted at rest in database             │
├─────────────────────────────────────────────────────────────────┤
│  Layer 4: Log Sanitization (sanitize_url_for_logging)           │
│           └─ Sensitive params redacted before any logging       │
├─────────────────────────────────────────────────────────────────┤
│  Layer 5: UI Warning                                            │
│           └─ Explicit security warning in Admin UI              │
└─────────────────────────────────────────────────────────────────┘

Example Usage

Enable the Feature

INSECURE_ALLOW_QUERYPARAM_AUTH=true
INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS=["mcp.tavily.com"]

Register Tavily MCP

curl -X POST http://localhost:4444/admin/gateways \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Tavily Search",
    "url": "https://mcp.tavily.com",
    "transport": "sse",
    "auth_type": "query_param",
    "auth_query_param_key": "tavilyApiKey",
    "auth_query_param_value": "tvly-your-api-key"
  }'

Testing

  • Unit tests for url_auth.py (19 tests)
  • All existing tests pass (5182 passed)
  • make pylint passes (10.00/10)
  • make flake8 passes
  • make bandit passes
  • Alembic migration verified (single head)

Checklist

  • Code follows project conventions
  • Tests added for new functionality
  • Documentation updated (README, ADR, usage guide)
  • Environment variables documented in .env.example
  • Helm chart updated
  • Security implications documented
  • Commits signed (DCO)

Add support for API key authentication via URL query parameters for
upstream MCP servers that require this method (e.g., Tavily MCP).

Security controls:
- Feature disabled by default (INSECURE_ALLOW_QUERYPARAM_AUTH=false)
- Host allowlist restricts which servers can use this auth method
- API keys encrypted at rest using AUTH_ENCRYPTION_SECRET
- URLs sanitized before logging to redact sensitive parameters
- Explicit security warnings in Admin UI

Changes:
- Add auth_query_params column to gateways table with Alembic migration
- Add query_param auth type to GatewayCreate/Update/Read schemas
- Create mcpgateway/utils/url_auth.py with helper functions
- Update gateway, tool, resource services to handle query param auth
- Update export/import services for backup/restore support
- Add Query Parameter (INSECURE) option to Admin UI
- Add feature flags to config.py, .env.example, Helm values.yaml
- Add ADR-035 and usage documentation
- Add unit tests for url_auth module
- Update AGENTS.md with Alembic migration guidance

Closes #1580

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Use explicit + concatenation for multi-line error messages in
ValueError raises to satisfy pylint W1404 checks.

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai changed the title Key auth Closes #1580 Key auth support for MCP Servers - closes #1580 Jan 19, 2026
@crivetimihai crivetimihai added the wxo wxo integration label Jan 19, 2026
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
- Fix auth_type overwrite bug: Only update auth_type when explicitly
  provided in update (not when None)
- Apply query-param auth to activation/refresh/health-check paths
- Sanitize server_url in structured tool logs to prevent key leakage
- Update test assertions to use settings.masked_auth_value consistently

Fixes URL allowlist bypass, structured log exposure, and initialization
paths for query_param gateways.

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai self-assigned this Jan 19, 2026
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai marked this pull request as ready for review January 19, 2026 21:49
@crivetimihai crivetimihai merged commit 5b3d5a9 into main Jan 19, 2026
50 checks passed
@crivetimihai crivetimihai deleted the key-auth branch January 19, 2026 22:06
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
* feat: Add query parameter authentication for gateway peers (IBM#1580)

Add support for API key authentication via URL query parameters for
upstream MCP servers that require this method (e.g., Tavily MCP).

Security controls:
- Feature disabled by default (INSECURE_ALLOW_QUERYPARAM_AUTH=false)
- Host allowlist restricts which servers can use this auth method
- API keys encrypted at rest using AUTH_ENCRYPTION_SECRET
- URLs sanitized before logging to redact sensitive parameters
- Explicit security warnings in Admin UI

Changes:
- Add auth_query_params column to gateways table with Alembic migration
- Add query_param auth type to GatewayCreate/Update/Read schemas
- Create mcpgateway/utils/url_auth.py with helper functions
- Update gateway, tool, resource services to handle query param auth
- Update export/import services for backup/restore support
- Add Query Parameter (INSECURE) option to Admin UI
- Add feature flags to config.py, .env.example, Helm values.yaml
- Add ADR-035 and usage documentation
- Add unit tests for url_auth module
- Update AGENTS.md with Alembic migration guidance

Closes IBM#1580

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* fix: resolve pylint implicit string concatenation warnings

Use explicit + concatenation for multi-line error messages in
ValueError raises to satisfy pylint W1404 checks.

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* Fix eslint

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* Fixes

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* fix: Address remaining query-param auth review findings

- Fix auth_type overwrite bug: Only update auth_type when explicitly
  provided in update (not when None)
- Apply query-param auth to activation/refresh/health-check paths
- Sanitize server_url in structured tool logs to prevent key leakage
- Update test assertions to use settings.masked_auth_value consistently

Fixes URL allowlist bypass, structured log exposure, and initialization
paths for query_param gateways.

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* docs: Add docstring for default_handler_factory in mcp_session_pool

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* Fixes

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* Lint fixes

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* Lint fixes

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wxo wxo integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE][AUTH]: API key auth support through query params

1 participant