mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
transform_mcp_tool_to_openai_tool
This commit is contained in:
parent
6e888474e1
commit
cd6055cfb0
2 changed files with 17 additions and 7 deletions
|
@ -2,18 +2,26 @@ from typing import List, Literal, Union
|
|||
|
||||
from mcp import ClientSession
|
||||
from mcp.types import Tool as MCPTool
|
||||
|
||||
from litellm.types.llms.openai import Tool
|
||||
from openai.types.chat import ChatCompletionToolParam
|
||||
from openai.types.shared_params.function_definition import FunctionDefinition
|
||||
|
||||
|
||||
def transform_mcp_tool_to_openai_tool(tool: MCPTool) -> Tool:
|
||||
def transform_mcp_tool_to_openai_tool(mcp_tool: MCPTool) -> ChatCompletionToolParam:
|
||||
"""Convert an MCP tool to an OpenAI tool."""
|
||||
raise NotImplementedError("Not implemented")
|
||||
return ChatCompletionToolParam(
|
||||
type="function",
|
||||
function=FunctionDefinition(
|
||||
name=mcp_tool.name,
|
||||
description=mcp_tool.description or "",
|
||||
parameters=mcp_tool.inputSchema,
|
||||
strict=False,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def load_mcp_tools(
|
||||
session: ClientSession, format: Literal["mcp", "openai"] = "mcp"
|
||||
) -> Union[List[MCPTool], List[Tool]]:
|
||||
) -> Union[List[MCPTool], List[ChatCompletionToolParam]]:
|
||||
"""
|
||||
Load all available MCP tools
|
||||
|
||||
|
@ -26,5 +34,7 @@ async def load_mcp_tools(
|
|||
"""
|
||||
tools = await session.list_tools()
|
||||
if format == "openai":
|
||||
return [transform_mcp_tool_to_openai_tool(tool) for tool in tools.tools]
|
||||
return [
|
||||
transform_mcp_tool_to_openai_tool(mcp_tool=tool) for tool in tools.tools
|
||||
]
|
||||
return tools.tools
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue