Publications
5 min readVerified by PayArk Labs

Designing APIs for AI Agents First: What the Model Context Protocol Taught Us

What the Model Context Protocol (MCP) taught us about building APIs that AI agents can actually use without hallucinating.

Designing APIs for AI Agents First: What the Model Context Protocol Taught Us

The way we design developer APIs has been frozen in place for a decade. You define a REST contract, document it with OpenAPI, generate a client SDK, and call it done. That paradigm was built for a specific kind of consumer: a human developer who reads docs, reasons about state, and writes code to interact with your system.

That paradigm is ending.

The Model Context Protocol (MCP) forced us to rethink every API design assumption we had at PayArk. What we built as a result changed how we think about the entire surface area of our platform, not just the AI integration layer.


1. What MCP Actually Is (And What It Isn't)

MCP is a specification, championed by Anthropic and adopted by Claude, Cursor, and others, that defines a standardized interface for AI systems to interact with external tools and data sources. At its core, it is deceptively simple: an AI agent calls a "tool," a function with defined input parameters, and receives a structured output. The agent then uses that output to reason about its next step.

This sounds like function-calling. It is not.

The critical distinction is the contract surface. Traditional function-calling is closed: the developer hardcodes the available tools for each specific AI interaction. MCP is open: the AI agent can dynamically discover, introspect, and reason about available tools at runtime. This changes the fundamental design question from "what do I need this agent to do?" to a far more consequential one: what should this system be able to expose?


2. The Fundamental API Design Problem: Humans vs. Agents

Human-first APIs are designed for comprehension. Endpoints are named intuitively, responses can be verbose, and inconsistency is acceptable as long as docs explain the exception.

Agents are different consumers. They don't "read" APIs, they pattern-match structured inputs and outputs against a reasoning graph built from your tool description strings. This imposes rigid requirements that are nearly invisible when building for human consumers.

Consider a standard REST endpoint we had at PayArk:

GET /v1/payments?project_id=proj_abc&status=success&page=2

For a human developer, this is perfectly clear. For an MCP agent, this single endpoint creates an ambiguity explosion. The agent doesn't know the range of valid status values. It doesn't know the pagination scheme. It doesn't know that project_id is required. It can only guess from the description field we provide, and if that description is incomplete, it will call the tool wrong.

After integrating MCP, we identified three core design pillars that separate agent-friendly APIs from the rest.


3. Pillar One: Atomicity Over Composability

Human developers love composable, chainable APIs. Agents cannot compose reliably, they will sometimes take shortcuts, hallucinate intermediate steps, or misinterpret how two separate API calls relate to each other.

For PayArk's MCP server, we rewrote our exposure surface to be atomic: each tool does exactly one thing and returns exactly one decisive result. Instead of exposing "list payments" and "get payment details" as two separate tools requiring the agent to chain calls, we built a single get_payment_analysis tool that accepts a payment ID and returns the full enriched record.

More calls. More round-trips. But zero ambiguity.


4. Pillar Two: Description Strings Are Your Real API

In traditional REST, your API contract is the schema. In MCP, your API contract is the natural language description string attached to every tool and parameter. This is not documentation you write after the fact. It is runtime contract enforcement.

Our tool descriptions are now written with surgical precision. A poorly written description like "gets payments" is a reliability failure. Our actual production description reads:

"Retrieves a single PayArk payment by its ID. Use this tool when you need to diagnose a failed transaction, look up the status of a specific charge, or investigate a webhook delivery failure. Requires a valid payment ID in the format pay_xxxxx. Do not use this for listing multiple payments."

The last sentence is critical. Without explicit negative-scope definitions, agents will attempt to use a single-resource tool like a collection endpoint.


5. Pillar Three: Errors Are Reasoning Inputs

A human reads a 404 response and goes to fix their code. An agent reads a 404 response and attempts to self-correct at runtime. This distinction completely changes how you should design error responses.

PayArk's MCP error responses now include a suggested_action field alongside the standard message:

{
  "error": "not_found_error",
  "message": "Payment pay_xyz was not found.",
  "suggested_action": "Verify the ID by calling list_payments with the relevant project_id first."
}

This single addition reduced agent hallucinations, where the model fabricates a plausible-looking payment ID to retry, by making the recovery path explicit.


6. What REST Gets Wrong for Agents (And What to Keep)

REST was never the problem. Loose REST was the problem. The agent-first constraints MCP imposed actually made our REST API better for human developers too. Atomic endpoints are easier to test. Precise description strings are better documentation. Structured errors give human developers the exact same decision-tree benefit they give AI agents.

The hidden lesson of MCP is that designing for the hardest consumer, an AI agent that cannot ask clarifying questions, cannot read between the lines, and cannot tolerate ambiguity, produces APIs with a level of rigor that benefits every consumer downstream.


7. The Future of the Financial API Surface

PayArk exposes the following MCP tools in production today:

ToolPurpose
list_projectsEnumerate merchant project IDs and metadata
get_paymentRetrieve enriched records with diagnostic context
list_paymentsPaginated query with explicit filter parameters
create_payment_linkGenerate hosted checkout URL from natural language input
get_subscription_statusReturn full lifecycle state with renewal date

We are building toward fully autonomous billing agents: AI systems that can detect a past_due subscription, generate a renewal link, and dispatch a personalized follow-up, all triggered from a single instruction to a Claude or Cursor agent with access to our MCP server.

The era of developers as the sole consumers of APIs is closing. The platforms that win the next cycle are the ones designing infrastructure that machines can reason about just as fluently as humans.


Links:

The Future is Autonomous.

Join the PayArk private alpha and see what industrial-grade financial engineering looks like.

Get Early Access