wenjin272 commented on code in PR #1074:
URL: https://github.com/apache/flink-agents/pull/1074#discussion_r3965440447


##########
python/flink_agents/integrations/mcp/mcp.py:
##########
@@ -65,12 +65,20 @@ def tool_type(cls) -> ToolType:
     def call(self, *args: Any, **kwargs: Any) -> Any:
         """Call the MCP tool with the given arguments."""
         if self.mcp_server is None:
-            msg = "MCP tool call requires a reference to the MCP server"
-            raise ValueError(msg)
+            return ToolResponse.error(
+                "MCP tool call requires a reference to the MCP server",
+                tool_name=self.metadata.name,
+            )
 
-        return asyncio.run(
-            self.mcp_server.call_tool_async(self.metadata.name, *args, 
**kwargs)
-        )
+        try:
+            return asyncio.run(
+                self.mcp_server.call_tool_async(self.metadata.name, *args, 
**kwargs)
+            )
+        except Exception as e:

Review Comment:
   Could we also normalize explicit outcomes in `PythonMCPTool.call()`? That 
Java wrapper still wraps every normal Python return in 
`ToolResponse.success(...)`. Returning `ToolResponse.error(...)` here therefore 
causes Java agents using Python MCP tools to record failures as successes. This 
reproduces with real Pemja for both transport exceptions and MCP protocol 
errors. Please cover this path with a cross-language regression test.



##########
python/flink_agents/integrations/mcp/mcp.py:
##########
@@ -237,6 +249,10 @@ async def call_tool_async(self, tool_name: str, *args: 
Any, **kwargs: Any) -> An
 
             content = [extract_mcp_content_item(item) for item in 
result.content]
 
+            if result.isError:

Review Comment:
   Could we move the protocol-error check outside `async with 
self._get_session()`? With a real `ClientSession`, raising here gets wrapped in 
an AnyIO `ExceptionGroup`. `MCPTool.call()` then retains only the outer 
message, “unhandled errors in a TaskGroup”, losing the original MCP error 
content and recovery hints. A regression test retaining the real session 
lifecycle would catch this; the current fake session does not.



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

Reply via email to