Back to course

Implementing Tools: Writing Data & Side Effects

Model Context Protocol (MCP) Server Engineering

Introduction to Tools

Tools are the most powerful part of MCP. They allow the AI to perform actions.

Defining a Tool

Tools use Zod for schema validation.

typescript server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [{ name: "calculate_sum", description: "Adds two numbers together", inputSchema: { type: "object", properties: { a: { type: "number" }, b: { type: "number" } }, required: ["a", "b"] } }] }));

Assignment: Define a tool named echo that takes a string and returns it.