MCP vs direct API integrations (and CLIs): when each one wins A benchmark on Node.js 22 comparing direct HTTP API calls, local CLIs and MCP servers found that MCP's M+N integration math only pays off when an AI agent crosses an ownership or runtime boundary, and that scaling an MCP server from 3 tools to 15 tools inflates prompt token overhead. The author measured startup time, per-call latency, prompt token overhead with OpenAI gpt-4.1-mini and lines of glue code for the same 3-operation local HTTP task service built each way, concluding that teams with a single AI host (M=1) add a protocol layer and an extra network or pipe hop for portability they don't need. The analysis argues MCP wins when exposing a product to third-party AI hosts or when several AI hosts run on one machine and need a stateful or authenticated integration. MCP vs direct API integrations and CLIs : when each one wins By Flavio https://flaviocopes.com/about/ Tagged: AI https://flaviocopes.com/tags/ai/ Compare direct HTTP APIs, local CLIs, and MCP servers with real latency and token benchmarks, auth and versioning tradeoffs, and a practical decision guide. When you connect an AI agent to an external system, you have three options. You can call the HTTP API directly from your own tool functions, wrap the system in a local CLI and let the agent run shell commands, or put an MCP https://flaviocopes.com/what-is-mcp/ server in front of it. A lot of teams now reach for MCP by default. Others avoid it completely because one bloated server ate a third of their context window. Both reactions miss the engineering tradeoffs. Each pattern puts the work in a different layer. Direct API calls keep everything inside your application process. A CLI pushes tool discovery to --help and pays a process spawn cost on every command. An MCP server adds a standard protocol boundary between the AI host and your integration. That gives you portability and credential isolation, at the cost of extra wiring and, if you expose too many tools, heavy prompt overhead. I wanted real numbers instead of opinions, so I wired the same 3-operation local HTTP task service using each approach on Node.js 22. I measured startup time, per-call latency, prompt token overhead with OpenAI gpt-4.1-mini , and lines of glue code. Then I scaled the MCP server from 3 tools to 15 tools to see what happens to the token budget. In this post, we’ll look at the M-by-N integration math and the benchmark data. We’ll also cover the parts a latency chart hides: authentication, multi-tenancy, versioning, error recovery, debugging, and hybrid patterns like deferred loading and Code Mode. The M-by-N promise, and when M is 1 The original pitch for MCP comes down to simple arithmetic. Suppose you have M AI applications Claude Code, Cursor, Codex, a desktop assistant and N external systems GitHub, Postgres, Sentry, Stripe, Linear . Without a shared protocol, every AI app needs its own custom integration for every external system. That leaves you with M N connectors to build, authenticate, and maintain. MCP puts a standard contract in the middle. Each AI host implements one MCP client layer, and each external system ships one MCP server. That drops the total number of integrations from M N to M + N . Once you build a server, every compatible host can discover its tools right away without custom glue. The math holds up, and it explains why MCP caught on so quickly with SaaS vendors and editor makers. Astro built one docs MCP server and it immediately worked in Claude Code, Cursor, and Codex. The trap is applying M N thinking when M = 1 . Say you’re building an AI support assistant or a workflow agent inside your own web app. There’s only one AI host here: your backend. Your backend already owns the prompt loop, calls the model provider SDK, and runs tool handlers. It also already talks to your Postgres database, billing API, and internal microservices. Plug M = 1 into both formulas. Direct integrations need 1 N = N tool adapters. Adding MCP requires 1 + N moving parts: an MCP client inside your backend plus N separate MCP servers, along with their transports, auth tokens, process supervision, and schema versioning. You end up adding a protocol layer and an extra network or pipe hop to solve a cross-host portability problem you don’t have. Even when M = 2 , like a backend API and an internal Slack bot in the same TypeScript monorepo, importing a shared internal package with typed functions is easier than running JSON-RPC between your own services. MCP only starts paying back its protocol overhead when you cross an ownership or runtime boundary. That happens in two cases: - You’re exposing your product to third-party AI hosts you don’t control. - You use several AI hosts on your own machine and want to configure a stateful or authenticated integration once instead of rewriting it per editor. Before you pick a protocol, count M . If M is 1 and stays 1, a plain function calling an HTTP API or SDK is almost always the right starting point. Three ways to wire the same service Before we look at the numbers, let’s clear up a common misconception. The language model itself doesn’t speak MCP, HTTP, or bash. At the model API boundary, every integration boils down to the same tool calling https://flaviocopes.com/ai-glossary/tool-calling/ loop. The host sends an array of JSON tool definitions, and the model replies with a tool name and JSON arguments. Then the host runs the tool and feeds the text result back into the next turn. The difference between direct APIs, CLIs, and MCP lives entirely between your agent host and the target service: In the direct API pattern, your agent harness registers one tool definition per operation right in code. When the model requests update task , your code validates the JSON arguments in memory, calls fetch or an official SDK client , and returns a trimmed JSON string. There’s no child process, no extra protocol framing, and no discovery handshake. In the local CLI pattern, your harness gives the model a single generic shell tool or a dedicated CLI runner . A small script or binary wraps the service, parses flags, calls the HTTP API, and prints JSON or plain text to stdout. Instead of loading every endpoint schema into the prompt upfront, you give the agent a short skill description or let it run tasks --help when needed. Every call spawns a fresh OS process, runs the command, and exits. In the MCP server pattern, the host creates a protocol client that talks to a separate server. That connection runs over stdio https://flaviocopes.com/ai-glossary/stdio/ a long-lived child process speaking newline-delimited JSON-RPC 2.0 or Streamable HTTP https://flaviocopes.com/ai-glossary/streamable-http/ an HTTP endpoint returning JSON or Server-Sent Events . At startup or on demand, the host calls tools/list , converts the server’s schemas into model tool definitions, and forwards each tool call as a tools/call JSON-RPC request. The server makes the real HTTP request and returns structured content plus text blocks. Notice what moves as you go from left to right: - Direct APIs : the host owns the code, types, credentials, and schemas. - Local CLI : the shell runs commands, and the binary owns its flags and help text. - MCP : the server owns the schemas, execution, and credentials, while the host only speaks JSON-RPC. Measuring the three patterns on the same task service Diagrams make every option look tidy. Real numbers show where the friction sits. To compare the three patterns fairly, I built a small local HTTP task service with three operations: listing tasks, reading one task by ID, and updating a task’s status. Every adapter hit that same localhost HTTP service on Node.js 22, keeping network jitter and database speed constant. I also wanted real prompt token counts instead of rough character-to-token estimates. So I sent the tool definitions for each setup through OpenAI gpt-4.1-mini and recorded the measured prompt tokens. First, let’s see how thin the integration layer is for each setup. The direct fetch wrapper needs zero transport boilerplate. You define the three tool schemas for the model and map each tool name to a fetch call: js const BASE = 'http://127.0.0.1:4010' export async function runDirectTool name, args { if name === 'list tasks' { const q = args.status ? ?status=${encodeURIComponent args.status } : '' return fetch ${BASE}/tasks${q} .then r = r.json } if name === 'get task' { return fetch ${BASE}/tasks/${encodeURIComponent args.id } .then r = r.json } if name === 'update task' { return fetch ${BASE}/tasks/${encodeURIComponent args.id } , { method: 'PATCH', headers: { 'content-type': 'application/json' }, body: JSON.stringify { status: args.status } , } .then r = r.json } throw new Error Unknown tool: ${name} } That entire adapter is 14 lines of glue code. Every type, header, and error check lives right next to your agent loop. The local CLI wrapper is almost as small at 16 lines of glue, and the model only sees one shell tool on the host side. On disk, a Node.js script parses process.argv , hits the same local HTTP endpoints, and prints JSON to stdout: js /usr/bin/env node const cmd, arg1, arg2 = process.argv.slice 2 const BASE = 'http://127.0.0.1:4010' if cmd === 'list' { const q = arg1 ? ?status=${encodeURIComponent arg1 } : '' console.log await fetch ${BASE}/tasks${q} .then r = r.text } else if cmd === 'get' { console.log await fetch ${BASE}/tasks/${encodeURIComponent arg1 } .then r = r.text } else if cmd === 'update' { const res = await fetch ${BASE}/tasks/${encodeURIComponent arg1 } , { method: 'PATCH', headers: { 'content-type': 'application/json' }, body: JSON.stringify { status: arg2 } , } console.log await res.text } else { console.error 'Usage: tasks