codeant-ai-for-open-source[bot] commented on code in PR #42629:
URL: https://github.com/apache/superset/pull/42629#discussion_r3691921960


##########
superset/mcp_service/app.py:
##########
@@ -1007,6 +1007,13 @@ def init_fastmcp_server(
     # circular import: flask_singleton imports from superset.extensions which
     # re-enters mcp_service during startup; must stay lazy inside the function.
     from superset.mcp_service.flask_singleton import app as flask_app  # noqa: 
PLC0415
+    from superset.mcp_service.session_scope import (  # noqa: PLC0415
+        install_mcp_session_scoping,
+    )
+
+    # Give each tool call its own SQLAlchemy session; the greenlet-scoped
+    # default lets concurrent async calls share (and tear down) one session.
+    install_mcp_session_scoping()

Review Comment:
   **Suggestion:** The factory-configured server path in `server.py` calls 
`create_mcp_app(**factory_config)` directly and never reaches 
`init_fastmcp_server()`. Consequently, deployments using 
`use_factory_config=True` do not install the MCP-aware scope function, so 
`_mcp_tool_call_context()` still creates per-call tokens that `db.session` 
ignores and concurrent tool calls continue sharing the greenlet-scoped session. 
Install the scoping during every MCP server creation path, including the 
factory path. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Factory-configured concurrent tools can share SQLAlchemy sessions.
   - ❌ One call teardown can detach another call’s ORM instances.
   - ⚠️ Default MCP server initialization is not affected.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=80304c042b0a4674890a1271a2cde3fa&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=80304c042b0a4674890a1271a2cde3fa&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/app.py
   **Line:** 1016:1016
   **Comment:**
        *Api Mismatch: The factory-configured server path in `server.py` calls 
`create_mcp_app(**factory_config)` directly and never reaches 
`init_fastmcp_server()`. Consequently, deployments using 
`use_factory_config=True` do not install the MCP-aware scope function, so 
`_mcp_tool_call_context()` still creates per-call tokens that `db.session` 
ignores and concurrent tool calls continue sharing the greenlet-scoped session. 
Install the scoping during every MCP server creation path, including the 
factory path.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42629&comment_hash=b45cebe9bbec0c25b7cbaefbe2e742c28b979cc16a06d6d83b121ded1842c28c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42629&comment_hash=b45cebe9bbec0c25b7cbaefbe2e742c28b979cc16a06d6d83b121ded1842c28c&reaction=dislike'>👎</a>



-- 
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]

Reply via email to