aminghadersohi opened a new pull request, #38523: URL: https://github.com/apache/superset/pull/38523
### SUMMARY Wires up `GlobalErrorHandlerMiddleware` and `LoggingMiddleware` into the MCP server middleware stack. Both middleware classes were fully implemented in `middleware.py` with unit tests but were never registered in `server.py`. The middleware list previously only included `ResponseSizeGuardMiddleware` and `CachingMiddleware`. ### Problem The MCP server had no global error handling or request logging. If a tool raised an unhandled exception, it could propagate uncaught, potentially crashing the server or returning raw tracebacks to LLM clients. There was also no observability into tool call durations, user context, or entity IDs being accessed — making debugging and monitoring difficult. ### What Changed **File: `superset/mcp_service/server.py`** 1. Updated the import to include `GlobalErrorHandlerMiddleware` and `LoggingMiddleware` 2. Added both middleware to the middleware list in the default initialization path **Middleware ordering** (first = outermost, runs first on request): 1. `GlobalErrorHandlerMiddleware` — outermost, catches all exceptions from inner middleware/tools 2. `LoggingMiddleware` — logs every tool call with duration, user context, entity IDs 3. `ResponseSizeGuardMiddleware` — guards against oversized responses 4. `CachingMiddleware` — caches tool responses **Why this order:** - Error handler must be outermost so it catches exceptions from all inner layers (including logging failures) - Logging should capture the full duration including size guard overhead but not be affected by caching (we want to log cache hits too, which means logging should be outside caching) ### TESTING INSTRUCTIONS - Existing middleware unit tests pass (`test_middleware.py`, `test_middleware_logging.py`) - MCP server starts without import errors - Tool calls produce structured log output with duration and user context - Unhandled exceptions in tools are caught and returned as structured error responses ### ADDITIONAL INFORMATION No new dependencies. No configuration changes. The middleware classes already existed with full test coverage — this PR simply registers them in the server startup path. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
