Key auth support for MCP Servers - closes #1580#2194
Merged
crivetimihai merged 9 commits intomainfrom Jan 19, 2026
Merged
Conversation
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>
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>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
auth_query_paramsJSON column togatewaystable (Alembic migration)auth_query_param_keyandauth_query_param_valuefields to GatewayCreate/Update schemasauth_query_param_keyandauth_query_param_value_maskedfields to GatewayRead schemaConfiguration
INSECURE_ALLOW_QUERYPARAM_AUTHfeature flag (default:false)INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTSallowlist (default:[]).env.examplewith documentationvalues.yamlServices
auth_query_paramsin gateway exportsauth_query_paramsin gateway importsUtilities
mcpgateway/utils/url_auth.pywith:apply_query_param_auth(): Append decrypted auth params to URLssanitize_url_for_logging(): Redact sensitive params before loggingSTATIC_SENSITIVE_PARAMS: FrozenSet of known sensitive parameter namesAdmin UI
Documentation
docs/docs/using/query-param-auth.mdSecurity Architecture
Example Usage
Enable the Feature
INSECURE_ALLOW_QUERYPARAM_AUTH=true INSECURE_QUERYPARAM_AUTH_ALLOWED_HOSTS=["mcp.tavily.com"]Register Tavily MCP
Testing
url_auth.py(19 tests)make pylintpasses (10.00/10)make flake8passesmake banditpassesChecklist
.env.example