MCP service: Flask app context error when running via 'superset mcp run'
- Dominant language
- Python
- Stars
- 74.8k
- Forks
- 18.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 692
Description
## Bug Description
Running `superset mcp run --host 0.0.0.0 --port 5008` starts the MCP server successfully and JWT authentication works, but tool execution immediately fails with a Flask application context error, terminating the session.
## Environment
- Superset version: 6.1.0rc1 (Docker image `apache/superset:6.1.0rc1`)
- FastMCP version: 2.14.3 (bundled)
- Deployment: ECS Fargate
- Auth: JWT via Okta (RS256, JWKS validation)
- Python: 3.10.19
## Steps to Reproduce
1. Configure MCP with JWT auth in `superset_config.py`:
```python
MCP_AUTH_ENABLED = True
MCP_JWT_ISSUER = "https://example.okta.com/oauth2/default"
MCP_JWT_AUDIENCE = "api://default"
MCP_JWT_ALGORITHM = "RS256"
MCP_JWKS_URI = "https://example.okta.com/oauth2/default/v1/keys"
```
2. Start MCP service:
```bash
superset mcp run --host 0.0.0.0 --port 5008
```
3. Connect with an MCP client (Claude Code) using a valid JWT token
4. Client sends `POST /mcp` with MCP initialize request
## Observed Behavior
The MCP server:
1. Accepts the POST request (200 OK)
2. Validates the JWT successfully
3. Crashes during request processing with:
```
WARNING - Failed to validate request: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
INFO - Terminating session: None
```
The session is immediately terminated and the client sees a connection failure.
## Expected Behavior
The MCP server should maintain the Flask application context when processing tool calls, allowing tools like `list_dashboards`, `execute_sql`, etc. to access the Superset database via Flask-SQLAlchemy.
## Server Logs
```
INFO: POST /mcp HTTP/1.1 200 OK
WARNING - Failed to validate request: No application found. Either work inside a view function or push an application context.
INFO - mcp.server.streamable_http - Terminating session: None
```
## Notes
- The MCP tools register successfully on startup (all 20+ tools including `generate_chart`, `list_dashboards`, `execute_sql`, etc.)
- The `/mcp` endpoint correctly returns 401 without a token and 200 with a valid token
- The issue appears to be that `superset mcp run` creates a FastMCP/Uvicorn server that doesn't wrap requests in a Flask app context
- The `--use-factory-config` flag exists but unclear if it addresses this issue
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Contributor guide
Research direction
Start by reproducing the failure with `superset mcp run` and a valid JWT, then trace request handling at the `/mcp` endpoint and the Flask application context boundary. Done means MCP tool calls such as `list_dashboards` and `execute_sql` complete without the application-context error while unauthenticated requests remain rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100