You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "jmaitrehenry (via GitHub)" <gi...@apache.org> on 2026/05/25 19:53:55 UTC
[I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
jmaitrehenry opened a new issue, #40423:
URL: https://github.com/apache/superset/issues/40423
### Bug description
Error:
DetachedInstanceError: Parent instance <PermissionView at 0x...>
is not bound to a Session; lazy load of 'permission' cannot proceed
Also: DBEventLogger.log() missing 3 required positional arguments
Context:
- tool=list_dashboards
- user_id=None (possible auth/session issue)
- mcp_service/middleware logs the error but secondary logger also fails
### Screenshots/recordings
❯ export SUPERSET_MCP_TOKEN='xxxx'
❯ SESSION_ID=$(
curl -sS -D - \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2025-06-18' \
-H "Authorization: Bearer $SUPERSET_MCP_TOKEN" \
-X POST 'https://xxxx/mcp' \
--data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"tools":{}},"clientInfo":{"name":"curl","version":"1.0.0"}}}' \
| awk '/^Mcp-Session-Id:/ {print $2}' | tr -d '\r'
)
❯ curl -sS \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2025-06-18' \
-H "Authorization: Bearer $SUPERSET_MCP_TOKEN" \
-H "Mcp-Session-Id: $SESSION_ID" \
-X POST 'https://xxxx/mcp' \
--data '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"list_dashboards","arguments":{"request":{"page":1}}}}'
event: message
data: {"method":"notifications/message","params":{"level":"info","data":{"msg":"Listing dashboards: page=1, page_size=10, search=None","extra":null}},"jsonrpc":"2.0"}
event: message
data: {"method":"notifications/message","params":{"level":"debug","data":{"msg":"Dashboard listing filters: filters=0, order_column=None, order_direction=asc","extra":null}},"jsonrpc":"2.0"}
event: message
data: {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"Error: Internal error in list_dashboards: An unexpected error occurred. Error ID: err_1779738544. Please contact support if this persists."}],"isError":false}}
### Superset version
master / latest-dev
### Python version
3.9
### Node version
Not applicable
### Browser
Not applicable
### Additional context
Docker image:
```
FROM apache/superset:6.1.0
USER root
RUN apt update && apt install -y gcc libpq-dev python3-dev pkg-config default-libmysqlclient-dev && apt clean && rm -rf /var/lib/apt/lists/*
RUN uv pip install psycopg2-binary mysqlclient clickhouse-connect fastmcp
```
mcp_config:
import os
MCP_SERVICE_HOST = "0.0.0.0"
MCP_SERVICE_PORT = 5008
MCP_SERVICE_URL = "https://xxxxx"
MCP_AUTH_ENABLED = True
MCP_JWT_ALGORITHM = "HS256"
MCP_JWT_SECRET = os.environ.get("MCP_JWT_SECRET")
MCP_JWT_ISSUER = "xxx"
MCP_JWT_AUDIENCE = "superset-mcp"
MCP_DEV_USERNAME = os.environ.get("MCP_DEV_USERNAME")
MCP_STORE_CONFIG = {
"enabled": True,
"CACHE_REDIS_URL": "redis://superset-redis-headless:6379/1",
"event_store_max_events": 100,
"event_store_ttl": 3600,
}
Logs:
```
[superset-mcp-7d5d9894c4-dlljf] 2026-05-25T19:32:10.650358183Z 2026-05-25 19:32:10,650:ERROR:superset.mcp_service.middleware:Unexpected error [err_1779737530] in list_dashboards: Parent instance <PermissionView at 0x7fbe85ffa350> is not bound to a Session; lazy load operation of attribute 'permission' cannot proceed (Background on this error at: https://sqlalche.me/e/14/bhk3)
[superset-mcp-7d5d9894c4-dlljf] 2026-05-25T19:32:10.665464304Z 2026-05-25 19:32:10,665:INFO:superset.mcp_service.middleware:MCP tool call: tool=list_dashboards, agent_id=None, user_id=None, method=tools/call, dashboard_id=None, slice_id=None, dataset_id=None, duration_ms=70, success=False
```
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
--
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: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4536933170
<!-- Greeting -->
Hi @jmaitrehenry! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team.
<!-- Answer -->
This is a known issue with Superset 6.1.0's MCP service. The root cause is that **per-request JWT authentication is not supported in v6.1.0** — the MCP routes are served by a FastMCP/ASGI sub-app that bypasses Flask's `@before_request` JWT middleware, so `g.user` is never set and `user_id` remains `None` [[1]](https://github.com/apache/superset/issues/40225).
Without a valid user session, the RBAC permission check attempts to access `PermissionView` relationships (lazy-loaded by default), but since there's no properly bound SQLAlchemy session in this context, you get the `DetachedInstanceError`.
**Fix/Workaround**: Set `MCP_DEV_USERNAME` in your config to delegate all MCP operations to a specific Superset user account:
```python
MCP_DEV_USERNAME = "your-service-account-username"
```
This was confirmed by a maintainer as the only supported authentication path in 6.1.0 [[1]](https://github.com/apache/superset/issues/40225). Your JWT configuration (`MCP_AUTH_ENABLED`, `MCP_JWT_SECRET`, etc.) won't actually authenticate requests in this version because the middleware never fires for `/mcp/*` routes.
**Important caveats**:
- All MCP tool calls will execute as this single delegated account (collapses RLS and audit trail to one user)
- The account needs sufficient FAB roles/permissions to access dashboards (at minimum an Admin or Alpha-level role for `list_dashboards`)
- Per-request JWT→user mapping is expected to land in a future release
The secondary `DBEventLogger.log()` error you're seeing is likely a cascading failure from the same issue — the logger tries to record the failed tool call but also can't resolve the user context.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=0b9acc65-5fc9-4e39-8611-e2ff87acb8cb) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "jmaitrehenry (via GitHub)" <gi...@apache.org>.
jmaitrehenry commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4594858589
@rusackas I didn't make the PR to the main superset repository because I still have the issue when I tested it, so it's not ready yet. Or at least, I need to test it more before.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4594826257
@aminghadersohi this one's right up your alley.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4594831393
Thanks for opening the PR @jmaitrehenry but for now it's just an example to us... please feel free to target the PR at Superset's `master` branch so everyone can benefit :D
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "jmaitrehenry (via GitHub)" <gi...@apache.org>.
jmaitrehenry commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4536966701
@dosu in my configuration, I have the `MCP_DEV_USERNAME` config set: `MCP_DEV_USERNAME = os.environ.get("MCP_DEV_USERNAME")`
And the env var is set to a real username and has the admin role.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] MCP tool error: DetachedInstanceError on PermissionView in list_dashboards (user_id=None) [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #40423:
URL: https://github.com/apache/superset/issues/40423#issuecomment-4537065361
<!-- Answer -->
Thanks for clarifying — this is a more specific issue then. Even with `MCP_DEV_USERNAME` properly set, users on 6.1.0 have reported that the user resolution still fails due to the **Flask app context not being properly maintained during MCP request handling** [[1]](https://github.com/apache/superset/issues/40225).
The issue is that in 6.1.0, the MCP routes run through a FastMCP/ASGI sub-app that bypasses Flask's request lifecycle. Even though `MCP_DEV_USERNAME` is configured, the code that resolves it to an actual user object (via `SecurityManager.get_user_by_username()`) may fail because there's no active Flask app context or SQLAlchemy session available at the time of the lookup [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/security/manager.py#L2457-L2467).
Other users in [#40225](https://github.com/apache/superset/issues/40225) solved this by **patching their Docker image with `auth.py` and `mcp_config.py` from the `master` branch** [[1]](https://github.com/apache/superset/issues/40225). The `master` branch includes several critical fixes that landed after 6.1.0:
- **PR #36013**: Introduced `_setup_user_context()` with eagerly loaded relationships (roles/groups), which prevents the `DetachedInstanceError` on `PermissionView`
- **PR #38747**: Fixed user resolution priority to properly read `MCP_DEV_USERNAME`
- **PR #39798**: Added `db.session.remove()` at the start of tool execution to clear stale thread-local sessions
- **PR #39015**: Added retry logic when `_setup_user_context()` encounters stale database connections
Your `DetachedInstanceError` specifically suggests the user *is* being found, but when RBAC permission checking accesses `PermissionView.permission` (a lazy-loaded relationship), the session is already gone. This matches the pattern fixed by eager-loading relationships in PR #36013.
**Recommended fix**: Replace `superset/mcp_service/auth.py` and `superset/mcp_service/mcp_config.py` in your Docker image with the versions from the current `master` branch, as other users have done successfully. You can add this to your Dockerfile:
```dockerfile
# After your existing RUN commands
COPY --from=master-source /path/to/auth.py /usr/local/lib/python3.9/site-packages/superset/mcp_service/auth.py
COPY --from=master-source /path/to/mcp_config.py /usr/local/lib/python3.9/site-packages/superset/mcp_service/mcp_config.py
```
Or download them directly from the repository's `master` branch and COPY them in.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=048563d3-de9c-41d1-b13a-ed418880c10a) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org