Skip to content

Tools

A tool is an action a connected client — and the model driving it — can invoke on your server.

defineTool takes a name, description, a schema and a handler. input is a Zod Schema.

src/mcp.ts
import { z } from "zod";
import { defineTool } from "@mcpexpress/core";
export const getWeather = defineTool({
name: "get_weather",
description: "Current weather for a city",
input: z.object({ city: z.string() }),
execute: async ({ city }, { signal }) => `It is sunny in ${city}`,
});

Based on the above definition, MCP Express takes the tool and advertises a get_weather tool with the provided input schema of city.