Muhammad Fari Madyan
Hire me
MCP Server · part 2 of 6

Building a Remote MCP Server on GCP Part 2: Designing Tools for a Model — Descriptions, Schemas, Structured Output & Annotations

Part two of a Building a Remote MCP Server on GCP series that opens with a quiz: five tools with one job each, descriptions as prompts, input schemas with enums from real data, isError results that name the next step, structuredContent next to text, readOnlyHint changing the UI in Claude, and 7,693 bytes of tool definitions.

Muhammad Fari Madyan

· 13 min read

Baca dalam Bahasa Indonesia →

Opening: An API Whose User Cannot Read the Docs

When I build a REST API, the user is a programmer. They read the documentation, try a request in Postman, read the error, and fix their code. If my endpoint is called getData, they will figure it out.

An MCP tool has a different user: a model. The model never sees my README, never sees my code, and cannot ask me a question. All it gets is what tools/list returns: a name, a description, an input schema, and maybe an output schema and some annotations. Based on that alone, it has to decide whether to call the tool, with what arguments, and what to do when the answer is bad.

Part 1 covered how messages travel. This part covers the harder question: how to design tools that a model uses well. Every example comes from the five tools of my blog server.


Warm-Up Quiz: Do You Still Remember?

Answer first. All correct? Jump to the Summary. Missed one? Let's refresh the material.

Question 1. A model calls search_content with limit: 50, while the schema allows at most 10. What should the model receive?

  • A. An HTTP 500
  • B. A tool result with isError: true and a message that says which argument is wrong
  • C. Fifty results anyway
Show the answer to question 1

B. A tool error should come back as a result the model can read, so it can fix the argument and try again. My server's real answer is in Section 4.

Question 2. Why does a tool result carry both content (text) and structuredContent (JSON)?

  • A. Backward compatibility only, one of them is ignored
  • B. Text is for the model to read, JSON matches the output schema so programs and clients can use it reliably
  • C. JSON is for the model, text is for logs
Show the answer to question 2

B. The model reads text well. Code reads JSON well. A tool with an outputSchema returns both, and the text should say the same thing as the JSON.

Question 3. What happens when a tool has readOnlyHint: false?

  • A. The tool cannot be called
  • B. Clients can treat it as a tool with side effects, for example by asking the user for approval before each call
  • C. The server refuses to run it
Show the answer to question 3

B. In Claude, my send_event tool was listed under write tools and needed approval. Annotations are hints for the client, not a security mechanism. Section 6 shows what it looked like.

Question 4. Why should the series argument be an enum built from the data instead of a free string?

  • A. Enums are faster to parse
  • B. The model sees the valid values in the schema and does not have to guess a key like gcp vs gcp-backend
  • C. JSON Schema does not support strings
Show the answer to question 4

B. A free string invites guesses that return zero results with no explanation. An enum moves the list of valid values into the schema, where the model reads it before calling.

Question 5. My tools/list answer is 7,693 bytes. Why does that matter?

  • A. It does not, bytes are cheap
  • B. Tool definitions are usually given to the model as context, so every extra word costs tokens in every conversation that has the connector on
  • C. Load balancers reject responses above 8 KB
Show the answer to question 5

B. Long descriptions are not free. They should be as long as needed to choose and call the tool correctly, and no longer.


1. Five Tools, One Job Each

I started from the questions I wanted Claude to answer, not from my data model:

Question from a userToolWhy a separate tool
"Which of your articles explains X?"search_contentShort results, so the model can scan many cheaply
"Summarize that article"get_articleThe full text, only when the model has picked one
"What should I read after this?"more_like_thisNeeds an article as input, not keywords
"What series do you have?"list_seriesBrowsing instead of searching, and the source of valid filter keys
(after answering)send_eventFeedback on whether a result helped

Two rules guided the split:

  • Search returns short, read returns long. search_content returns a title, a URL and a 240-character excerpt per article. The model can compare five results for a few hundred tokens, then call get_article on the one that fits. One "search and return everything" tool would put five full articles into the context to use one.
  • Every tool name is a verb plus an object. search_content, get_article, list_series. A model, like a person, guesses a tool's job from its name first.

2. The Description Is a Prompt

This is the real description of my search tool:

TS
description:
  "Full-text search over mfarim.com blog articles. Typo tolerant for longer words. Returns ranked articles with title, URL, short description, series and topics. Use short keyword queries (e.g. 'firestore pagination', 'cache stampede'), not whole sentences. Filter by language, series or topic when the user asks for one.",

Every sentence is there for a reason:

SentenceWhat it prevents
"Full-text search over mfarim.com blog articles"The model calling it for questions the blog cannot answer
"Typo tolerant for longer words"The model "correcting" a user's typo badly before searching
"Returns ranked articles with title, URL ..."The model expecting the full article and skipping get_article
"Use short keyword queries ... not whole sentences"Whole questions as queries. My search first requires every word to match (Part 3), and a 15-word question almost never does
"Filter by language, series or topic when the user asks for one"Filters applied when the user never asked, which hides good results

The sentence about short keyword queries came from watching how a model calls a search tool by default: it tends to pass the user's question almost word for word. Telling it what kind of query works is the cheapest relevance fix there is.

The server as a whole also has instructions, sent once in initialize:

TEXT
Use search_content first, then get_article for the full text. Always link the article URL when you use it.

That last sentence matters for a blog: an answer built from my article should send the reader to my article.


3. Input Schemas: Make Wrong Calls Impossible

The input schema is written with zod, and the SDK turns it into JSON Schema for tools/list:

TS
inputSchema: {
  query: z.string().trim().min(1).max(200).describe("Keywords to search for."),
  lang: z.enum(["en", "id", "any"]).default("any").describe("en = English, id = Indonesian, any = both."),
  series: z.enum(seriesKeys).optional().describe("Only articles in this series (see list_series)."),
  topic: z.enum(topicKeys).optional().describe("Only articles about this topic."),
  limit: z.number().int().min(1).max(10).default(5),
  offset: z.number().int().min(0).max(50).default(0).describe("For the next page, pass nextOffset from the previous result."),
},

The principles behind it:

  • Enums from real data. seriesKeys and topicKeys are read from the index at startup. The model sees "gcp-backend", "firestore-cache-search" and the rest in the schema, so it does not invent "gcp". When I add a series, the enum updates itself.
  • Limits everywhere. query at most 200 characters, limit at most 10, offset at most 50. A model will not abuse them on purpose, but a confused loop or a hostile client might.
  • Defaults that fit the common case. lang: "any" and limit: 5. A good default means most calls need only query.
  • describe() on anything that is not obvious. en = English, id = Indonesian looks trivial to me. To a model, id could just as well mean "identifier".

4. Errors the Model Can Recover From

There are two kinds of errors in MCP, and the difference matters:

KindExampleWho sees it
Protocol error (JSON-RPC error)Malformed JSON, unknown methodThe client. The model usually never sees it
Tool error (result with isError: true)Wrong argument, article not foundThe model, which can try again

When the model breaks the schema, the SDK answers with a tool error. This is the real answer for limit: 50:

JSON
{"result":{"content":[{"type":"text","text":"MCP error -32602: Input validation error: Invalid arguments for tool search_content: Too big: expected number to be <=10 at limit"}],"isError":true},"jsonrpc":"2.0","id":3}

The model can read "<=10 at limit" and call again with 10. For errors in my own logic, I write the message myself, and every message says what to do next:

TS
return {
  ...errorResult(
    other
      ? `"${slug}" has no ${lang === "en" ? "English" : "Indonesian"} version. It exists in ${other.lang}: call get_article with lang "${other.lang}".`
      : `No article with slug "${slug}". Use search_content to find the right slug.`,
  ),
  results: 0,
};

"Not found" alone leaves the model stuck. "It exists in Indonesian: call get_article with lang "id"" gives it the exact next call.

The same idea applies to results that are technically fine but weak:

  • Zero results say: No articles matched "...". Try fewer or different keywords, the other language, or list_series to browse.
  • Weak results say so. When no article matches every word, my search falls back to "any word" (Part 3) and the text begins with (no article matched every word; these match some of them). Without that line, the model would present weak matches with full confidence.
  • More results say how to get them: More results: call again with offset 3.

Finally, every handler is wrapped so that an unexpected exception becomes a short tool error and one log line, never a stack trace in the model's context:

TS
} catch (error) {
  log("ERROR", "tool call failed", { tool, ms: Math.round(performance.now() - started), ok: false, error: error instanceof Error ? error.message : String(error), ...fields });
  return errorResult("The server hit an unexpected error. Please try again.");
}

5. Structured Output: Text for the Model, JSON for Code

Each tool declares an outputSchema and returns structuredContent that matches it, next to the text:

TS
outputSchema: {
  query: z.string(),
  total: z.number(),
  matchMode: z.enum(["all", "any"]),
  nextOffset: z.number().nullable(),
  results: z.array(hitSchema),
},
JSON
{"query": "cache stampede", "total": 11, "matchMode": "all", "nextOffset": 3, "results": [{"slug": "gcp-backend-part-6-scale-and-cost", "lang": "id", "title": "GCP untuk Backend Engineer Part 6: ...", "url": "https://www.mfarim.com/blog/id/gcp-backend-part-6-scale-and-cost", ...}]}

Why both:

  • The text is written for reading: a numbered list with the series and part, the URL and a short description. Models handle this kind of text very well.
  • The JSON is a contract. A client, a test, or another program can rely on nextOffset being a number or null, without parsing English sentences.

The rule I follow: the text and the JSON must say the same thing. If the JSON says nextOffset: 3, the text says "call again with offset 3".

get_article shows why structured fields help with long content. It cuts an article at maxChars (default 8,000, between 500 and 30,000) and returns truncated: true plus the article's headings. For my idempotency article, cut at 600 characters, the result had truncated: true and 15 headings. The model can see that "From my own project: CahTix" exists even though that section was cut, and ask for more if the user wants it.


6. Annotations: Hints That Change the UI

Annotations describe how a tool behaves. Four of my tools are pure reads:

TS
annotations: { readOnlyHint: true, openWorldHint: false },

send_event writes something, so it says so:

TS
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },

I did not expect this to be visible, but it was. When I added the server to Claude as a custom connector, the connector settings split the tools into read-only tools and write/delete tools. The four search tools could run freely. send_event showed Needs approval, and in Cowork the "always allow" option was not available for it.

Two lessons from that:

  • Annotations are worth setting correctly. They decide how much friction a tool has. A read tool marked as a write tool would ask for approval on every search.
  • Annotations are hints, not security. A client cannot verify them. A server could lie and mark a destructive tool as read-only. The real protection is what the server allows, not what it claims.

There is also a design lesson in there. send_event was meant to collect feedback ("the user opened result 2", "no result was good"). But a feedback tool that needs approval on every call will rarely be called. The cheaper source of the same signal is something the server already does: it logs every search with its query and result count (Part 4). Zero-result queries show up in the logs without the model doing anything.


7. The Cost of Being Described

Tool definitions are not free. My tools/list answer is 7,693 bytes. Hosts usually pass tool definitions to the model as context, so with the connector on, that text is part of every conversation. At a rough four bytes per token, that is in the order of two thousand tokens.

That pushed me toward a few habits:

  • Describe what the model needs to choose and call the tool. Not how it is implemented.
  • Put examples in the description only when they change behavior. 'firestore pagination', 'cache stampede' stayed because it stops whole-sentence queries.
  • Do not add tools "just in case". Five tools that each do one job are easier for the model to choose between than twelve that overlap.

8. Three Tool Design Traps

Trap one: a description written for programmers. "Searches the index" tells a model almost nothing. Say what is searched, what comes back, what a good query looks like, and when to use filters.

Trap two: throwing instead of returning errors. An exception becomes a protocol error or a generic failure, and the model cannot recover. Return isError: true with the next step in the message.

Trap three: giant results. A tool that returns full articles for every search fills the context with text the model will not use. Return short results, and let a second tool fetch the long one.


Summary

  • The user of a tool is a model. It only sees the name, description, schemas and annotations from tools/list.
  • One job per tool: search returns short results (240-character excerpts), read returns the full article (up to 8,000 characters by default, with truncated and headings).
  • The description is a prompt: what it searches, what it returns, what a good query looks like, when to filter. Server-wide guidance goes in instructions.
  • Input schemas: enums from real data, limits on everything, useful defaults, describe() for anything ambiguous.
  • Errors come back as isError: true results with the next step. Weak, empty and paged results say so in the text.
  • Structured output: text for the model, structuredContent matching outputSchema for code, and both must agree.
  • Annotations change the UI: Claude grouped read-only and write tools, and send_event needed approval. They are hints, not security.
  • Definitions cost context: 7,693 bytes for five tools.

Next

Good tools are only as good as what is behind them. In Part 3, we open up the search engine: how 194 Markdown articles become an in-memory index, why the search tries every word first and then any word, and how I found and measured a real bug in more_like_this, where series templates mattered more than the subject.

ShareLinkedInXWhatsApp

Written by Muhammad Fari Madyan

Senior Backend Engineer and co-founder of LampungDev. I write up what I build so others can learn from it.

Work with me
← part 1MCP Basicspart 3 →The Search Behind the Tool

Muhammad Fari Madyan

Senior Backend Engineer building real-time, high-concurrency systems that hold up in production. Co-founder of LampungDev. Based in Bandar Lampung, Indonesia (UTC+7), working remote.

Work

Case studiesCahTixExam platform, 4 stacksOpen source

© 2026 Muhammad Fari Madyan

Designed and built by Muhammad Fari Madyan