Query Parameter Authenticationยถ
Overviewยถ
Security Warning
Query parameter authentication is inherently insecure (CWE-598). API keys in URLs may appear in proxy logs, browser history, and server access logs. Only use this authentication method when the upstream MCP server requires it (e.g., Tavily MCP).
MCP Gateway supports API key authentication via URL query parameters for upstream MCP servers that mandate this authentication method. This feature is disabled by default and requires explicit opt-in.
Use Casesยถ
Query parameter authentication is specifically designed for:
- Tavily MCP Server: Requires
tavilyApiKeyas a query parameter - Other MCP servers that mandate query parameter authentication
- Legacy APIs that don't support header-based authentication
Prerequisitesยถ
Before using query parameter authentication, you must:
- Enable the feature flag in your environment
- Configure the host allowlist (recommended for production)
Environment Configurationยถ
# Enable query parameter authentication (required)
INSECURE_ALLOW_QUERYPARAM_AUTH=true
# Restrict to specific hosts (recommended for production)
INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS=["mcp.tavily.com"]
Host Allowlist
Always configure INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS in production to restrict which upstream servers can use this authentication method. An empty list [] allows any host.
Configurationยถ
Via Admin UIยถ
- Navigate to the Admin Panel at
http://localhost:8000/admin/ - Click on the "Gateways" tab
- When adding or editing a gateway:
- Select "Query Parameter (INSECURE)" as the Authentication Type
- Read the security warning displayed
- Enter the Query Parameter Name (e.g.,
tavilyApiKey) - Enter the API Key Value
- Submit the form to save your configuration
Via APIยถ
Send a POST request to /admin/gateways with query parameter authentication:
{
"name": "Tavily MCP",
"url": "https://mcp.tavily.com",
"transport": "sse",
"auth_type": "query_param",
"auth_query_param_key": "tavilyApiKey",
"auth_query_param_value": "your-tavily-api-key"
}
Via Python SDKยถ
from mcpgateway.schemas import GatewayCreate
gateway = GatewayCreate(
name="Tavily MCP",
url="https://mcp.tavily.com",
transport="sse",
auth_type="query_param",
auth_query_param_key="tavilyApiKey",
auth_query_param_value="your-tavily-api-key"
)
How It Worksยถ
When a gateway is configured with query parameter authentication:
- Registration: The API key is encrypted and stored in the database
- Connection: The gateway appends the decrypted API key to the URL when connecting
- Tool Invocation: Each request to the upstream server includes the API key in the URL
- Logging: URLs are sanitized before logging to redact sensitive query parameters
Original URL: https://mcp.tavily.com
With Auth: https://mcp.tavily.com?tavilyApiKey=your-api-key
In Logs: https://mcp.tavily.com?tavilyApiKey=REDACTED
Security Considerationsยถ
Risksยถ
- Proxy Logs: API keys may appear in proxy server access logs
- Browser History: If URLs are exposed to browsers, keys may be stored in history
- Server Logs: Upstream servers may log the full URL including query parameters
- Network Monitoring: Network monitoring tools may capture the full URL
Mitigationsยถ
- Feature Flag: Disabled by default, requires explicit opt-in
- Host Allowlist: Restrict which hosts can use this auth method
- Encrypted Storage: API keys are encrypted at rest
- Log Sanitization: Sensitive query parameters are redacted in gateway logs
- UI Warning: Clear security warning displayed in the Admin UI
Recommendationsยถ
- Configure your proxy servers to redact query strings from access logs
- Use the host allowlist to restrict this auth method to specific services
- Rotate API keys regularly
- Monitor for unauthorized access to your API keys
Troubleshootingยถ
"Query parameter authentication is disabled"ยถ
Cause: The feature flag is not enabled.
Solution: Set INSECURE_ALLOW_QUERYPARAM_AUTH=true in your environment.
"Host not in allowed hosts"ยถ
Cause: The upstream host is not in the configured allowlist.
Solution: Add the host to INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS:
API key not being sentยถ
Cause: The gateway may not have the auth_query_params configured correctly.
Solution: Verify the gateway configuration via the API:
Check that auth_type is query_param and auth_query_param_key is set.
Example: Tavily MCP Serverยถ
Here's a complete example of configuring the Tavily MCP server:
1. Enable the Featureยถ
# .env
INSECURE_ALLOW_QUERYPARAM_AUTH=true
INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS=["mcp.tavily.com"]
2. Register the Gatewayยถ
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-here"
}'
3. Create a Virtual Serverยถ
curl -X POST http://localhost:4444/admin/servers \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tavily Search Server",
"gateway_ids": ["<gateway-id-from-step-2>"]
}'
4. Use the Toolsยถ
The Tavily search tools are now available through your virtual server's MCP endpoint.
