mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
basic MCP client structure
This commit is contained in:
parent
177e72334c
commit
3a48f9eee5
4 changed files with 36 additions and 0 deletions
6
litellm/litellm_core_utils/mcp_client/Readme.md
Normal file
6
litellm/litellm_core_utils/mcp_client/Readme.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# LiteLLM MCP Client
|
||||
|
||||
LiteLLM MCP Client is a client that allows you to use MCP tools with LiteLLM.
|
||||
|
||||
|
||||
|
||||
0
litellm/litellm_core_utils/mcp_client/__init__.py
Normal file
0
litellm/litellm_core_utils/mcp_client/__init__.py
Normal file
0
litellm/litellm_core_utils/mcp_client/client.py
Normal file
0
litellm/litellm_core_utils/mcp_client/client.py
Normal file
30
litellm/litellm_core_utils/mcp_client/tools.py
Normal file
30
litellm/litellm_core_utils/mcp_client/tools.py
Normal 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
|
||||
Loading…
Add table
Reference in a new issue