About
Fastify Mcp — Model Context Protocol server
README
Integrate Model Context Protocol servers with your Fastify app.
Supports the Streamable HTTP transport as well as the legacy HTTP+SSE transport.
Usage
First, define your MCP server.
function createServer() {
const mcpServer = new McpServer({
name: "...",
version: "...",
});
mcpServer.tool("...");
mcpServer.resource("...");
return mcpServer.server;
}
Create a Fastify app and register the plugin.
import { fastify } from "fastify";
import { streamableHttp } from "fastify-mcp";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
const app = fastify();
app.register(streamableHttp, {
// Set to `true` if you want a stateful server
stateful: false,
mcpEndpoint: "/mcp",
sessions: new Sessions<StreamableHTTPServerTransport>()
createServer,
});
app.listen({ port: 8080 });
See the examples directory for more detailed examples.
Installation
# npm
npm install fastify-mcp
# yarn
yarn add fastify-mcp
Session Management
The official MCP TypeScript SDK does not support managing multiple sessions out of the box, and therefore it's the host server's responsibility to do so.
This package uses an in-memory mapping of each active session against its session ID to manage multiple sessions, as recommended by the MCP SDK examples.
Session Events
The Sessions class emits the following events:
connected: Emitted when a new session is added.terminated: Emitted when a session is removed.error: Emitted when an asynchronous event handler throws an error.
const sessions = new Sessions<StreamableHTTPServerTransport>();
sessions.on("connected", (sessionId) => {
console.log(`Session ${sessionId} connected`);
});
sessions.on("terminated", (sessionId) => {
console.log(`Session ${sessionId} terminated`);
});
Contributing
Please file an issue if you encounter a problem when using this package. Pull requests for new features or bug fixes are also welcome.
Install Fastify Mcp in Claude Desktop, Claude Code & Cursor
unyly install fastify-mcpInstalls into Claude Desktop, Claude Code, Cursor & VS Code — handles npx, uvx and build-from-source repos for you.
First time? Get the CLI: curl -fsSL https://unyly.org/install | sh
Or configure manually
Run in your terminal:
claude mcp add fastify-mcp -- npx -y fastify-mcpFAQ
Is Fastify Mcp MCP free?
Yes, Fastify Mcp MCP is free — one-click install via Unyly at no cost.
Does Fastify Mcp need an API key?
No, Fastify Mcp runs without API keys or environment variables.
Is Fastify Mcp hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Fastify Mcp in Claude Desktop, Claude Code or Cursor?
Open Fastify Mcp on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
Fetch
Web content fetching and conversion for efficient LLM usage.
AWS KB Retrieval
Retrieval from AWS Knowledge Base using Bedrock Agent Runtime.
by modelcontextprotocolSpring AI MCP Server
Provides auto-configuration for setting up an MCP server in Spring Boot applications.
llm-analysis-assistant
A very streamlined mcp client that supports calling and monitoring stdio/sse/streamableHttp, and can also view request responses through the /logs page. It also
by xuzexin-hzCompare Fastify Mcp with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All ai MCPs
