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).
ContextForge 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.
Admin UI URL
- Direct installs (
uvx, pip, ordocker run):http://localhost:4444/admin/ - Docker Compose (nginx proxy):
http://localhost:8080/admin/ - Dev server (
make dev):http://localhost:8000/admin/
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 (see Admin UI URL above)
- 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
The Admin UI displays an inline warning when you select query-parameter authentication to highlight the security risks.
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.