Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

doc litellm MCP client

Ishaan Jaff145d2d8dd61b
diff --git a/docs/my-website/docs/mcp.md b/docs/my-website/docs/mcp.md
new file mode 100644
index 00000000000..ef198de9478
--- /dev/null
+++ b/docs/my-website/docs/mcp.md
@@ -0,0 +1,114 @@
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+# /mcp Model Context Protocol [Beta]
+
+Use Model Context Protocol with LiteLLM.
+
+## Overview
+
+LiteLLM supports Model Context Protocol (MCP) tools by offering a client that exposes a tools method for retrieving tools from a MCP server
+
+## Usage
+
+<Tabs>
+<TabItem value="sdk" label="LiteLLM Python SDK">
+
+```python
+import asyncio
+from litellm import experimental_create_mcp_client, completion
+from litellm.mcp_stdio import experimental_stdio_mcp_transport
+
+async def main():
+ client_one = None
+
+ try:
+ # Initialize an MCP client to connect to a `stdio` MCP server:
+ transport = experimental_stdio_mcp_transport(
+ command='node',
+ args=['src/stdio/dist/server.js']
+ )
+ client_one = await experimental_create_mcp_client(
+ transport=transport
+ )
+
+ tools = await client_one.list_tools(format="openai")
+ response = await litellm.completion(
+ model="gpt-4o",
+ tools=tools,
+ messages=[
+ {
+ "role": "user",
+ "content": "Find products under $100"
+ }
+ ]
+ )
+
+ print(response.text)
+ except Exception as error:
+ print(error)
+ finally:
+ await asyncio.gather(
+ client_one.close() if client_one else asyncio.sleep(0),
+ )
+
+if __name__ == "__main__":
+ asyncio.run(main())
+```
+
+</TabItem>
+<TabItem value="proxy" label="LiteLLM Proxy Server">
+
+```python
+import asyncio
+from openai import OpenAI
+from litellm import experimental_create_mcp_client
+from litellm.mcp_stdio import experimental_stdio_mcp_transport
+
+async def main():
+ client_one = None
+
+ try:
+ # Initialize an MCP client to connect to a `stdio` MCP server:
+ transport = experimental_stdio_mcp_transport(
+ command='node',
+ args=['src/stdio/dist/server.js']
+ )
+ client_one = await experimental_create_mcp_client(
+ transport=transport
+ )
+
+ # Get tools from MCP client
+ tools = await client_one.list_tools(format="openai")
+
+ # Use OpenAI client connected to LiteLLM Proxy Server
+ client = openai.OpenAI(
+ api_key="sk-1234",
+ base_url="http://0.0.0.0:4000"
+ )
+ response = client.chat.completions.create(
+ model="gpt-4",
+ tools=tools,
+ messages=[
+ {
+ "role": "user",
+ "content": "Find products under $100"
+ }
+ ]
+ )
+
+ print(response.choices[0].message.content)
+ except Exception as error:
+ print(error)
+ finally:
+ await asyncio.gather(
+ client_one.close() if client_one else asyncio.sleep(0),
+ )
+
+if __name__ == "__main__":
+ asyncio.run(main())
+```
+
+</TabItem>
+</Tabs>
+
diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js
index 1df988f372d..a1499cc0b01 100644
--- a/docs/my-website/sidebars.js
+++ b/docs/my-website/sidebars.js
@@ -293,6 +293,7 @@ const sidebars = {
"text_completion",
"embedding/supported_embedding",
"anthropic_unified",
+ "mcp",
{
type: "category",
label: "/images",