Date: June 19, 2025
Platform: MacOS
Project: TikAPI_MCP
Environment: /Users/tengjizhang/projects/flashbots_x/TikAPI_MCP
The TikAPI MCP server was experiencing failures when making requests to the TikAPI service, with empty error messages: "An error occurred while requesting TikAPI: ". This prevented the /resources/read and search functionality from working properly.
- Confirmed server was running on port 8000
- Verified basic endpoints (
/resources/list,/tools/list) were functional - Checked
.envconfiguration and TikAPI keys were present - Confirmed Redis was running properly
-
curl: β Works perfectly
curl -H "X-API-KEY: ..." "https://api.tikapi.io/public/video?id=7003402629929913605"
-
urllib: β Works perfectly
-
aiohttp: β Works perfectly
-
httpx.Client (sync): β Works perfectly
-
httpx.AsyncClient (async): β FAILS with ConnectError
The issue is specifically with httpx's AsyncClient - not TikAPI, not the network, not SSL/TLS, but the async implementation.
# β
This works
with httpx.Client() as client:
response = client.get("https://api.tikapi.io/...")
# β This fails
async with httpx.AsyncClient() as client:
response = await client.get("https://api.tikapi.io/...") # ConnectError- Error Location:
httpcore/_backends/anyio.pyduring TLS handshake - Error Type:
ConnectErrorwith empty message - Consistency: 100% reproducible with AsyncClient, 0% failure with sync Client
- Different httpx configurations (HTTP/1.1 only, no verification, custom timeouts)
- Multiple anyio versions (3.7.1, 4.9.0)
- Different SSL contexts and verification settings
- Various connection pool settings
- Alternative event loop (uvloop)
Updated all dependencies to latest versions:
- httpx: 0.27.2 β 0.28.1
- httpcore: 1.0.9 (latest)
- anyio: 3.7.1 β 4.9.0
- aiohttp: 3.12.13 (latest)
- fastapi: 0.115.13 (latest)
- pydantic: 2.11.7 (latest)
- uvicorn: 0.34.3 (latest)
Result: Issue persists even with latest versions.
This appears to be a rare edge case involving:
- TikAPI's specific server configuration
- httpx AsyncClient's anyio backend
- macOS environment SSL/TLS handling
| Method | Status | Notes |
|---|---|---|
| curl | β Works | Standard HTTP client |
| urllib | β Works | Python built-in |
| aiohttp | β Works | Alternative async HTTP client |
| httpx.Client (sync) | β Works | Same library, sync version |
| httpx.AsyncClient | β Fails | TLS handshake failure in anyio |
- Severity: High (blocks core functionality)
- Scope: Specific to httpx AsyncClient + TikAPI combination
- Reproducibility: 100% consistent
During investigation, several working alternatives were discovered:
- httpx.Client (synchronous) - Same library, but sync version works perfectly
- aiohttp - Alternative async HTTP client, fully functional
- urllib - Python built-in library, works when wrapped in asyncio.to_thread
- Using sync httpx.Client with asyncio.to_thread for async compatibility
- Replacing httpx.AsyncClient with aiohttp
- Using urllib in threaded async context
All approaches maintain the async interface while avoiding the httpx AsyncClient issue.
debug_httpx_backends.py- httpx configuration testingdebug_async_vs_sync.py- Async vs sync comparisontest_aiohttp.py- Alternative HTTP client verificationtikapi_urllib_test.py- urllib verification- Various other debugging scripts
Investigation Duration: ~2 hours
Confidence Level: High (extensively tested and reproduced)
Risk Level: Low (workaround is reliable and well-tested)