[email protected]
Portfolio / mcp2cli

mcp2cli

Open source under the MIT licence. View the source

Indexed as a reference implementation in the XERJ Corpus Hub. XERJ Corpus Hub contributor

A CLI that lets agents call MCP server tools through bash instead of loading every tool definition into the system prompt.

mcp2cli

The problem

Loading all MCP tool definitions into an LLM's system prompt costs roughly 13K+ tokens permanently. With mcp2cli an agent pays context only for the one tool schema it looks up when it needs it.

How it works

The CLI reads a service registry (~/.config/mcp2cli/services.json, same command/args/env shape as Claude Desktop's mcpServers) and dispatches tool calls to a persistent daemon over a Unix socket. The daemon keeps a pooled, health-checked connection to each MCP server so calls return in milliseconds instead of paying a 2-5 second startup, and exits after an idle timeout (default 60s). Input is validated before dispatch and output is always structured JSON on stdout with logs on stderr and semantic exit codes.

How mcp2cli works

Features

  • mcp2cli <service> <tool> --params '<json>' invokes any tool; mcp2cli schema <service>.<tool> inspects its schema on demand
  • Persistent daemon with connection pool and idle shutdown
  • Structured JSON output and semantic exit codes (validation, auth, tool, connection, internal)
  • --dry-run, --fields filtering, and --params - to pass secrets on stdin instead of argv
  • generate-skills builds agent skill files from MCP tool schemas
  • Multi-user tokens with RBAC roles and per-identity credential management

How it was built

The first version shipped on 2026-03-09. It moved the tools of every registered MCP server behind one shell command, so coding agents stopped loading every tool definition into context on every turn.

A daemon replaced one process per call because spawning a server each time was slow. It holds a connection pool, exits when idle, and later grew a network mode so several machines share one set of connections and credentials.

The container image first bundled every MCP server and failed to build five times for five different reasons. The fix was to call each server over HTTP from its own deployment instead of bundling them.

Audit logs once stored values returned by secret-lookup tools because key-based sanitising could not see a secret under a neutral key. Redaction moved to the service and tool name, recording only the response length.

Claude Opus co-authored 29 of 66 commits, and from September work ran as small agent lanes, each with a check that had to fail before the change and pass after it. Rico made the design calls, including the deliberate over-redaction.