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


##########
python/flink_agents/e2e_tests/e2e_tests_integration/mcp_remote_agent.py:
##########
@@ -0,0 +1,112 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+#################################################################################
+"""Agent definitions exercising an MCP server directly, without any LLM.
+
+The actions fetch the MCP ``add`` tool and (for the prompt-enabled server) the
+``ask_sum`` prompt via ``ctx.get_resource`` and invoke them in-process, so the
+test round-trips to a real MCP server without a chat model in the loop.
+"""
+
+from pydantic import BaseModel
+from pyflink.datastream import KeySelector
+
+from flink_agents.api.agents.agent import Agent
+from flink_agents.api.decorators import action, mcp_server
+from flink_agents.api.events.event import Event, InputEvent, OutputEvent
+from flink_agents.api.events.event_type import EventType
+from flink_agents.api.resource import ResourceDescriptor, ResourceName, 
ResourceType
+from flink_agents.api.runner_context import RunnerContext
+
+MCP_SERVER_ENDPOINT_WITH_PROMPTS = "http://127.0.0.1:8000/mcp";
+MCP_SERVER_ENDPOINT_WITHOUT_PROMPTS = "http://127.0.0.1:8001/mcp";
+
+
+class MCPCalcInput(BaseModel):
+    """Input for an MCP calculation request."""
+
+    key: str
+    a: int
+    b: int
+
+
+class MCPCalcKeySelector(KeySelector):
+    """KeySelector extracting the routing key from an MCPCalcInput."""
+
+    def get_key(self, value: MCPCalcInput) -> str:
+        """Extract key from MCPCalcInput."""
+        return value.key
+
+
+def _call_add(ctx: RunnerContext, a: int, b: int) -> int:
+    """Fetch the MCP ``add`` tool and invoke it, returning the numeric sum."""
+    add = ctx.get_resource("add", ResourceType.TOOL)
+    result = add.call({"a": a, "b": b})
+    # MCPTool.call returns a list of extracted content items; the add tool
+    # yields a single text item holding the sum.
+    return int(result[0])
+
+
+class MCPRemoteWithPromptsAgent(Agent):

Review Comment:
   It seems this Agent is intended to replace `MyMCPAgent` in 
`e2e_tests_mcp/mcp_test.py`. However, unlike its predecessor, it does not bind 
MCP prompts and tools to the ChatModel, which I consider a regression in test 
coverage. Could we continue using `MyMCPAgent` instead, limiting changes to 
only the submission and validation logic within the `test_mcp` function?



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