Archon
Archon copied to clipboard
MCP API logging syntax error: TypeError on /api/mcp/logs/stream endpoint
Bug Description
The MCP API crashes when accessing the logs streaming endpoint (/api/mcp/logs/stream) due to incorrect logging syntax mixing standard Python logging with Logfire keyword arguments.
Error Details
TypeError: Logger._log() got an unexpected keyword argument 'error'
File "/app/src/server/api_routes/mcp_api.py", line 619, in get_logs
api_logger.error("MCP server logs API failed", error=str(e))
Steps to Reproduce
- Navigate to the MCP page in the frontend
- The page attempts to connect to WebSocket endpoint
/api/mcp/logs/stream - When the endpoint encounters any error, the logging statement fails
Root Cause
The mcp_api.py file has inconsistent logging patterns:
- Line 619:
api_logger.error("MCP server logs API failed", error=str(e))❌ (Logfire keyword syntax) - Line 561:
api_logger.error("MCP server start API failed - error=%s", str(e))✅ (Standard format) - Line 580:
api_logger.error(f"MCP server stop API failed - error={str(e)}")✅ (F-string format)
The api_logger is created by get_logger() which returns a standard Python logging.Logger that doesn't support keyword arguments like error=.
Affected Code
File: python/src/server/api_routes/mcp_api.py
Lines: 619, 637, 701, 826, 837 (all use error= keyword syntax)
Suggested Fix
Replace Logfire-style keyword logging with standard Python logging patterns:
# Current (broken):
api_logger.error("MCP server logs API failed", error=str(e))
# Fix option 1 (f-string):
api_logger.error(f"MCP server logs API failed - error={str(e)}")
# Fix option 2 (format string):
api_logger.error("MCP server logs API failed - error=%s", str(e))
Environment
- This affects all environments where Logfire is not fully configured
- Error surfaces when MCP page is accessed and log streaming fails
Impact
- MCP page completely unusable due to WebSocket connection failure
- All MCP logging functionality broken
- Crashes the entire request handling
Technical Notes
This is a pre-existing issue (introduced in commit 59084036 on 2025-08-13) but surfaces more frequently now due to increased MCP page usage.