An MCP is not designed like an API
Published: · 2 min read
I built an MCP server so an AI could query business data. I thought it would be like building an API. It was not.
An API is consumed by a developer who reads the documentation once. An MCP is consumed by a model that decides, on every call, which tool to use, with which parameters and how many times. It also never gets tired, and it retries in a loop.
Designing tools is not exposing endpoints
Fewer tools, organised by intent. If you mirror your API one to one, the
model gets confused and your context fills up. buscar_cliente beats six CRUD
endpoints.
The description is a prompt. The model picks the tool based only on what the description says. Changing one line changes its behaviour, so you version it and test it like code.
Parameters that cannot be misread. I use enums, explicit formats and examples. If the model can guess, it will guess.
{
"formato": "YYYY-MM-DD",
"estado": ["activo", "inactivo"]
}
Responses written for the context window. I return summarised, useful data, not the raw 200-field JSON. Every token you return is a token you pay for.
The error is a prompt too. “You do not have access, use listar_clientes”
works far better than an empty 403. The agent corrects itself.
Security
Short-lived tokens, and a second factor for anything sensitive. The agent being authenticated does not mean the person is present.
Permissions belong to the resource, not to the tool. Being able to call
consultar_cliente does not grant access to every client. Never trust the ID the
LLM puts there.
I start read-only. Writes are enabled explicitly, with human confirmation.
Architecture and scalability
A gateway concentrates authentication, rate limiting and auditing. The tools only hold their own logic.
The server is stateless and scales horizontally. Sessions and counters live in Redis.
Rate limiting goes by cost. A heavy query drains more of the bucket than a
ping. I answer 429 with Retry-After.
There is a cache per tool, because agents repeat the same question a lot.
Heavy work goes async. The tool returns a job_id and the agent polls the
status with another tool.
Pagination is mandatory, with a hard cap on rows per response.
Short timeouts and a circuit breaker, to fail fast and with a clear message.
Observability
I log which tool was called, who called it, with what scope, how long it took and how many tokens it returned.
tool: buscar_cliente
user: agente-123
scope: clientes
duration: 842ms
tokens: 487
That is how you catch the loops before they reach the invoice.
In short
An API is designed for people who read documentation. An MCP is designed for a client that interprets, improvises and never sleeps.