Add two numbers
FastMCP is a robust TypeScript framework designed for building Model Context Protocol (MCP) servers with client session handling capabilities. It provides a streamlined approach to defining tools, resources, and prompts while offering comprehensive features like authentication, session management, and support for various content types including images and audio. With built-in error handling, logging, and multiple transport options, FastMCP simplifies the development of MCP servers for AI applications.
FastMCP is a TypeScript framework that makes it easy to build Model Context Protocol (MCP) servers. It provides a clean, type-safe API for defining tools that can be used by AI models to interact with your application.
You can install FastMCP using npm, yarn, or pnpm:
npm install fastmcp
# or
yarn add fastmcp
# or
pnpm add fastmcp
Creating a simple MCP server with FastMCP is straightforward:
import { FastMCP } from "fastmcp";
import { z } from "zod"; // Or any validation library that supports Standard Schema
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
});
server.addTool({
name: "add",
description: "Add two numbers",
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return String(args.a + args.b);
},
});
server.start({
transportType: "stdio",
});
FastMCP supports multiple transport types:
server.start({
transportType: "sse",
sse: {
endpoint: "/sse",
port: 8080,
},
});
server.start({
transportType: "httpStream",
httpStream: {
endpoint: "/stream",
port: 8080,
},
});
FastMCP includes many advanced features:
FastMCP provides CLI tools for testing and debugging your MCP servers:
# Test a server using CLI
npx fastmcp dev path/to/server.ts
# Debug a server using MCP Inspector
npx fastmcp inspect path/to/server.ts
FastMCP supports multiple schema validation libraries through the Standard Schema specification:
Choose the one that best fits your project's needs.