Skip to content

Step 7: MCP client — stdio/SSE transports, tool adapter, auto-registration #6

@hackertron

Description

@hackertron

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions