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

   ## Summary
   
   Fixes the "Working outside of application context" error that occurs when 
calling any MCP tool on the standalone MCP server.
   
   **Root Cause**: The `mcp_auth_hook` decorator assumed Flask application 
context was already pushed by external middleware (as stated in the docstring: 
"assumes Flask application context... have already been set by 
WorkspaceContextMiddleware"). However, no such middleware exists for the 
standalone MCP server launched via `superset mcp run`.
   
   **Solution**: Wrap all tool executions with `app.app_context()` using the 
Flask app singleton from `flask_singleton.py`. This ensures Flask's 
`current_app` and `g` objects are available during tool execution.
   
   ### Changes
   - Import `get_flask_app` from `flask_singleton` in `mcp_auth_hook`
   - Wrap both async and sync wrapper functions with `with app.app_context():`
   - Updated docstring to reflect actual behavior
   
   ## Before/After
   
   **Before**: All MCP tool calls fail with:
   ```
   RuntimeError: Working outside of application context.
   
   This typically means that you attempted to use functionality that needed
   the current application. To solve this, set up an application context
   with app.app_context().
   ```
   
   **After**: All MCP tools work correctly:
   - ✅ health_check
   - ✅ list_datasets
   - ✅ list_charts
   - ✅ list_dashboards
   - ✅ get_dataset_info
   - ✅ get_chart_info
   - ✅ get_instance_info
   - ✅ get_schema
   - ✅ execute_sql
   - ✅ generate_explore_link
   
   ## Testing Instructions
   
   1. Start the MCP server: `superset mcp run --port 5008`
   2. Connect an MCP client (e.g., Claude Desktop)
   3. Call any tool (e.g., `health_check`)
   4. Verify the tool returns a valid response instead of the app context error
   
   ## Additional Information
   
   This bug was introduced because the original implementation assumed 
middleware would push app context, but standalone MCP server mode doesn't have 
such middleware. The pattern used here (wrapping with `app.app_context()`) is 
consistent with how `caching.py` handles the same issue (lines 137-142).
   
   🤖 Generated with [Claude Code](https://claude.ai/code)


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