-
Notifications
You must be signed in to change notification settings - Fork 16.1k
fix(mcp-service): ensure Flask app context in auth hook and resolve Pydantic warnings #36013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Code Review Agent Run #838990Actionable Suggestions - 0Additional Suggestions - 3
Review 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Incomplete alias configuration for schema field ▹ view | ||
| Unnecessary eager loading of user relationships ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/mcp_service/common/error_schemas.py | ✅ |
| superset/mcp_service/auth.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #36013 +/- ##
===========================================
+ Coverage 0 68.35% +68.35%
===========================================
Files 0 631 +631
Lines 0 45991 +45991
Branches 0 4983 +4983
===========================================
+ Hits 0 31439 +31439
- Misses 0 13306 +13306
- Partials 0 1246 +1246
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:
|
|
I've had claude address the reviewer feedback with the latest commit: Changes Made1. Replaced
|
Antonio-RiveroMartnez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This commit extends PR apache#36013 to fully resolve the 'Working outside of application context' error for async MCP tools. Changes: - Add async/sync detection using inspect.iscoroutinefunction() - Create separate async_wrapper and sync_wrapper functions - Add test_request_context() nested inside app_context() for g object access - Support await for async tools, regular call for sync tools The original PR added app_context() which partially fixed the issue, but async tools like list_charts still failed because: 1. The decorator didn't await async functions 2. Only app_context() was used, but g object requires test_request_context() Both contexts are needed: - app_context() provides current_app, config, db - test_request_context() provides g, request Tested with get_instance_info and list_charts - both work without context errors.
This commit extends PR apache#36013 to fully resolve the 'Working outside of application context' error for async MCP tools. Changes: - Add async/sync detection using inspect.iscoroutinefunction() - Create separate async_wrapper and sync_wrapper functions - Add test_request_context() nested inside app_context() for g object access - Support await for async tools, regular call for sync tools The original PR added app_context() which partially fixed the issue, but async tools like list_charts still failed because: 1. The decorator didn't await async functions 2. Only app_context() was used, but g object requires test_request_context() Both contexts are needed: - app_context() provides current_app, config, db - test_request_context() provides g, request Tested with get_instance_info and list_charts - both work without context errors.
327a12a to
52d6db4
Compare
…_check - Remove Flask app context creation from mcp_auth_hook decorator - Decorator now assumes Flask context is set by middleware (production) - Add Context parameter to health_check tool for FastMCP compatibility - Extract helper functions to reduce auth hook complexity - Fix import formatting in health_check.py
d215346 to
de35377
Compare
SUMMARY
This PR fixes two critical bugs and enhances documentation in the MCP service:
health_checktool failing in deployment with "Working outside of application context" errorschemafield shadowing BaseModel attributeContext:
The
health_checktool was the only MCP tool that doesn't access Flask functionality directly. In stateless HTTP mode, the@mcp_auth_hookdecorator attempted to accesscurrent_app.configwithout ensuring Flask app context was active, causing failures in deployment environments while working fine locally.CHANGES
1. Flask App Context Fix (
superset/mcp_service/auth.py)Problem:
health_checktool failed in deployment with "Working outside of application context"mcp_auth_hookcalledcurrent_app.configwithout active Flask contextSolution:
Impact:
stateless_http=Truemode in production2. Pydantic Warning Fix (
superset/mcp_service/common/error_schemas.py)Problem:
Solution:
Impact:
schemaandschema_name)3. Enhanced Auth Documentation (
superset/mcp_service/auth.py)Changes:
Impact:
TESTING
✅ All 178 MCP service unit tests pass
✅ Pre-commit checks pass (mypy, ruff, pylint)
✅ No Pydantic warnings when importing MCP service
✅ Backward compatibility verified for
DatasetContextusageBEFORE/AFTER
Before:
health_checktool fails in deployment with Flask context errorAfter:
ADDITIONAL INFORMATION