Configurable MCP_CLIENT_AUTH_ENABLED closes #705 #710
Merged
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.
PR: Add Configurable MCP Client Authentication for Proxy Deployments closes #705
Overview
This PR implements configurable MCP client authentication to support enterprise deployments where MCP Gateway operates behind authentication proxies. This addresses Issue #705 - "Option to completely remove Bearer token auth to MCP gateway".
Problem Statement
Previously, MCP Gateway required JWT bearer token authentication for all MCP client operations, even when deployed behind enterprise authentication proxies (OAuth2 Proxy, Authelia, Cloudflare Access, etc.). This created unnecessary complexity as organizations had to manage JWT tokens despite having centralized authentication at the proxy layer.
The
AUTH_REQUIRED=false
setting only made authentication optional but didn't fully disable JWT validation, and there was no way to trust proxy-provided user headers.Solution Implemented
New Configuration Options
Added three new environment variables to enable proxy authentication:
MCP_CLIENT_AUTH_ENABLED
(default:true
)false
, bypasses JWT validation entirelyAUTH_REQUIRED
(which controls admin UI auth)TRUST_PROXY_AUTH
(default:false
)true
when disabling MCP client authPROXY_USER_HEADER
(default:X-Authenticated-User
)Key Changes
1. Configuration (
mcpgateway/config.py
)MCP_CLIENT_AUTH_ENABLED=false
withoutTRUST_PROXY_AUTH=true
2. Authentication Logic (
mcpgateway/utils/verify_credentials.py
)require_auth()
to support proxy authenticationsource: "proxy"
indicator for traceability3. WebSocket Security (
mcpgateway/main.py
)4. Test Updates
tests/conftest.py
- Addedmcp_client_auth_enabled=False
to test settingstests/unit/mcpgateway/utils/test_verify_credentials.py
- Added mock Request objects for new parametertests/unit/mcpgateway/test_main.py
- Updated WebSocket test mocking strategytests/unit/mcpgateway/test_main_extended.py
- Updated WebSocket error scenario testtests/unit/mcpgateway/utils/test_proxy_auth.py
- Comprehensive proxy auth test suiteSecurity Considerations
The implementation includes multiple security safeguards:
MCP_CLIENT_AUTH_ENABLED=false
ANDTRUST_PROXY_AUTH=true
source: "proxy"
in user contextTesting
Unit Tests Added (
tests/unit/mcpgateway/utils/test_proxy_auth.py
)Comprehensive test coverage including:
Manual Testing Scenarios
Documentation
Created Documentation Files
docs/docs/deployment/proxy-auth.md
- Deployment guide with examples for:docs/docs/manage/proxy.md
- Comprehensive management guide with:Updated Files
.env.example
- Added new configuration options with descriptionsQuality Assurance
All quality checks pass:
make doctest
- All doctests pass (452 passed)make test
- All unit tests pass (1563 passed, 10 skipped)make htmlcov
- Coverage report generation worksmake smoketest
- Smoke tests passmake lint-web
- Web linting passes (0 vulnerabilities)make flake8
- No Python linting issuesmake bandit
- No security issues identifiedmake interrogate
- Full docstring coverage (100%)make pylint
- Code rated 10.00/10make verify
- Package verification passes (Mascarpone rating)Migration Path
For existing deployments:
Use Cases Enabled
This implementation enables common enterprise patterns:
Benefits
Related Links
Files Changed Summary
Core Implementation
mcpgateway/config.py
- Added proxy auth configurationmcpgateway/utils/verify_credentials.py
- Modified authentication logicmcpgateway/main.py
- Fixed WebSocket auth gap, added proxy supportTests
tests/conftest.py
- Updated test configurationtests/unit/mcpgateway/utils/test_verify_credentials.py
- Fixed for new paramstests/unit/mcpgateway/test_main.py
- Fixed WebSocket teststests/unit/mcpgateway/test_main_extended.py
- Fixed error scenario teststests/unit/mcpgateway/utils/test_proxy_auth.py
- New comprehensive test suiteDocumentation
docs/docs/deployment/proxy-auth.md
- Complete deployment guidedocs/docs/manage/proxy.md
- Management and architecture guide.env.example
- Updated with new variablesChecklist