Skip to content
Cloudflare Docs

Tools

Model Context Protocol (MCP) tools are functions that a MCP Server provides and MCP clients can call.

When you build MCP Servers with the @cloudflare/model-context-protocol package, you can define tools using the @modelcontextprotocol/typescript-sdk package.

For example, the following code defines a simple MCP server that adds two numbers together:

src/index.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
import { DurableMCP } from "@cloudflare/model-context-protocol";
export class MyMCP extends DurableMCP {
server = new McpServer({ name: "Demo", version: "1.0.0" });
async init() {
this.server.tool(
"add",
{ a: z.number(), b: z.number() },
async ({ a, b }) => ({
content: [{ type: "text", text: String(a + b) }],
}),
);
}
}