fastmcp
A TypeScript framework for building MCP servers.
claude mcp add --transport stdio punkpeye-fastmcp npx -y fastmcp \ --env MCP_DEBUG="Enable debug logging (optional)"
How to use
FastMCP is a TypeScript framework for building MCP servers. It provides a structured way to define tools, resources, prompts, and routes, with built-in support for authentication, context headers, session tracking, media content, streaming, and various transport options. The framework aims to reduce boilerplate and provide intuitive APIs for common MCP tasks like defining prompts, resources, and server behavior, while still letting you customize error handling, HTTP routes, and streaming behavior. With FastMCP you can build an MCP server that supports HTTP streaming (and SSE), HTTPS, custom routes for REST APIs or admin interfaces, and edge-runtime compatible deployments.
To use it, install the package, create and configure a FastMCP instance, and start the server with a chosen transport (for example stdio for local testing or HTTP streaming for remote clients). The README includes examples of adding tools, starting the server with different transport types, and testing via the MCP CLI or inspector tooling. You can also run HTTP streaming and SSE transports, or configure HTTPS by supplying SSL certificate options. The included showcase demonstrates how to add a simple calculation tool and run the server, while the library handles the MCP protocol specifics for you.
In practice, you typically create a server instance, register tools (each with parameters and an execute function), and then start the server with a transport type such as stdio, HTTP streaming, or a custom transport. For remote clients, you can connect via HTTP streaming or SSE transports, and for secure deployments you can enable HTTPS by providing certificates. The framework also supports prompts, resource embedding, progress notifications, and typed server events, making it straightforward to deliver rich MCP experiences.
How to install
Prerequisites:
- Node.js (14.x or newer) and npm/yarn/pnpm
- Basic familiarity with TypeScript/JavaScript project setup
Installation steps:
- Create a new project folder and initialize a Node.js project (skip if adding to an existing project):
mkdir my-fastmcp-server
cd my-fastmcp-server
npm init -y
- Install FastMCP from npm:
npm install fastmcp
- Create a basic server file (e.g., src/server.ts) to initialize FastMCP and start with a sample transport:
import { FastMCP } from "fastmcp";
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
});
// Example: add a simple tool (optional)
// server.addTool({ name: "echo", description: "Echo input", parameters: z.object({ text: z.string() }), execute: async (args) => args.text });
server.start({ transportType: "stdio" });
- Run the server (adjust to your build setup if using TypeScript compilation):
# If using plain ts-node or a build step, run accordingly. Example with ts-node:
npx ts-node src/server.ts
- Optional: build and test with the MCP CLI as shown in the README:
git clone https://github.com/punkpeye/fastmcp.git
cd fastmcp
npm install
npm run build
# Test the addition server example:
npx fastmcp dev src/examples/addition.ts
npx fastmcp inspect src/examples/addition.ts
Additional notes
Tips and common considerations:
- The default transport for local testing is stdio. For remote usage, consider httpStream or SSE transports and configure ports and endpoints accordingly.
- HTTPS support requires SSL certificates; you can provide sslCert, sslKey, and optional sslCa when starting the HTTP streaming server.
- If you plan to run on Cloudflare Workers, Deno Deploy, or other edge runtimes, ensure compatibility with the Edge Runtime support notes in the README.
- Environment variables can be used to toggle debug modes or pass sensitive configuration at runtime; keep secrets out of source control and consider using a secret manager in production.
- The framework emphasizes reducing boilerplate. Leverage built-in error handling, typed server events, and resource embedding to build feature-rich MCP servers quickly.
Related MCP Servers
Security-Detections
MCP to help Defenders Detection Engineer Harder and Smarter
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
mcp-container-ts
This is a quick start guide that provides the basic building blocks to set up a remote Model Context Protocol (MCP) server using Azure Container Apps. The MCP server is built using Node.js and TypeScript, and it can be used to run various tools and services in a serverless environment.
bc-webclient
MCP server for Microsoft Dynamics 365 Business Central via reverse-engineered WebUI protocol. Enables AI assistants like Claude to interact with BC through the native WebSocket interface.
mcp-bundler
Is the MCP configuration too complicated? You can easily share your own simplified setup!