Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Concept · 15 min · revision 3

Designing Tools for Agents, Not for APIs

Design MCP tools around the tasks an agent performs rather than the endpoints an API exposes: a few task-level tools, concise results that keep the identifiers needed for the next call, actionable tool errors, and bounded output with a stable order and a cursor.

Contentsand lesson path

What you will learn

  • Design server tools for agents: a few task-level tools with concise, paginated, deterministically ordered output instead of one tool per API endpoint.

Prerequisites: MCP Fundamentals

01. Why it matters

A web front end calls an API with fixed code: it knows which endpoint to call, ignores the fields it does not need, and pays almost nothing for a large payload. An agent is different. The model reads every tool definition before it acts, chooses tools by their names and descriptions, and reads every byte of every result into its context window. Context is limited and costs money and time, and irrelevant fields compete for the model's attention with the facts that matter.

So the first instinct when wrapping an existing service, one MCP tool per REST endpoint, usually works badly. With forty endpoints the model must pick among forty similar tools, chain several calls for one user request, and carry raw JSON between them. Each extra step is another chance to pass a wrong argument. This lesson gives you four design rules, and the lab in lesson 3 applies them to a real wrapper.

02. Rule 1: A few task-level tools

Start from the jobs users will ask the agent to do, not from the API reference. For an issue tracker those jobs might be: find issues matching some criteria, read one issue in enough detail to act on it, change an issue's state, and summarise what needs attention. Each job becomes one tool, even when it needs several API calls inside:

  • search_issues(state, label, limit, cursor) replaces list, filter and pagination endpoints;
  • get_issue(number) fetches the issue and the few comment details that matter, instead of exposing issue, comments and reactions endpoints separately;
  • set_issue_state(number, state) replaces a generic PATCH with a narrow, typed change.

A tool that combines calls is not automatically all-or-nothing. If it creates a branch, starts a build and updates DNS, a failure in step three leaves the first two done. The tool then owns partial failure: make each step safe to repeat (idempotent), report which steps completed, and undo or resume where possible.

Keep write tools narrow and visible. A separate set_issue_state with an enum is easier for a host to put behind a confirmation prompt than a generic "update anything" tool. The specification also lets you attach annotations such as readOnlyHint and destructiveHint to a tool; clients may use them for display or confirmation, but must treat them as untrusted hints from servers they do not trust, so they never replace access control.

03. Rule 2: Concise results that keep the identifiers

Return the fields that inform the agent's next decision. For an issue that is usually its number, title, state, label, assignee and comment count, not node IDs, avatar URLs, reaction counts or audit timestamps. In lesson 3 the tracker returns 19 fields and 1,077 bytes for one issue, and the tool returns 8 fields and 341 bytes. Measure your own payloads in bytes, and in tokens with your model's token counter, before and after shaping them.

Two refinements matter in practice:

  • Keep the identifiers the next call needs. If get_issue drops the issue number, the agent cannot call set_issue_state afterwards. What you remove are opaque internal keys (UUIDs, node IDs) that no tool accepts. Where a cryptic ID is the only handle, resolve it to something meaningful, such as a login instead of a numeric user ID.
  • Let the caller ask for more. A parameter such as detail: Literal["concise", "detailed"] = "concise" keeps the common case small while still allowing a full record when the agent needs it. For a whole record that a user wants to attach as context, a resource such as issues://{number} is often a better fit than a tool.

Errors follow the same idea. Raise a tool error whose message says what went wrong and what to do next, for example "Not found. Use search_issues to find valid issue numbers." An HTTP status code or a stack trace tells the model nothing it can act on. A failure that no retry can fix, such as rejected server credentials, should say so, so the agent stops retrying.

04. Rule 3: Bounded, stable, paginated output

Any tool that can return many items needs a bound. Give it a limit parameter with a modest default and a hard maximum (for example 20 and 50), and return a cursor when more items exist, together with a short note such as "Showing 20 issues. More match: call again with cursor=next_cursor." The note matters: without it the model may assume it has seen everything.

Pagination is only reliable over a deterministic order. Sort by a key that is unique and does not change while the agent reads, such as the issue number, and make the cursor mean "continue after key X" (keyset pagination). Sorting by "last updated" and paging by offset breaks as soon as data changes between calls. The script below shows the failure with ten issues, three per page, while someone updates issue 2 after the first page.

Python · paging_demo.py
"""Why the order behind a cursor must be stable (stdlib only)."""
issues = [{"number": n, "updated": n} for n in range(1, 11)]  # ten issues


def page_by_offset(offset: int, size: int) -> list[int]:
    """Newest-updated first, page N = rows [offset, offset + size)."""
    rows = sorted(issues, key=lambda i: i["updated"], reverse=True)
    return [i["number"] for i in rows[offset:offset + size]]


def page_by_key(after: int, size: int) -> list[int]:
    """Ordered by number, page = the next `size` numbers after the cursor."""
    rows = sorted(i["number"] for i in issues)
    return [n for n in rows if n > after][:size]


def walk(fetch, start) -> list[int]:
    seen, cursor = [], start
    for step in range(4):
        page = fetch(cursor, 3)
        if not page:
            break
        seen += page
        cursor = cursor + 3 if fetch is page_by_offset else page[-1]
        if step == 0:  # someone comments on issue 2 while the agent reads
            issues[1]["updated"] = 99
    return seen


print("offset:", walk(page_by_offset, 0))
issues[1]["updated"] = 2  # reset the data
print("keyset:", walk(page_by_key, 0))
Terminal
python3 paging_demo.py
Expected output
offset: [10, 9, 8, 8, 7, 6, 5, 4, 3, 1]
keyset: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

With offsets, issue 8 appears twice and issue 2 never appears: the update moved issue 2 to the front, so every later row shifted by one. With a keyset cursor over a stable key, each of the ten issues appears exactly once in this run. A keyset walk can still miss an item inserted behind the cursor while the agent reads, so say in the note that the list reflects the data at the time of each call.

Three more details make cursors robust. Treat the cursor as opaque: encode it (for example base64 of a small JSON object) so callers are not meant to build or edit it, and you stay free to change what it holds. Base64 is not secret: anyone can decode and alter it, so validate every cursor you receive, and sign it (for example with an HMAC over its contents) if tampering must be detectable. Tie it to the filters it was created with, and reject a cursor reused with different filters. Answer a malformed or stale cursor with a tool error that says to start again without one.

MCP itself uses the same pattern for its list methods. tools/list, resources/list, resources/templates/list and prompts/list return nextCursor when more items exist, and the client passes it back as cursor. Revision 2026-07-28 also asks servers to return tools/list in a deterministic order, so clients can cache the list and model prompt caches keep hitting.

05. Rule 4: Descriptions and parameters are the manual

The model learns your tools only from their names, descriptions and schemas. Write each description for a capable newcomer:

  • what the tool does and when to use it, and which other tool to use instead when it is the wrong one;
  • what the result contains and how it is bounded ("at most limit issues, ordered by number");
  • the format of awkward inputs (dates, identifiers) and what happens on bad input.

Prefer constrained types to prose: an enum such as Literal["open", "closed"], numeric bounds, and sensible defaults stop invalid calls before they happen. Use clear verb-object names (search_issues, not issues2), and avoid two tools whose descriptions overlap. When a host combines several servers, tool names can collide, so a consistent prefix such as tracker_ helps. Finally, test descriptions with the model you will use: run realistic requests and read the transcripts, because wording that seems obvious to you can still mislead it.

06. Check your understanding

Practice check · 3 questions

Designing tools for agents

Apply the four rules to these situations.

Q1. To save context, a teammate trims `get_customer` down to name, plan and status. The agent can no longer complete "upgrade this customer". Why?
Q2. Why should `search_orders` hand out its cursor as an opaque encoded string rather than a plain page number such as `3`?
Q3. A host asks the user before any tool call that may write. A server from an unvetted vendor marks its `sync_branches` tool with `readOnlyHint: true`. Should the host skip the question for that tool?
Practice only: not graded, not saved, not evidence.

07. Apply it

For the skill project, write a one-page design for an issue-tracker server with four task-level tools before you code. For each tool give its name, a description written for the model, its parameters with types, defaults and limits, the fields it returns (mark the identifiers a follow-up call needs), its sort key and cursor if it returns lists, and two error messages with the next step for each. Then check the design against the four rules and change anything that mirrors an endpoint rather than a task. Lesson 3 builds three of these tools against a mock REST API.

08. Review prompt

From memory, list the four rules in this lesson and give one concrete example of each from an issue tracker. Then explain why offset pagination over "last updated" order skips and repeats items, what makes a good cursor, and which identifiers a concise result must keep.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check