yanand0909 commented on code in PR #107: URL: https://github.com/apache/flink-agents/pull/107#discussion_r2323681939
########## python/flink_agents/api/tools/mcp.py: ########## @@ -0,0 +1,281 @@ +################################################################################ +# 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. +################################################################################# +from __future__ import annotations + +from abc import ABC +import asyncio +from contextlib import AsyncExitStack +from datetime import timedelta +from typing import Any, Dict, List, Optional, Tuple +from urllib.parse import urlparse + +import httpx +from mcp.client.session import ClientSession +from mcp.client.streamable_http import streamablehttp_client +from pydantic import Field +from typing_extensions import override + +from flink_agents.api.resource import Resource, ResourceType +from flink_agents.api.tools.tool import BaseTool, ToolMetadata, ToolType +from flink_agents.api.tools.utils import extract_mcp_content_item +from flink_agents.api.prompts.prompt import Prompt + + + +class MCPToolDefinition(BaseTool): + """MCP tool definition that can be called directly. + + This represents a single tool from an MCP server. + """ + + mcp_server: Optional["MCPServer"] = Field(default=None, exclude=True) + + @classmethod + @override + def tool_type(cls) -> ToolType: + return ToolType.MCP + + @override + def call(self, *args: Any, **kwargs: Any) -> Any: + """Call the MCP tool with the given arguments.""" + if self.mcp_server is None: + raise ValueError("MCP tool call requires a reference to the MCP server") + + return asyncio.run(self.mcp_server._call_tool_async(self.metadata.name, *args, **kwargs)) + + +class MCPPrompt(Prompt): Review Comment: Yes this is what I wanted to discuss as MCPPrompt is conceptually different from Prompt we have we might need to make some changes to our prompt design -- 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]
