Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

Add comments to the MCP example (#2507)

Will Sargentc548a35781b2
diff --git a/examples/mcp_example.py b/examples/mcp_example.py
index a12c3faf1..13ba92d7c 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=[