Tools are functions the AI can call to fetch data or mutate state. They are the most powerful part of MCP.
The TypeScript SDK highly recommends using the zod library for argument validation.
import { z } from "zod";
server.tool(
"calculate_tax",
"Calculate sales tax for a given purchase amount",
{
amount: z.number().describe("The total purchase amount"),
param_state: z.string().describe("Two-letter state code")
},
async ({ amount, param_state }) => {
return { content: [{ type: "text", text: `Tax is high in ${param_state}` }] };
}
);