[Feature Request] Add Enterprise Network Support for MCP Proxy
Summary
Add opt-in configuration to support ucode mcp-proxy in corporate environments with HTTP proxies and custom CA certificates, eliminating the need for manual patching.
Problem
ucode mcp-proxy fails to connect to Databricks MCP servers in enterprise environments with:
- Corporate HTTP proxies (
HTTP_PROXY environment variable)
- Custom CA certificates (
SSL_CERT_FILE pointing to corporate CA bundle)
Error:
Failed to connect to databricks-app-mcp-server-12
MCP server connection timed out after 30000ms
Root Cause
Two httpx2 library behaviors break in corporate networks:
-
httpx2 ignores proxy=None: The AsyncClient(proxy=None) parameter is ignored; httpx2 still reads HTTP_PROXY/HTTPS_PROXY environment variables, routing internal servers through the corporate proxy unnecessarily
-
SSL_CERT_FILE replaces system trust store: When set, httpx2 uses only the custom CA bundle, ignoring the system trust store. This breaks verification of legitimate public certificates (e.g., Databricks' DigiCert certificates)
Current Workaround
Users must manually patch src/ucode/mcp_proxy.py (~25 lines), which:
- Doesn't scale for enterprise deployments
- Breaks on updates
- Requires technical knowledge to apply
Proposed Solution
Add opt-in environment variables for enterprise network support:
UCODE_MCP_ENTERPRISE_MODE=1 # Enable both features (recommended)
UCODE_MCP_PROXY_BYPASS=1 # Enable proxy bypass only
UCODE_MCP_USE_SYSTEM_TRUST_STORE=1 # Enable system trust store only
User Configuration
In ~/.claude/mcp.json:
{
"mcpServers": {
"databricks-mcp": {
"type": "stdio",
"command": "/path/to/ucode",
"args": ["mcp-proxy", "--url", "...", "--host", "...", "--profile", "..."],
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1"
}
}
}
}
That's it! No code changes, no manual patching.
Implementation Details
Changes to src/ucode/mcp_proxy.py
async def _run(url: str, workspace: str, profile: str | None) -> None:
import os
httpx = _httpx()
auth = _build_token_auth(workspace, profile)
saved_env_vars = {}
# Check opt-in flags
enterprise_mode = os.environ.get('UCODE_MCP_ENTERPRISE_MODE') == '1'
proxy_bypass = os.environ.get('UCODE_MCP_PROXY_BYPASS') == '1' or enterprise_mode
use_system_trust = os.environ.get('UCODE_MCP_USE_SYSTEM_TRUST_STORE') == '1' or enterprise_mode
# Proxy bypass (when enabled and URL matches NO_PROXY)
if proxy_bypass:
no_proxy_list = os.environ.get('NO_PROXY', '').split(',')
if any(p.strip() and p.strip() in url for p in no_proxy_list):
for key in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
# System trust store (when enabled)
if use_system_trust:
for key in ['SSL_CERT_FILE', 'REQUESTS_CA_BUNDLE']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
try:
async with httpx.AsyncClient(...) as http_client:
# ... existing code ...
finally:
os.environ.update(saved_env_vars) # Always restore
Lines changed: ~30 lines added, 0 removed, 1 modified (add try/finally)
Benefits
✅ No breaking changes - Opt-in, backward compatible
✅ Configuration only - No manual patching required
✅ Secure - Maintains full SSL verification
✅ Granular control - Enable features individually or together
✅ Enterprise ready - Works with various corporate network setups
✅ Easy to maintain - Simple, clean implementation
Testing
Verified in production environment:
- ✅ Corporate proxy (NO_PROXY bypass works)
- ✅ Custom CA certificates (system trust store works)
- ✅ Full SSL verification maintained (DigiCert verified)
- ✅ Backward compatible (no issues when disabled)
- ✅ Environment variables properly restored
Alternatives Considered
- Auto-detection - Too implicit, harder to troubleshoot
- Configuration file - Adds complexity, environment vars are standard
- CLI flags - Doesn't work well with MCP server spawning
- Upstream httpx2 fix - Out of our control, takes time
Impact
- Affected users: Enterprise deployments with proxy + custom CA certificates
- Risk: Very low (opt-in, minimal code changes)
- Effort: 4-5 days (implementation + tests + docs)
Documentation
Will need updates to:
- README.md (add Enterprise Network Configuration section)
- Troubleshooting guide (add corporate network section)
- API reference (document environment variables)
References
- Full proposal: (attach
ucode_upstream_proposal.md)
- Implementation: (attach
ucode_PR_implementation.py)
- Bug report: (attach
httpx2-mcp-proxy-bug-report.md)
Questions?
Happy to discuss implementation details, provide more test cases, or clarify any aspect of this proposal.
Reporter: Sergei Alekseev (sergei.alekseev@novartis.com)
Date: 2026-09-16
Tested Environment: macOS, Python 3.12.13, httpx2 2.13.0, Corporate network with proxy + custom CA
Upstream Feature Proposal: Configurable Proxy and SSL Handling for ucode mcp-proxy
Target Repository: https://github.com/databricks/unity-gateway
Component: src/ucode/mcp_proxy.py
Issue: MCP proxy fails in corporate environments with proxy servers and custom CA certificates
Proposed By: Sergei Alekseev (sergei.alekseev@novartis.com)
Date: 2026-09-16
Problem Statement
ucode mcp-proxy fails to connect to Databricks MCP servers in corporate environments due to:
- httpx2 ignores
proxy=None: The library reads HTTP_PROXY/HTTPS_PROXY environment variables even when proxy bypass is needed
- SSL_CERT_FILE replaces system trust store: When set, httpx2 uses only the custom CA bundle, breaking verification of public certificates
Current Impact:
- Users experience 30-second timeout errors
- Manual patching required (not scalable)
- Affects enterprise deployments with proxy + custom CA certificates
Proposed Solution: Environment-Based Configuration
Add opt-in environment variables that allow users to configure proxy and SSL behavior without code changes.
Design Principles
- ✅ Backward Compatible - No changes for users without these issues
- ✅ Opt-In - Users explicitly enable the workarounds
- ✅ Secure - Maintains SSL verification by default
- ✅ Configurable - Works for various corporate network setups
- ✅ No Breaking Changes - Existing functionality unchanged
Implementation Design
New Environment Variables
# Enable proxy bypass for URLs matching NO_PROXY patterns
UCODE_MCP_PROXY_BYPASS=1
# Use system trust store instead of SSL_CERT_FILE for MCP connections
UCODE_MCP_USE_SYSTEM_TRUST_STORE=1
# Alternative: Combined flag for enterprise environments
UCODE_MCP_ENTERPRISE_MODE=1
Implementation in mcp_proxy.py
async def _run(url: str, workspace: str, profile: str | None) -> None:
import os
httpx = _httpx()
auth = _build_token_auth(workspace, profile)
saved_env_vars = {}
# Check if enterprise/proxy bypass mode is enabled
enterprise_mode = os.environ.get('UCODE_MCP_ENTERPRISE_MODE') == '1'
proxy_bypass_enabled = (
os.environ.get('UCODE_MCP_PROXY_BYPASS') == '1' or enterprise_mode
)
use_system_trust = (
os.environ.get('UCODE_MCP_USE_SYSTEM_TRUST_STORE') == '1' or enterprise_mode
)
# Proxy bypass logic (opt-in)
if proxy_bypass_enabled:
no_proxy_list = os.environ.get('NO_PROXY', '').split(',')
should_bypass = any(
pattern.strip() and pattern.strip() in url
for pattern in no_proxy_list
)
if should_bypass:
for key in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
# System trust store logic (opt-in)
if use_system_trust:
for key in ['SSL_CERT_FILE', 'REQUESTS_CA_BUNDLE']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
# Rest of the function with try/finally to restore environment
try:
async with httpx.AsyncClient(
auth=auth,
timeout=httpx.Timeout(
connect=30.0,
read=300.0,
write=30.0,
pool=30.0,
),
) as http_client:
async with streamable_http_client(url, http_client=http_client) as streams:
http_read, http_write = streams[0], streams[1]
async with stdio_server() as (stdio_read, stdio_write):
async with anyio.create_task_group() as tg:
tg.start_soon(_pump_upstream, http_read, stdio_write)
await _pump(stdio_read, http_write)
tg.cancel_scope.cancel()
finally:
# Always restore environment variables
os.environ.update(saved_env_vars)
User Configuration Examples
Example 1: Corporate Environment (Recommended)
Users set environment variables in ~/.claude/mcp.json:
{
"mcpServers": {
"databricks-mcp": {
"type": "stdio",
"command": "/path/to/ucode",
"args": ["mcp-proxy", "--url", "...", "--host", "...", "--profile", "..."],
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1"
}
}
}
}
OR in ~/.claude/settings.json (global):
{
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1",
"HTTP_PROXY": "http://proxy.company.com:8080",
"NO_PROXY": "localhost,internal.company.com,aws.databricksapps.com",
"SSL_CERT_FILE": "/path/to/corporate-ca.crt"
}
}
Example 2: Granular Control
{
"env": {
"UCODE_MCP_PROXY_BYPASS": "1",
"UCODE_MCP_USE_SYSTEM_TRUST_STORE": "1"
}
}
Example 3: No Configuration Needed
Users without proxy/SSL issues don't set anything - works as before.
Documentation for Users
Quick Start for Enterprise Users
Add to your Claude Code MCP configuration:
{
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1"
}
}
This enables:
- ✅ Proxy bypass for URLs matching
NO_PROXY patterns
- ✅ System trust store for public certificate verification
- ✅ Corporate CA certificates still work for internal services
Environment Variables Reference
| Variable |
Default |
Description |
UCODE_MCP_ENTERPRISE_MODE |
0 |
Enable both proxy bypass and system trust store (recommended for corporate) |
UCODE_MCP_PROXY_BYPASS |
0 |
Enable proxy bypass when URL matches NO_PROXY patterns |
UCODE_MCP_USE_SYSTEM_TRUST_STORE |
0 |
Use system trust store instead of SSL_CERT_FILE for MCP connections |
Alternative Design: Auto-Detection (Advanced)
For a more automatic solution, detect corporate environment indicators:
def _should_enable_enterprise_mode(url: str) -> bool:
"""Auto-detect if enterprise mode is needed."""
# Check if proxy is configured
has_proxy = bool(os.environ.get('HTTP_PROXY') or os.environ.get('HTTPS_PROXY'))
# Check if custom SSL cert is configured
has_custom_ssl = bool(os.environ.get('SSL_CERT_FILE'))
# Check if URL would match NO_PROXY
no_proxy = os.environ.get('NO_PROXY', '')
matches_no_proxy = any(
pattern.strip() and pattern.strip() in url
for pattern in no_proxy.split(',')
)
# Enable enterprise mode if all conditions met
return has_proxy and has_custom_ssl and matches_no_proxy
Pros:
- No configuration required from users
- Automatically handles corporate environments
Cons:
- Less explicit (harder to troubleshoot)
- May trigger in unintended scenarios
- Users have less control
Recommendation: Start with explicit opt-in (safer), consider auto-detection in future versions.
Testing Strategy
Test Matrix
| Environment |
HTTP_PROXY |
SSL_CERT_FILE |
NO_PROXY |
UCODE_MCP_ENTERPRISE_MODE |
Expected Result |
| Standard |
❌ |
❌ |
❌ |
❌ |
Works (no change) |
| Corporate (mode off) |
✅ |
✅ |
✅ |
❌ |
Timeout (existing behavior) |
| Corporate (mode on) |
✅ |
✅ |
✅ |
✅ |
Works ✅ |
| Home network |
✅ |
❌ |
❌ |
✅ |
Works (no effect) |
| VPN only |
❌ |
✅ |
❌ |
✅ |
Works (uses system trust) |
Unit Tests
# Test proxy bypass logic
def test_proxy_bypass_enabled():
os.environ['UCODE_MCP_ENTERPRISE_MODE'] = '1'
os.environ['NO_PROXY'] = 'aws.databricksapps.com'
os.environ['HTTP_PROXY'] = 'http://proxy:8080'
# Test that proxy is unset for matching URLs
assert proxy_should_be_bypassed('https://mcp.aws.databricksapps.com')
def test_proxy_bypass_disabled():
os.environ.pop('UCODE_MCP_ENTERPRISE_MODE', None)
os.environ['NO_PROXY'] = 'aws.databricksapps.com'
os.environ['HTTP_PROXY'] = 'http://proxy:8080'
# Test that proxy is NOT bypassed when mode is off
assert not proxy_should_be_bypassed('https://mcp.aws.databricksapps.com')
Integration Tests
@pytest.mark.asyncio
async def test_mcp_proxy_corporate_mode():
"""Test MCP proxy works in corporate environment with enterprise mode."""
os.environ['UCODE_MCP_ENTERPRISE_MODE'] = '1'
os.environ['HTTP_PROXY'] = 'http://test-proxy:8080'
os.environ['SSL_CERT_FILE'] = '/path/to/corporate-ca.crt'
os.environ['NO_PROXY'] = 'aws.databricksapps.com'
# Should connect successfully
result = await _run(
url='https://mcp.aws.databricksapps.com/mcp',
workspace='test-workspace',
profile='test-profile'
)
assert result is not None
# Verify environment restored
assert os.environ['HTTP_PROXY'] == 'http://test-proxy:8080'
assert os.environ['SSL_CERT_FILE'] == '/path/to/corporate-ca.crt'
Migration Path for Existing Users
For Users with Manual Patches
- Update ucode to version with this feature
- Remove manual patch (restore original
mcp_proxy.py)
- Add configuration to
~/.claude/mcp.json:
{
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1"
}
}
- Test connection
For New Users
Simply set UCODE_MCP_ENTERPRISE_MODE=1 in their MCP server configuration if in corporate environment.
Security Considerations
Security Properties Maintained
✅ SSL Verification ON by default - No changes without opt-in
✅ System trust store is secure - Contains validated public CAs
✅ Environment restored - No side effects on other processes
✅ No verify=False - Never disables SSL verification
✅ Explicit opt-in - Users choose to enable the feature
Security Concerns Addressed
Q: Does this reduce security?
A: No. Using the system trust store (which contains DigiCert, Let's Encrypt, etc.) is the standard secure approach for verifying public certificates.
Q: What about internal servers?
A: Internal servers should have separate configuration or use proper public CAs. The custom SSL_CERT_FILE is only unset temporarily for the MCP connection, then restored.
Q: Could this be abused?
A: Users already have full control over environment variables. This feature just makes corporate network configurations work correctly.
Documentation Updates Needed
1. README.md
Add section: Enterprise Network Configuration
### Using ucode MCP Proxy in Corporate Environments
If you're behind a corporate proxy with custom CA certificates, enable enterprise mode:
**In ~/.claude/mcp.json:**
```json
{
"mcpServers": {
"databricks-mcp": {
"env": {
"UCODE_MCP_ENTERPRISE_MODE": "1"
}
}
}
}
This enables proxy bypass for NO_PROXY matches and uses the system trust store for public certificates.
### 2. Troubleshooting Guide
Add section: **Connection Timeouts in Corporate Networks**
```markdown
**Problem:** Connection times out after 30 seconds
**Solution:** Enable enterprise mode if you have:
- Corporate HTTP proxy (HTTP_PROXY set)
- Custom CA certificates (SSL_CERT_FILE set)
- Internal Databricks URLs in NO_PROXY
Set `UCODE_MCP_ENTERPRISE_MODE=1` in your MCP configuration.
3. API Documentation
Document new environment variables in API reference.
Pull Request Checklist
Additional Enhancements (Optional)
1. Logging
Add debug logging to help troubleshoot:
import logging
logger = logging.getLogger(__name__)
if enterprise_mode:
logger.debug("Enterprise mode enabled")
if should_bypass:
logger.debug(f"Bypassing proxy for {url} (matches NO_PROXY)")
if use_system_trust:
logger.debug("Using system trust store for SSL verification")
Enable with: export UCODE_LOG_LEVEL=DEBUG
2. Configuration Validation
Validate configuration on startup:
def _validate_enterprise_config():
"""Warn if enterprise mode is enabled but NO_PROXY is not set."""
if os.environ.get('UCODE_MCP_ENTERPRISE_MODE') == '1':
if not os.environ.get('NO_PROXY'):
logger.warning(
"UCODE_MCP_ENTERPRISE_MODE is enabled but NO_PROXY is not set. "
"Proxy bypass may not work as expected."
)
3. Configuration File Support
Allow configuration via ~/.ucode/config.toml:
[mcp-proxy]
enterprise_mode = true
proxy_bypass = true
use_system_trust_store = true
Success Metrics
After implementation, success is measured by:
- Zero manual patches required - Configuration-only solution
- No regression - Existing users unaffected
- User adoption - Corporate users enable the feature
- Reduced support tickets - Fewer timeout issues reported
- Positive feedback - Users confirm it works in their environments
Timeline Estimate
| Phase |
Effort |
Duration |
| Implementation |
1-2 days |
Core logic + try/finally wrapper |
| Unit tests |
0.5 days |
Test all configuration permutations |
| Integration tests |
1 day |
Corporate environment simulation |
| Documentation |
0.5 days |
README, troubleshooting, examples |
| Code review |
1 day |
Security review, backward compat check |
| Total |
4-5 days |
Ready for release |
References
Contact
Author: Sergei Alekseev
Email: sergei.alekseev@novartis.com
Date: 2026-09-16
For questions or discussion about this proposal, please comment on the GitHub issue or reach out directly.
Bug Report: httpx2/httpcore2 Issues in ucode mcp-proxy
Date: 2026-09-15
Reporter: Sergei Alekseev
Component: ucode (Databricks Unity Gateway)
Affected File: src/ucode/mcp_proxy.py
httpx2 Version: 2.13.0
httpcore2 Version: (bundled with httpx2)
Summary
The ucode mcp-proxy command fails to connect to internal Databricks MCP servers due to two critical issues in httpx2/httpcore2:
- Proxy environment variables not respected:
AsyncClient(proxy=None) parameter is ignored; httpx2 still reads and uses HTTP_PROXY/HTTPS_PROXY environment variables
- Custom CA certificates not supported: No mechanism works for custom CA certificates (not
verify=path, not verify=SSLContext, not SSL_CERT_FILE environment variable)
Environment
- OS: macOS (Darwin 25.6.0)
- Python: 3.12.13
- httpx2: 2.13.0
- Target: Internal corporate MCP server
- URL:
https://mcp-server-12-*.aws.databricksapps.com/mcp
- Resolves to: 10.194.65.212, 10.194.64.173 (RFC 1918 private IPs)
- Network: Corporate environment with proxy
- Proxy:
http://nibr-proxy.global.nibr.novartis.net:2011
- NO_PROXY: Contains
aws.databricksapps.com
- Custom CA:
/Users/aleksse1/ca-certs.crt
Issue #1: Proxy Parameter Ignored
Expected Behavior
import httpx2
async with httpx2.AsyncClient(proxy=None) as client:
# Should NOT use HTTP_PROXY/HTTPS_PROXY environment variables
response = await client.get("https://internal-server.example.com")
Actual Behavior
httpx2 reads HTTP_PROXY/HTTPS_PROXY environment variables even when proxy=None is explicitly set, causing:
- Attempts to route internal IP addresses through corporate proxy
- 30-second connection timeout (proxy cannot route to internal IPs)
Reproduction
import os
import httpx2
import asyncio
os.environ['HTTP_PROXY'] = 'http://proxy.example.com:8080'
os.environ['HTTPS_PROXY'] = 'http://proxy.example.com:8080'
os.environ['NO_PROXY'] = 'internal.example.com'
async def test():
# This SHOULD bypass proxy but DOES NOT
async with httpx2.AsyncClient(proxy=None) as client:
response = await client.get("https://internal.example.com")
# Result: Tries to use proxy despite proxy=None
asyncio.run(test())
Workaround
Must explicitly unset environment variables before creating AsyncClient:
saved_proxy_vars = {}
for key in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']:
if key in os.environ:
saved_proxy_vars[key] = os.environ[key]
del os.environ[key]
try:
async with httpx2.AsyncClient(proxy=None) as client:
# Now works correctly
pass
finally:
os.environ.update(saved_proxy_vars)
Issue #2: SSL_CERT_FILE Environment Variable Overrides System Trust Store
Expected Behavior
When SSL_CERT_FILE is set to a custom CA bundle (for verifying internal corporate servers), httpx2 should still be able to verify public certificates by falling back to the system trust store.
OR the custom CA bundle should be additive to the system trust store, not replace it entirely.
Actual Behavior
When SSL_CERT_FILE points to a custom CA bundle, httpx2 completely ignores the system trust store, causing verification failures for any certificate not signed by CAs in the custom bundle.
Example: Databricks MCP servers use legitimate DigiCert certificates (public CA). With SSL_CERT_FILE pointing to a corporate CA bundle (for other internal servers), httpx2 fails to verify the Databricks certificate even though it's valid:
httpx2.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
self-signed certificate in certificate chain (_ssl.c:1010)
However, the exact same certificate verifies successfully when SSL_CERT_FILE is unset (using system trust store)
Root Cause
httpx2 reads SSL_CERT_FILE at client creation and uses only that CA bundle, completely bypassing the system trust store. This breaks verification for any public certificates not in the custom bundle.
Test Results
| Configuration |
Result |
SSL_CERT_FILE set (corporate CA only) |
❌ SSL error |
SSL_CERT_FILE unset (system trust store) |
✅ Works perfectly! |
verify=False |
✅ Works (but insecure) |
Reproduction
import httpx2
import asyncio
import os
# Corporate environment has SSL_CERT_FILE set to custom CA bundle
os.environ['SSL_CERT_FILE'] = '/path/to/corporate-ca-bundle.crt'
async def test():
# This FAILS even though the target uses a valid public certificate (DigiCert)
try:
async with httpx2.AsyncClient() as client:
await client.get("https://public-server-with-digicert-cert.example.com")
except httpx2.ConnectError as e:
print(f"Failed: {e}")
# Result: CERTIFICATE_VERIFY_FAILED (DigiCert CA not in corporate bundle)
asyncio.run(test())
Workaround
Temporarily unset SSL_CERT_FILE to use the system trust store:
import os
saved_ssl_vars = {}
for key in ['SSL_CERT_FILE', 'REQUESTS_CA_BUNDLE']:
if key in os.environ:
saved_ssl_vars[key] = os.environ[key]
del os.environ[key]
try:
async with httpx2.AsyncClient() as client:
# Now uses system trust store → verifies public certificates correctly
await client.get("https://public-server.example.com")
finally:
os.environ.update(saved_ssl_vars)
Better solution: Create a CA bundle that contains both corporate CAs and public CAs (but this may not be practical in enterprise environments)
Combined Fix Applied
async def _run(url: str, workspace: str, profile: str | None) -> None:
import os
httpx = _httpx()
auth = _build_token_auth(workspace, profile)
# WORKAROUND 1: Unset proxy environment variables (httpx2 ignores proxy=None)
saved_env_vars = {}
no_proxy_list = os.environ.get('NO_PROXY', '').split(',')
use_proxy = not any(pattern.strip() and pattern.strip() in url for pattern in no_proxy_list)
if not use_proxy:
for key in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
# WORKAROUND 2: Unset SSL_CERT_FILE to use system trust store for public certificates
for key in ['SSL_CERT_FILE', 'REQUESTS_CA_BUNDLE']:
if key in os.environ:
saved_env_vars[key] = os.environ[key]
del os.environ[key]
try:
async with httpx.AsyncClient(
auth=auth,
timeout=httpx.Timeout(30.0, read=300.0, write=30.0, pool=30.0),
) as http_client:
# ✓ Full SSL verification enabled (verify=True by default)
# ✓ Uses system trust store (verifies DigiCert, Let's Encrypt, etc.)
async with streamable_http_client(url, http_client=http_client) as streams:
# ... rest of proxy logic
pass
finally:
os.environ.update(saved_env_vars)
Impact
This affects any use of httpx2 in environments with:
- Corporate proxy configurations
- Custom CA bundles (SSL_CERT_FILE) that need to coexist with public certificate verification
- NO_PROXY bypass requirements
Security Note
The implemented fix maintains full SSL verification:
- ✅ Databricks certificates verified against system trust store (DigiCert CA)
- ✅ No
verify=False used
- ✅ HTTPS connections properly authenticated
- ✅ Secure by default
The fix works by temporarily unsetting SSL_CERT_FILE when connecting to public endpoints, allowing httpx2 to use the system trust store which contains all major public CAs.
Comparison with curl
For reference, curl works correctly with the same configuration:
curl -v \
--cacert /Users/aleksse1/ca-certs.crt \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize",...}' \
https://mcp-server-12-*.aws.databricksapps.com/mcp
# Result: HTTP 200, instant response
# NO_PROXY is respected automatically
# Custom CA cert works via --cacert flag
Requested Fixes
-
Honor proxy=None parameter: When explicitly set, do not read HTTP_PROXY/HTTPS_PROXY environment variables
-
Make SSL_CERT_FILE additive, not exclusive: When SSL_CERT_FILE is set, it should supplement the system trust store, not replace it. This allows verification of both:
- Corporate certificates (from custom CA bundle)
- Public certificates (from system trust store)
Alternative: Provide a way to explicitly merge custom CAs with system trust store.
-
Document the behavior: Clearly document that:
proxy=None does not prevent reading proxy environment variables
SSL_CERT_FILE completely replaces the system trust store
- Provide workarounds for mixed environments (corporate + public certificates)
Additional Context
- Original httpx (v0.x) may have worked differently
- This is specifically httpx2 (v2.x) with httpcore2 backend
- Issue discovered in Databricks Unity Gateway (
ucode) MCP proxy implementation
- Workarounds successfully tested and working in production
Related Files
Test Environment
python --version
# Python 3.12.13
pip list | grep httpx
# httpx2 2.13.0
pip list | grep httpcore
# httpcore2 (bundled with httpx2)
Contact: sergei.alekseev@novartis.com
Date: September 15, 2026
[Feature Request] Add Enterprise Network Support for MCP Proxy
Summary
Add opt-in configuration to support
ucode mcp-proxyin corporate environments with HTTP proxies and custom CA certificates, eliminating the need for manual patching.Problem
ucode mcp-proxyfails to connect to Databricks MCP servers in enterprise environments with:HTTP_PROXYenvironment variable)SSL_CERT_FILEpointing to corporate CA bundle)Error:
Root Cause
Two httpx2 library behaviors break in corporate networks:
httpx2 ignores
proxy=None: TheAsyncClient(proxy=None)parameter is ignored; httpx2 still readsHTTP_PROXY/HTTPS_PROXYenvironment variables, routing internal servers through the corporate proxy unnecessarilySSL_CERT_FILE replaces system trust store: When set, httpx2 uses only the custom CA bundle, ignoring the system trust store. This breaks verification of legitimate public certificates (e.g., Databricks' DigiCert certificates)
Current Workaround
Users must manually patch
src/ucode/mcp_proxy.py(~25 lines), which:Proposed Solution
Add opt-in environment variables for enterprise network support:
User Configuration
In
~/.claude/mcp.json:{ "mcpServers": { "databricks-mcp": { "type": "stdio", "command": "/path/to/ucode", "args": ["mcp-proxy", "--url", "...", "--host", "...", "--profile", "..."], "env": { "UCODE_MCP_ENTERPRISE_MODE": "1" } } } }That's it! No code changes, no manual patching.
Implementation Details
Changes to
src/ucode/mcp_proxy.pyLines changed: ~30 lines added, 0 removed, 1 modified (add try/finally)
Benefits
✅ No breaking changes - Opt-in, backward compatible
✅ Configuration only - No manual patching required
✅ Secure - Maintains full SSL verification
✅ Granular control - Enable features individually or together
✅ Enterprise ready - Works with various corporate network setups
✅ Easy to maintain - Simple, clean implementation
Testing
Verified in production environment:
Alternatives Considered
Impact
Documentation
Will need updates to:
References
ucode_upstream_proposal.md)ucode_PR_implementation.py)httpx2-mcp-proxy-bug-report.md)Questions?
Happy to discuss implementation details, provide more test cases, or clarify any aspect of this proposal.
Reporter: Sergei Alekseev (sergei.alekseev@novartis.com)
Date: 2026-09-16
Tested Environment: macOS, Python 3.12.13, httpx2 2.13.0, Corporate network with proxy + custom CA
Upstream Feature Proposal: Configurable Proxy and SSL Handling for ucode mcp-proxy
Target Repository: https://github.com/databricks/unity-gateway
Component:
src/ucode/mcp_proxy.pyIssue: MCP proxy fails in corporate environments with proxy servers and custom CA certificates
Proposed By: Sergei Alekseev (sergei.alekseev@novartis.com)
Date: 2026-09-16
Problem Statement
ucode mcp-proxyfails to connect to Databricks MCP servers in corporate environments due to:proxy=None: The library readsHTTP_PROXY/HTTPS_PROXYenvironment variables even when proxy bypass is neededCurrent Impact:
Proposed Solution: Environment-Based Configuration
Add opt-in environment variables that allow users to configure proxy and SSL behavior without code changes.
Design Principles
Implementation Design
New Environment Variables
Implementation in
mcp_proxy.pyUser Configuration Examples
Example 1: Corporate Environment (Recommended)
Users set environment variables in
~/.claude/mcp.json:{ "mcpServers": { "databricks-mcp": { "type": "stdio", "command": "/path/to/ucode", "args": ["mcp-proxy", "--url", "...", "--host", "...", "--profile", "..."], "env": { "UCODE_MCP_ENTERPRISE_MODE": "1" } } } }OR in
~/.claude/settings.json(global):{ "env": { "UCODE_MCP_ENTERPRISE_MODE": "1", "HTTP_PROXY": "http://proxy.company.com:8080", "NO_PROXY": "localhost,internal.company.com,aws.databricksapps.com", "SSL_CERT_FILE": "/path/to/corporate-ca.crt" } }Example 2: Granular Control
{ "env": { "UCODE_MCP_PROXY_BYPASS": "1", "UCODE_MCP_USE_SYSTEM_TRUST_STORE": "1" } }Example 3: No Configuration Needed
Users without proxy/SSL issues don't set anything - works as before.
Documentation for Users
Quick Start for Enterprise Users
Add to your Claude Code MCP configuration:
{ "env": { "UCODE_MCP_ENTERPRISE_MODE": "1" } }This enables:
NO_PROXYpatternsEnvironment Variables Reference
UCODE_MCP_ENTERPRISE_MODE0UCODE_MCP_PROXY_BYPASS0UCODE_MCP_USE_SYSTEM_TRUST_STORE0Alternative Design: Auto-Detection (Advanced)
For a more automatic solution, detect corporate environment indicators:
Pros:
Cons:
Recommendation: Start with explicit opt-in (safer), consider auto-detection in future versions.
Testing Strategy
Test Matrix
Unit Tests
Integration Tests
Migration Path for Existing Users
For Users with Manual Patches
mcp_proxy.py)~/.claude/mcp.json:{ "env": { "UCODE_MCP_ENTERPRISE_MODE": "1" } }For New Users
Simply set
UCODE_MCP_ENTERPRISE_MODE=1in their MCP server configuration if in corporate environment.Security Considerations
Security Properties Maintained
✅ SSL Verification ON by default - No changes without opt-in
✅ System trust store is secure - Contains validated public CAs
✅ Environment restored - No side effects on other processes
✅ No verify=False - Never disables SSL verification
✅ Explicit opt-in - Users choose to enable the feature
Security Concerns Addressed
Q: Does this reduce security?
A: No. Using the system trust store (which contains DigiCert, Let's Encrypt, etc.) is the standard secure approach for verifying public certificates.
Q: What about internal servers?
A: Internal servers should have separate configuration or use proper public CAs. The custom SSL_CERT_FILE is only unset temporarily for the MCP connection, then restored.
Q: Could this be abused?
A: Users already have full control over environment variables. This feature just makes corporate network configurations work correctly.
Documentation Updates Needed
1. README.md
Add section: Enterprise Network Configuration
This enables proxy bypass for NO_PROXY matches and uses the system trust store for public certificates.
3. API Documentation
Document new environment variables in API reference.
Pull Request Checklist
src/ucode/mcp_proxy.pyAdditional Enhancements (Optional)
1. Logging
Add debug logging to help troubleshoot:
Enable with:
export UCODE_LOG_LEVEL=DEBUG2. Configuration Validation
Validate configuration on startup:
3. Configuration File Support
Allow configuration via
~/.ucode/config.toml:Success Metrics
After implementation, success is measured by:
Timeline Estimate
References
Contact
Author: Sergei Alekseev
Email: sergei.alekseev@novartis.com
Date: 2026-09-16
For questions or discussion about this proposal, please comment on the GitHub issue or reach out directly.
Bug Report: httpx2/httpcore2 Issues in ucode mcp-proxy
Date: 2026-09-15
Reporter: Sergei Alekseev
Component:
ucode(Databricks Unity Gateway)Affected File:
src/ucode/mcp_proxy.pyhttpx2 Version: 2.13.0
httpcore2 Version: (bundled with httpx2)
Summary
The
ucode mcp-proxycommand fails to connect to internal Databricks MCP servers due to two critical issues in httpx2/httpcore2:AsyncClient(proxy=None)parameter is ignored; httpx2 still reads and usesHTTP_PROXY/HTTPS_PROXYenvironment variablesverify=path, notverify=SSLContext, notSSL_CERT_FILEenvironment variable)Environment
https://mcp-server-12-*.aws.databricksapps.com/mcphttp://nibr-proxy.global.nibr.novartis.net:2011aws.databricksapps.com/Users/aleksse1/ca-certs.crtIssue #1: Proxy Parameter Ignored
Expected Behavior
Actual Behavior
httpx2 reads
HTTP_PROXY/HTTPS_PROXYenvironment variables even whenproxy=Noneis explicitly set, causing:Reproduction
Workaround
Must explicitly unset environment variables before creating AsyncClient:
Issue #2: SSL_CERT_FILE Environment Variable Overrides System Trust Store
Expected Behavior
When
SSL_CERT_FILEis set to a custom CA bundle (for verifying internal corporate servers), httpx2 should still be able to verify public certificates by falling back to the system trust store.OR the custom CA bundle should be additive to the system trust store, not replace it entirely.
Actual Behavior
When
SSL_CERT_FILEpoints to a custom CA bundle, httpx2 completely ignores the system trust store, causing verification failures for any certificate not signed by CAs in the custom bundle.Example: Databricks MCP servers use legitimate DigiCert certificates (public CA). With
SSL_CERT_FILEpointing to a corporate CA bundle (for other internal servers), httpx2 fails to verify the Databricks certificate even though it's valid:However, the exact same certificate verifies successfully when
SSL_CERT_FILEis unset (using system trust store)Root Cause
httpx2 reads
SSL_CERT_FILEat client creation and uses only that CA bundle, completely bypassing the system trust store. This breaks verification for any public certificates not in the custom bundle.Test Results
SSL_CERT_FILEset (corporate CA only)SSL_CERT_FILEunset (system trust store)verify=FalseReproduction
Workaround
Temporarily unset
SSL_CERT_FILEto use the system trust store:Better solution: Create a CA bundle that contains both corporate CAs and public CAs (but this may not be practical in enterprise environments)
Combined Fix Applied
Impact
This affects any use of httpx2 in environments with:
Security Note
The implemented fix maintains full SSL verification:
verify=FalseusedThe fix works by temporarily unsetting
SSL_CERT_FILEwhen connecting to public endpoints, allowing httpx2 to use the system trust store which contains all major public CAs.Comparison with curl
For reference,
curlworks correctly with the same configuration:Requested Fixes
Honor
proxy=Noneparameter: When explicitly set, do not read HTTP_PROXY/HTTPS_PROXY environment variablesMake SSL_CERT_FILE additive, not exclusive: When
SSL_CERT_FILEis set, it should supplement the system trust store, not replace it. This allows verification of both:Alternative: Provide a way to explicitly merge custom CAs with system trust store.
Document the behavior: Clearly document that:
proxy=Nonedoes not prevent reading proxy environment variablesSSL_CERT_FILEcompletely replaces the system trust storeAdditional Context
ucode) MCP proxy implementationRelated Files
src/ucode/mcp_proxy.py(Databricks Unity Gateway)Test Environment
Contact: sergei.alekseev@novartis.com
Date: September 15, 2026