change location of MCP client

This commit is contained in:
Ishaan Jaff 2025-03-21 10:30:57 -07:00
parent 50ec2bd5c9
commit 039129676c
5 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1,30 @@
from typing import List, Literal, Union
from mcp import ClientSession
from mcp.types import Tool as MCPTool
from litellm.types.llms.openai import Tool
def transform_mcp_tool_to_openai_tool(tool: MCPTool) -> Tool:
"""Convert an MCP tool to an OpenAI tool."""
raise NotImplementedError("Not implemented")
async def load_mcp_tools(
session: ClientSession, format: Literal["mcp", "openai"] = "mcp"
) -> Union[List[MCPTool], List[Tool]]:
"""
Load all available MCP tools
Args:
session: The MCP session to use
format: The format to convert the tools to
By default, the tools are returned in MCP format.
If format is set to "openai", the tools are converted to OpenAI tools.
"""
tools = await session.list_tools()
if format == "openai":
return [transform_mcp_tool_to_openai_tool(tool) for tool in tools.tools]
return tools.tools