aminghadersohi opened a new pull request, #37309:
URL: https://github.com/apache/superset/pull/37309
### SUMMARY
Flask-AppBuilder deprecated `appbuilder.app` - it now returns a `LocalProxy`
to `current_app` instead of the actual Flask app instance.
**Root Cause:**
The previous code in `superset/mcp_service/flask_singleton.py` checked
`appbuilder.app is not None` which **always returned True** because it compared
a `LocalProxy` object (not `None`) rather than the resolved value. This caused
the code to store the `LocalProxy` instead of the actual Flask app.
When MCP tools later called `app.app_context()` outside of a Flask context
(e.g., in HTTP server mode with uvicorn), the LocalProxy couldn't resolve,
causing:
```
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().
```
**Fix:**
- Check `appbuilder._session is not None` to properly detect if appbuilder
was initialized via `init_app()`
- Use `current_app._get_current_object()` to get the actual Flask app
instance when in an app context
- Create a minimal Flask app when not in an app context (standalone MCP
server mode)
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
**Before:**
```
[01/21/26 11:46:33] Error calling tool 'health_check'
RuntimeError: Working outside of application context.
```
**After:**
```
Calling health_check tool...
SUCCESS! Result: <fastmcp.tools.tool.ToolResult object at 0x12e3194c0>
INFO:superset.mcp_service.system.tool.health_check:Health check completed
successfully
```
### TESTING INSTRUCTIONS
1. Start the MCP server in HTTP mode:
```bash
superset mcp run
```
2. Call the `health_check` tool (or any MCP tool) - it should now work
without the "Working outside of application context" error
3. Alternatively, test programmatically:
```python
import asyncio
from superset.mcp_service.app import mcp
tools = mcp._tool_manager._tools
health_check_tool = tools.get('health_check')
result = asyncio.run(health_check_tool.run(arguments={}))
print(result) # Should succeed
```
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] 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]