From c548a35781b267dc79c76d58805dea4f2f9e4621 Mon Sep 17 00:00:00 2001 From: Will Sargent Date: Thu, 20 Mar 2025 09:38:25 -0700 Subject: [PATCH] Add comments to the MCP example (#2507) --- examples/mcp_example.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/mcp_example.py b/examples/mcp_example.py index a12c3faf..13ba92d7 100644 --- a/examples/mcp_example.py +++ b/examples/mcp_example.py @@ -2,22 +2,33 @@ from pprint import pprint from letta_client import Letta +# Connect to Letta server client = Letta(base_url="http://localhost:8283") +# Use the "everything" mcp server: +# https://github.com/modelcontextprotocol/servers/tree/main/src/everything mcp_server_name = "everything" mcp_tool_name = "echo" +# List all McpTool belonging to the "everything" mcp server. mcp_tools = client.tools.list_mcp_tools_by_server( mcp_server_name=mcp_server_name, ) + +# We can see that "echo" is one of the tools, but it's not +# a letta tool that can be added to a client (it has no tool id). for tool in mcp_tools: pprint(tool) +# Create a Tool (with a tool id) using the server and tool names. mcp_tool = client.tools.add_mcp_tool( mcp_server_name=mcp_server_name, mcp_tool_name=mcp_tool_name ) +# Create an agent with the tool, using tool.id -- note that +# this is the ONLY tool in the agent, you typically want to +# also include the default tools. agent = client.agents.create( memory_blocks=[ { @@ -31,6 +42,7 @@ agent = client.agents.create( ) print(f"Created agent id {agent.id}") +# Ask the agent to call the tool. response = client.agents.messages.create( agent_id=agent.id, messages=[