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


##########
superset/core/mcp/core_mcp_injection.py:
##########
@@ -38,6 +38,32 @@
 logger = logging.getLogger(__name__)
 
 
+def _resolve_tool_name(base_name: str, replaces: Optional[str]) -> tuple[str, 
str]:
+    """Return (tool_name, context_type) for registration.
+
+    When *replaces* is set the tool is replacing a host tool, so the name is
+    used as-is and context_type is always "host".
+    """
+    if replaces is not None:
+        return replaces, "host"
+    return _get_prefixed_id_with_context(base_name)
+
+
+def _remove_tool_for_replacement(mcp: Any, name: str) -> None:
+    """Remove *name* from the MCP registry before registering a replacement.
+
+    Logs a warning (rather than raising) when the tool is not found, which
+    can happen if registration order changes or in partial-init environments.
+    """
+    try:
+        mcp.remove_tool(name)

Review Comment:
   **Suggestion:** The replacement-removal helper calls `mcp.remove_tool`, but 
this codebase removes tools through `mcp.local_provider.remove_tool`; if 
`FastMCP` does not expose `remove_tool` on the top-level object, replacement 
registration will raise `AttributeError` and fail before the new tool is added. 
Use the same removal path used elsewhere (`local_provider.remove_tool`) to 
avoid a runtime API mismatch. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Extensions replacing host tools crash during MCP tool registration.
   - ❌ Replacement tools never register; host tools remain active.
   - ⚠️ LLM clients cannot use optimized get_instance_info replacement.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction âś… </b></summary>
   
   ```mdx
   1. Start the MCP service so `superset.mcp_service.app.mcp` is created as a 
`FastMCP`
   instance via `create_mcp_app()` (superset/mcp_service/app.py:60-77, 600-637) 
and
   `initialize_core_mcp_dependencies()` is called to inject concrete decorators
   (superset/core/mcp/core_mcp_injection.py:54-76, 337-416;
   superset/mcp_service/app.py:640-646).
   
   2. Observe that all existing code paths that remove tools from the MCP 
registry use
   `mcp.local_provider.remove_tool(tool_name)` 
(superset/mcp_service/app.py:20-36 and 39-43
   in the 818-876 snippet, corresponding to file lines ~846 and ~859), and 
there are no other
   references to `mcp.remove_tool` in the repository (verified by `Grep` for 
`remove_tool`).
   
   3. In an extension package that uses the public stub decorator, import 
`tool` from
   `superset_core.mcp.decorators` and define a replacement tool as shown in the 
stub
   docstring (superset-core/src/superset_core/mcp/decorators.py:91-94):
   `@tool(replaces="get_instance_info")` followed by `def 
my_custom_instance_info() -> dict:
   ...`. When the extension module is imported, 
`initialize_core_mcp_dependencies()` has
   already replaced `superset_core.mcp.decorators.tool` with 
`create_tool_decorator`
   (superset/core/mcp/core_mcp_injection.py:72-74, 337-416).
   
   4. During decoration, `create_tool_decorator(..., 
replaces="get_instance_info")` calls
   `_remove_tool_for_replacement(mcp, replaces)`
   (superset/core/mcp/core_mcp_injection.py:78-80, 60-120), which in turn calls
   `mcp.remove_tool(name)` at superset/core/mcp/core_mcp_injection.py:59 (35-74 
snippet line
   25). Because the codebase’s established removal API is 
`mcp.local_provider.remove_tool`
   and there is no evidence of a top-level `FastMCP.remove_tool` method, this 
call will raise
   `AttributeError` on the `FastMCP` instance, causing the decorator’s 
try-block to fail and
   re-raise (superset/core/mcp/core_mcp_injection.py:68-88, 60-120). The 
replacement tool is
   never registered and extension initialization fails.
   ```
   </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=784242e3933b47f48f01783bebba20a8&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=784242e3933b47f48f01783bebba20a8&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/core/mcp/core_mcp_injection.py
   **Line:** 59:59
   **Comment:**
        *Api Mismatch: The replacement-removal helper calls `mcp.remove_tool`, 
but this codebase removes tools through `mcp.local_provider.remove_tool`; if 
`FastMCP` does not expose `remove_tool` on the top-level object, replacement 
registration will raise `AttributeError` and fail before the new tool is added. 
Use the same removal path used elsewhere (`local_provider.remove_tool`) to 
avoid a runtime API mismatch.
   
   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%2F41607&comment_hash=7cbf7250f403da0614da935a13368dfe568f841f8588531b34e354d3c0237867&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41607&comment_hash=7cbf7250f403da0614da935a13368dfe568f841f8588531b34e354d3c0237867&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