MCP server
The Model Context Protocol lets an agent discover and call your tools and
read your resources. The server is a contract with a caller that reasons in
natural language and will misuse anything ambiguous, so design for a smart
caller that cannot see your source.
Method
- Expose the right primitive. MCP offers tools (actions the agent
invokes), resources (data the agent reads), and prompts (templates the
agent fills). Read-only data is a resource, not a tool; an action with
effects is a tool. Choosing wrong makes the agent fetch data by calling
side-effecting tools, or take actions it thinks are safe reads.
- Name and describe for the model, not the maintainer. Every tool's name
and description is how the agent decides whether and how to call it. Say
what it does, when to use it, and what it returns, in one clear statement.
A vague description produces wrong calls no schema can prevent.
- Make schemas strict and self-documenting. Each parameter has a type, a
description, and required-or-optional stated. Constrain enums, ranges, and
formats so the model cannot pass a shape you will reject. Invalid states
the schema forbids are calls you never have to handle.
- Return results the model can use. Structured, labeled output over raw
dumps; the fields the agent needs to decide the next step, not your
internal representation. Truncate or paginate large results so one call
cannot blow the context window.
- Errors are part of the contract. A failed call returns a clear,
actionable message the agent can recover from ("file not found: check the
path" beats a stack trace). Distinguish the agent's mistake from a server
failure so the agent knows whether to retry, fix its input, or give up.
- Guard every boundary, because the caller is not trusted. Validate and
sanitize all inputs; scope what each tool can touch; never expose a tool
that runs arbitrary commands, reads arbitrary paths, or leaks secrets.
Treat tool arguments as hostile input reaching a privileged operation,
because that is exactly what they are.
- Keep tools small and composable. One tool, one job, with a name that
says it. A mega-tool with a mode parameter is harder for the agent to use
correctly than three focused tools.
Litmus tests
- Could the agent use every tool correctly from its name, description, and
schema alone, with no access to your code?
- Can any tool call cause damage the caller did not clearly intend?
- Does every error tell the agent what to do next?
- Could a single response overflow the context window?
Boundaries
Follow the MCP specification and your SDK's conventions; a server that
diverges from the protocol is a server clients cannot use. Expose the
smallest surface that serves the need. Every tool is attack surface and
context cost, so a tool that is rarely useful is a net loss.
1---2name: mcp-server3description: Design a Model Context Protocol server that exposes tools and data to AI agents safely and legibly. Use when building an MCP server or deciding what to expose to an agent.4---56# MCP server78The Model Context Protocol lets an agent discover and call your tools and9read your resources. The server is a contract with a caller that reasons in10natural language and will misuse anything ambiguous, so design for a smart11caller that cannot see your source.1213## Method14151. **Expose the right primitive.** MCP offers tools (actions the agent16 invokes), resources (data the agent reads), and prompts (templates the17 agent fills). Read-only data is a resource, not a tool; an action with18 effects is a tool. Choosing wrong makes the agent fetch data by calling19 side-effecting tools, or take actions it thinks are safe reads.202. **Name and describe for the model, not the maintainer.** Every tool's name21 and description is how the agent decides whether and how to call it. Say22 what it does, when to use it, and what it returns, in one clear statement.23 A vague description produces wrong calls no schema can prevent.243. **Make schemas strict and self-documenting.** Each parameter has a type, a25 description, and required-or-optional stated. Constrain enums, ranges, and26 formats so the model cannot pass a shape you will reject. Invalid states27 the schema forbids are calls you never have to handle.284. **Return results the model can use.** Structured, labeled output over raw29 dumps; the fields the agent needs to decide the next step, not your30 internal representation. Truncate or paginate large results so one call31 cannot blow the context window.325. **Errors are part of the contract.** A failed call returns a clear,33 actionable message the agent can recover from ("file not found: check the34 path" beats a stack trace). Distinguish the agent's mistake from a server35 failure so the agent knows whether to retry, fix its input, or give up.366. **Guard every boundary, because the caller is not trusted.** Validate and37 sanitize all inputs; scope what each tool can touch; never expose a tool38 that runs arbitrary commands, reads arbitrary paths, or leaks secrets.39 Treat tool arguments as hostile input reaching a privileged operation,40 because that is exactly what they are.417. **Keep tools small and composable.** One tool, one job, with a name that42 says it. A mega-tool with a mode parameter is harder for the agent to use43 correctly than three focused tools.4445## Litmus tests4647- Could the agent use every tool correctly from its name, description, and48 schema alone, with no access to your code?49- Can any tool call cause damage the caller did not clearly intend?50- Does every error tell the agent what to do next?51- Could a single response overflow the context window?5253## Boundaries5455Follow the MCP specification and your SDK's conventions; a server that56diverges from the protocol is a server clients cannot use. Expose the57smallest surface that serves the need. Every tool is attack surface and58context cost, so a tool that is rarely useful is a net loss.