$git clone https://github.com/punkpeye/fastmcpA TypeScript framework for building MCP servers capable of handling client sessions.
| 1 | # FastMCP |
| 2 | |
| 3 | A TypeScript framework for building [MCP](https://glama.ai/mcp) servers capable of handling client sessions. |
| 4 | |
| 5 | > [!NOTE] |
| 6 | > |
| 7 | > For a Python implementation, see [FastMCP](https://github.com/jlowin/fastmcp). |
| 8 | |
| 9 | ## Features |
| 10 | |
| 11 | - Simple Tool, Resource, Prompt definition |
| 12 | - [Authentication](#authentication) |
| 13 | - [Passing headers through context](#passing-headers-through-context) |
| 14 | - [Session ID and Request ID tracking](#session-id-and-request-id-tracking) |
| 15 | - [Sessions](#sessions) |
| 16 | - [Image content](#returning-an-image) |
| 17 | - [Audio content](#returning-an-audio) |
| 18 | - [Embedded](#embedded-resources) |
| 19 | - [Logging](#logging) |
| 20 | - [Error handling](#errors) |
| 21 | - [HTTP Streaming](#http-streaming) (with SSE compatibility) |
| 22 | - [HTTPS Support](#https-support) for secure connections |
| 23 | - [Custom HTTP routes](#custom-http-routes) for REST APIs, webhooks, and admin interfaces |
| 24 | - [Edge Runtime Support](#edge-runtime-support) for Cloudflare Workers, Deno Deploy, and more |
| 25 | - [Stateless mode](#stateless-mode) for serverless deployments |
| 26 | - CORS (enabled by default) |
| 27 | - [Progress notifications](#progress) |
| 28 | - [Streaming output](#streaming-output) |
| 29 | - [Typed server events](#typed-server-events) |
| 30 | - [Prompt argument auto-completion](#prompt-argument-auto-completion) |
| 31 | - [Sampling](#requestsampling) |
| 32 | - [Elicitation](#elicitation) |
| 33 | - [Configurable ping behavior](#configurable-ping-behavior) |
| 34 | - [Health-check endpoint](#health-check-endpoint) |
| 35 | - [Roots](#roots-management) |
| 36 | - CLI for [testing](#test-with-mcp-cli) and [debugging](#inspect-with-mcp-inspector) |
| 37 | |
| 38 | ## When to use FastMCP over the official SDK? |
| 39 | |
| 40 | FastMCP is built on top of the official SDK. |
| 41 | |
| 42 | The official SDK provides foundational blocks for building MCPs, but leaves many implementation details to you: |
| 43 | |
| 44 | - [Initiating and configuring](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L664-L744) all the server components |
| 45 | - [Handling of connections](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L760-L850) |
| 46 | - [Handling of tools](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L1303-L1498) |
| 47 | - [Handling of responses](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L989-L1060) |
| 48 | - [Handling of resources](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L1151-L1242) |
| 49 | - Adding [prompts](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L760-L850), [resources](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L960-L962), [resource templates](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L964-L987) |
| 50 | - Embedding [resources](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L1569-L1643), [image](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L51-L111) and [audio](https://github.com/punkpeye/fastmcp/blob/06c2af7a3d7e3d8c638deac1964ce269ce8e518b/src/FastMCP.ts#L113-L173) content blocks |
| 51 | |
| 52 | FastMCP eliminates this complexity by providing an opinionated framework that: |
| 53 | |
| 54 | - Handles all the boilerplate automatically |
| 55 | - Provides simple, intuitive APIs for common tasks |
| 56 | - Includes built-in best practices and error handling |
| 57 | - Lets you focus on your MCP's core functionality |
| 58 | |
| 59 | **When to choose FastMCP:** You want to build MCP servers quickly without dealing with low-level implementation details. |
| 60 | |
| 61 | **When to use the official SDK:** You need maximum control or have specific architectural requirements. In this case, we encourage referencing FastMCP's implementation to avoid common pitfalls. |
| 62 | |
| 63 | ## Installation |
| 64 | |
| 65 | ```bash |
| 66 | npm install fastmcp |
| 67 | ``` |
| 68 | |
| 69 | ## Quickstart |
| 70 | |
| 71 | > [!NOTE] |
| 72 | > |
| 73 | > There are many real-world examples of using FastMCP in the wild. See the [Showcase](#showcase) for examples. |
| 74 | |
| 75 | ```ts |
| 76 | import { FastMCP } fro |