Context
MCP (Model Context Protocol) lets external tool servers plug into Yantra. Any MCP-compatible server becomes a Yantra tool automatically.
Scope
MCP client
- Stdio transport — spawn subprocess, communicate over stdin/stdout
- SSE transport — connect to HTTP server, receive Server-Sent Events
- Call
tools/list to discover available tools
- Call
tools/call to execute tools
MCPToolAdapter
- Wraps each MCP tool as a
types.Tool
- Name:
<server>_<tool> (namespaced to avoid collisions)
- SafetyTier:
SideEffecting (conservative default for external tools)
- Schema: converted from MCP tool schema to Yantra FunctionDecl
Config-driven discovery
- Read
mcp.servers from config
- For each server: spawn/connect, list tools, wrap, register
- Environment variable forwarding (
env map in config)
Auto-registration
- All adapted tools registered in ToolRegistry at startup
- Appear alongside native tools in LLM function calling
Config example
[mcp.servers.filesystem]
transport = "stdio"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "."]
[mcp.servers.github]
transport = "stdio"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_TOKEN = "env:GITHUB_TOKEN" }
[mcp.servers.postgres]
transport = "sse"
url = "http://localhost:3001/sse"
Files to create
internal/mcp/
├── client.go # MCP client (stdio + SSE)
├── adapter.go # MCPToolAdapter
├── manager.go # Discovery + registration
└── mcp_test.go
Dependencies
github.com/modelcontextprotocol/go-sdk (or raw protocol implementation)
- Config types already exist in
internal/types/config.go (MCPConfig, MCPServerConfig)
Context
MCP (Model Context Protocol) lets external tool servers plug into Yantra. Any MCP-compatible server becomes a Yantra tool automatically.
Scope
MCP client
tools/listto discover available toolstools/callto execute toolsMCPToolAdapter
types.Tool<server>_<tool>(namespaced to avoid collisions)SideEffecting(conservative default for external tools)Config-driven discovery
mcp.serversfrom configenvmap in config)Auto-registration
Config example
Files to create
Dependencies
github.com/modelcontextprotocol/go-sdk(or raw protocol implementation)internal/types/config.go(MCPConfig, MCPServerConfig)