Skip to content

feat: add stdio MCP server support for client-side tool execution#707

Open
pmukeshreddy wants to merge 5 commits intoletta-ai:mainfrom
pmukeshreddy:feat/stdio-mcp-support
Open

feat: add stdio MCP server support for client-side tool execution#707
pmukeshreddy wants to merge 5 commits intoletta-ai:mainfrom
pmukeshreddy:feat/stdio-mcp-support

Conversation

@pmukeshreddy
Copy link

Summary

Implements #150 - adds support for connecting stdio MCP servers through client-side tool execution.

Since agents run on Letta Cloud, they can connect to http and sse MCP servers directly. This PR enables stdio server support by executing tools client-side via the CLI.

How it works

  1. User adds stdio server: /mcp add --transport stdio <name> <command> [args...]
  2. CLI spawns the MCP server as a local subprocess
  3. Tools are registered with Letta Cloud (with require_approval=true)
  4. When agent calls a tool, CLI intercepts the approval request
  5. CLI executes tool locally via stdio and returns result to server

Changes

  • Add src/mcp/ module for managing stdio server connections
  • Update src/cli/commands/mcp.ts with stdio server registration
  • Update src/agent/approval-execution.ts for client-side MCP tool execution
  • Update src/headless.ts for MCP initialization and cleanup

Test plan

# Add stdio MCP server
/mcp add --transport stdio test npx @modelcontextprotocol/server-everything

# Test tools
echo "hello"
get environment variables
calculate sum of 10 and 25

Demo

All 9 tools from @modelcontextprotocol/server-everything tested successfully:

  • echo, get_env, get_annotated_message, get_sum, get_tiny_image
  • get_structured_content, get_resource_reference, get_resource_links, gzip_file_as_resource

Closes #150

Implements letta-ai#495 - enables connecting stdio MCP servers to Letta Cloud
through client-side tool execution.

Key changes:
- Add MCP module (src/mcp/) for managing stdio server connections
- Register MCP tools with Letta Cloud using approval flow
- Execute MCP tools locally via stdio when approved
- Track tool-to-server mappings for proper routing
- Support tool name mapping (Python-safe to original names)

The implementation leverages the existing approval architecture:
1. User adds stdio MCP server via `/mcp add --transport stdio`
2. CLI spawns subprocess and fetches tool definitions
3. Tools are registered with Letta Cloud (require_approval=true)
4. When agent calls tool, CLI intercepts approval request
5. CLI executes tool locally and returns result to server
@pmukeshreddy
Copy link
Author

Testing Instructions

# Clone & setup
git clone https://github.com/pmukeshreddy/letta-code.git
cd letta-code
git checkout feat/stdio-mcp-support
bun install

# Run with your API key
export LETTA_API_KEY=your-key-here
bun run dev

Test stdio MCP

/mcp add --transport stdio test npx @modelcontextprotocol/server-everything

# Try these:
echo "Hello from MCP!"
What are my environment variables?
Calculate sum of 15 and 27

Should see tools execute locally via stdio subprocess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support stdio MCP servers

1 participant