AI Agents Engineering · Model Context Protocol · Lesson 3 of 3
Building an MCP server
Anthropic FDE and agent-engineer interviews literally ask candidates to build an MCP server. The shape is small: declare a server, register tools/resources/prompts, and run a transport. Here is the essence with the Python SDK.
from mcp.server.fastmcp import FastMCP mcp = FastMCP("orders") @mcp.tool() def get_order_status(order_id: str) -> str: """Look up the status of a customer order by id.""" return lookup(order_id) # your real logic @mcp.resource("orders://recent") def recent_orders() -> str: """Recent orders as context.""" return format_recent() if __name__ == "__main__": mcp.run(transport="stdio") # or "streamable-http" for remote
- The SDK turns typed function signatures + docstrings into the JSON schema + description the model sees — so name and document them well.
- Test locally with the MCP Inspector, then point a client (Claude Desktop/Code, your agent) at it.
- For production: pick streamable HTTP, add auth, apply least-privilege, and log every call.
- Don't load every tool into context: tool definitions at scale blow the attention budget — use progressive disclosure / tool search, loading definitions on demand.
- Code mode: for tool-heavy work, let the model write code that calls MCP tools in a sandbox, so only final results enter context — order-of-magnitude token savings.
- Tool poisoning: malicious tool names/descriptions/results are an injection vector — vet and pin servers, and review tool metadata like third-party code.
The whiteboard answerIf asked to build one: 'Declare a server, register a tool with a typed signature and docstring so the SDK generates the schema, run it over stdio for local or streamable HTTP for remote, and enforce auth + least privilege in the tool body.' That is a complete answer.
◆ Lock it in
- An MCP server = declare server → register tools/resources/prompts → run a transport.
- Typed signatures + docstrings become the schema + description the model sees.
- Test with the Inspector; for prod use streamable HTTP with auth + least privilege.
Feynman drill — say it out loudSketch the minimal code and steps to expose one tool as an MCP server.
Step 1 rate your confidence · Step 2 pick your answer
In a typical MCP SDK, where does the tool's JSON schema and description come from?
Step 1 — how sure are you?