aminghadersohi opened a new pull request, #38560:
URL: https://github.com/apache/superset/pull/38560

   ### SUMMARY
   
   After registering `LoggingMiddleware` in the MCP server startup, the MCP 
server started failing the `initialize` handshake with clients (e.g. Claude 
Code) with:
   
   ```
   WARNING:root:Failed to validate request: Working outside of application 
context.
   ```
   
   **Root cause**: `LoggingMiddleware.on_message()` fires on ALL MCP messages 
including the protocol-level `initialize` handshake. It calls 
`event_logger.log()` which requires Flask app context, but during `initialize` 
there is no Flask app context pushed (`mcp_auth_hook` only pushes context for 
tool calls, not protocol messages).
   
   **Fix**: Wrap the `event_logger.log()` call in `on_message()` with 
`try/except RuntimeError` to gracefully skip logging when no Flask app context 
is available.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A - backend fix
   
   ### TESTING INSTRUCTIONS
   
   1. Start the MCP server locally: `python -m superset.mcp_service.server`
   2. Connect with an MCP client (e.g. Claude Code `/mcp`)
   3. Verify the `initialize` handshake completes successfully (no `Working 
outside of application context` error)
   4. Verify tool calls still log properly via `event_logger`
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
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]

Reply via email to