Repository navigation
fix(mcp): resolve Flask app context error in MCP tools - #37309
Conversation
Flask-AppBuilder deprecated `appbuilder.app` - it now returns a LocalProxy to `current_app` instead of the actual Flask app instance. The previous code checked `appbuilder.app is not None` which always returned True (comparing LocalProxy object identity, not the resolved value), causing it to store the LocalProxy instead of the actual app. When MCP tools later called `app.app_context()` outside of a Flask context, the LocalProxy couldn't resolve, causing: "RuntimeError: Working outside of application context" This fix: - Checks `appbuilder._session is not None` to properly detect if appbuilder was initialized via init_app() - Uses `current_app._get_current_object()` to get the actual Flask app when in an app context - Creates a minimal Flask app when not in an app context (standalone MCP server mode) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Code Review Agent Run #5ceba3Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
CodeAnt AI finished reviewing your PR. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #37309 +/- ##
===========================================
+ Coverage 0 67.59% +67.59%
===========================================
Files 0 644 +644
Lines 0 48319 +48319
Branches 0 5300 +5300
===========================================
+ Hits 0 32663 +32663
- Misses 0 14365 +14365
- Partials 0 1291 +1291
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
villebro
left a comment
There was a problem hiding this comment.
It seems we've been playing whack-a-mole on this, let's hope this finally resolves the remaining issues 😃
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
SUMMARY
Flask-AppBuilder deprecated
appbuilder.app- it now returns aLocalProxytocurrent_appinstead of the actual Flask app instance.Root Cause:
The previous code in
superset/mcp_service/flask_singleton.pycheckedappbuilder.app is not Nonewhich always returned True because it compared aLocalProxyobject (notNone) rather than the resolved value. This caused the code to store theLocalProxyinstead 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:Fix:
appbuilder._session is not Noneto properly detect if appbuilder was initialized viainit_app()current_app._get_current_object()to get the actual Flask app instance when in an app contextBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
After:
TESTING INSTRUCTIONS
Start the MCP server in HTTP mode:
Call the
health_checktool (or any MCP tool) - it should now work without the "Working outside of application context" errorAlternatively, test programmatically:
ADDITIONAL INFORMATION