MCP Server vs Claude‑CLI: Picking the Fastest, Most Re‑usable Way to Hook Claude into Your Workflow
For developers seeking the most **efficient** and **re-usable** integration with Claude, the data points to a clear winner: **Build an MCP server.**
Author’s note:
Question: Should I build an MCP server or a CLI tool for Claude? What’s most efficient?
Context: Context:
I want something fast and re-usable.
Executive Summary
For developers seeking the most efficient and re-usable integration with Claude, the data points to a clear winner: Build an MCP server.
While building a custom Command Line Interface (CLI) using the Anthropic API is a valid approach for standalone scripts, the Model Context Protocol (MCP) offers superior performance and reusability. An MCP server using the standard input/output (stdio) transport eliminates network latency, incurs zero per-request API costs for the transport layer, and allows your tools to be used instantly across Claude Desktop, IDEs, and other agents without code changes.
Key findings include:
- Speed: MCP’s stdio transport offers “optimal performance with no network overhead,” whereas API-based CLIs incur 80-100ms+ network round-trips per turn 1.
- Efficiency: Adopting MCP with a “code execution” pattern can reduce token usage by over 98% compared to traditional tool definitions 2.
- Reusability: An MCP server is a universal connector; once built, it works in Claude Desktop, Zed, Replit, and any other MCP client 3.
What Is the Model Context Protocol (MCP)?
The Model Context Protocol (MCP) is an open standard designed to connect AI assistants to systems where data lives, such as content repositories, business tools, and development environments 3.
Architecture & Transports
At its core, MCP uses JSON-RPC 2.0 to exchange messages between a client (like Claude Desktop) and a server (your tool) 1. The protocol defines two primary transport layers, which significantly impact efficiency:
- Stdio Transport (Recommended for Local): The client launches the server as a subprocess and communicates via standard input (
stdin) and standard output (stdout) 4. This method provides “optimal performance with no network overhead” 1. - Streamable HTTP (SSE): Uses Server-Sent Events for streaming messages over HTTP. This is necessary for remote deployments but introduces network latency 4.
For a local workflow, the stdio transport makes MCP servers significantly faster than a custom CLI that must make HTTP requests to the Anthropic API for every interaction.
The Ecosystem Advantage
The ecosystem is growing rapidly, with thousands of servers and SDKs already available 2. Official SDKs for Python and TypeScript abstract away the complexity of the protocol, allowing developers to focus solely on their business logic 5.
Building an MCP Server: The Efficient Path
Building an MCP server is often faster than building a robust CLI because the SDKs handle the “plumbing” (connection, message framing, error handling).
Quick-start: Python
Using the official Python SDK, you can create a server that exposes a tool in just a few lines of code. This server uses the stdio transport by default.
# Example structure based on MCP SDK patternsfrom mcp.server.fastmcp import FastMCP
mcp = FastMCP("my-server")
@mcp.tool()def add(a: int, b: int) -> int: """Add two numbers""" return a + b
if __name__ == "__main__": mcp.run()Note: The Python SDK allows iterating quickly with FastMCP or FastAPI 5.
Quick-start: TypeScript
The TypeScript SDK is ideal if your stack is already Node.js based.
// Example structure based on MCP SDK patternsimport { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({ name: "my-server", version: "1.0.0",});
server.tool("add", { a: z.number(), b: z.number() }, async ({ a, b }) => { return { content: [{ type: "text", text: String(a + b) }] };});
const transport = new StdioServerTransport();await server.connect(transport);Note: This creates a server that communicates via stdio, ready to be connected to a client 6.
Efficiency Benchmark: The “Code Execution” Pattern
One of the most compelling reasons to choose MCP is token efficiency. When agents connect to many tools, loading all tool definitions into the context window can be expensive.
Anthropic engineering found that by presenting MCP servers as code APIs (where the model writes code to call the tool rather than using a direct tool-call definition), they reduced token usage for a task from 150,000 tokens to 2,000 tokens—a saving of 98.7% 2.
Connecting to Claude Desktop
Reusability is a primary advantage of MCP. Instead of building a custom UI or CLI loop, you can plug your server directly into Claude Desktop.
You simply edit the claude_desktop_config.json file to tell Claude where to find your server.
Configuration File Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json7
Configuration Example:
{ "mcpServers": { "my-tool": { "command": "uv", "args": ["run", "my_server.py"] } }}Once configured, the tools provided by your server appear natively in the Claude Desktop interface 7.
The CLI Alternative: Custom vs. Official
If you decide to build a CLI tool instead, you have two options: building a custom tool using the API, or leveraging the official Claude Code CLI.
Option A: Custom CLI (Anthropic API)
Building a custom CLI involves making HTTP requests to https://api.anthropic.com 8.
- Pros: Full control over the user interface and logic.
- Cons: You must handle authentication, rate limits (headers like
anthropic-ratelimit-requests-remaining), and network errors manually 9. Every interaction incurs a network round-trip (80-100ms+). - Cost: You pay for every input and output token sent to the API 9.
Option B: Official Claude Code CLI
Anthropic provides an official CLI tool (claude) that supports MCP natively.
- Command:
claude mcpallows you to configure and manage MCP servers directly from the terminal 10. - Benefit: This offers a “hybrid” approach. You build the logic as an MCP server (reusable) but access it via the command line (fast/scriptable) using the official tool.
Comparative Analysis
The following table contrasts building a custom CLI against building an MCP server (using stdio transport).
| Feature | MCP Server (Stdio) | Custom CLI (API Wrapper) |
|---|---|---|
| Latency | < 5ms (Local process pipe) 1 | ~100ms+ (HTTPS round-trip) |
| Transport Cost | $0 (Local execution) | $0 (But requires API token usage) |
| Reusability | High (Works in Claude Desktop, IDEs, Agents) 3 | Low (Bespoke to your script) |
| Dev Effort | Low (SDKs scaffold the server) 5 | Medium (Must handle auth/retries) 8 |
| Security | Runs with user privileges; requires path whitelisting 7 | Requires API key management |
| Token Efficiency | High (Supports “code execution” pattern) 2 | Variable (Depends on implementation) |
Risks & Failure Modes
While MCP is generally superior for this use case, there are risks to consider:
- Security Exposure: An MCP server runs with the permissions of the user who launches it. If you configure a filesystem server, you must explicitly grant access only to safe directories. The documentation warns: “Only grant access to directories you’re comfortable with Claude reading and modifying” 7.
- Token Bloat: If you connect too many MCP servers without using the code-execution pattern, the sheer volume of tool definitions can slow down the agent and increase costs 2.
- Complexity: For a simple “one-off” question to Claude, a
curlcommand or simple script might be faster to write than a full server. However, the SDKs have largely mitigated this 5.
Recommendation: The Hybrid Pattern
To maximize both speed and reusability, do not choose between a server and a CLI. Build an MCP server and use the official Claude CLI to access it.
- Build the logic as an MCP Server: This ensures your tool is transport-agnostic and can be plugged into Claude Desktop, IDEs, or other agents later.
- Use
claude mcp: Leverage the official Claude Code CLI to interact with your server from the terminal 10.
This approach gives you the scriptability of a CLI tool with the architectural benefits of the Model Context Protocol.
Bottom Line
- For Speed: Choose MCP with stdio transport. It eliminates network overhead 1.
- For Reusability: Choose MCP. Your tool becomes a universal connector for any AI client 3.
- For Efficiency: Use MCP with code execution. This can reduce token overhead by ~98% 2.
- Action Plan:
- Install the Python or TypeScript MCP SDK 5.
- Define your tools in a simple server script.
- Add the server config to
claude_desktop_config.json7. - Access it via Claude Desktop or the
claudeCLI command 10.
References
Footnotes
Other Ideas