Defining Tool Schemas — Tools & Functions
← Back to Dashboard
1. Server Initialization2. Defining Tool Schemas3. Tool Execution & Errors
Defining Tool Schemas
Tools Give AI Hands
Tools are functions the AI can call to fetch data or mutate state. They are the most powerful part of MCP.
Registering a Tool with registerTool & Zod
Modern MCP TypeScript SDKs use server.registerTool() (which replaced the deprecated v1 server.tool() shorthand) and support Standard Schema libraries like zod, Valibot, or ArkType, compiling schemas to JSON Schema 2020-12.
import { z } from "zod";
server.registerTool(
"calculate_tax",
{
title: "Sales Tax Calculator",
description: "Calculate sales tax for a given purchase amount",
inputSchema: z.object({
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 calculated for $${amount} in ${param_state}` }] };
}
);
🎯 Pro Tip: The LLM reads the description of the tool and the descriptions of every parameter. The clearer your Zod
.describe() annotations, the better the AI performs!⌨ HANDS-ON LABValidate Tool Schemas via Inspector CLI
⭐ +150 XPInspect tool definitions returned by tools/list and verify parameters conform to JSON Schema.
1Run inspector in CLI mode to list tools of server-sqlite.
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
What are MCP Tools used for?
Compressing text data
Allowing the AI to fetch dynamic data or mutate external state
Styling user interfaces
Encrypting database passwords