@mcp-it/fastify
🤖 Automatically generate MCP tools from your Fastify API routes.
A Fastify plugin (@mcp-it/fastify
) for the Model Context Protocol (MCP) that allows you to expose your Fastify routes as MCP tools. This enables AI assistants to interact with your API directly through the MCP protocol.
Overview
This plugin automatically discovers your Fastify routes and exposes them as tools consumable by MCP clients like Cursor or Claude. It leverages Fastify's schema system to generate complete tool definitions.
Note
While this package focuses specifically on Fastify, the @mcp-it
scope may host adapters for other Node.js frameworks (like Express, NestJS, etc.) in the future.
Installation
Usage
Features
- Automatic Route Discovery: Utilizes Fastify hooks to identify all registered routes.
- Schema Utilization: Employs Fastify route schemas for comprehensive tool generation.
- Per-Route Configurations: Allows customization on a per-route basis.
- Multiple Transports: Supports both Server-Sent Events and Streamable HTTP transports.
- Debug Endpoint: An optional endpoint to view generated tools, independent of transport.
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
name | string | "Fastify MCP" | Name for the MCP server displayed to the client. |
description | string | "MCP server for Fastify" | Description for the MCP server. |
transportType | string | "sse" | Transport protocol to use: "sse" or "streamableHttp" . |
describeFullSchema | boolean | false | Include detailed input/output schemas and examples in descriptions. |
skipHeadRoutes | boolean | true | Exclude HEAD routes from the generated MCP tools. |
skipOptionsRoutes | boolean | true | Exclude OPTIONS routes from the generated MCP tools. |
mountPath | string | "/mcp" | Base path prefix where MCP SSE and message endpoints are mounted. |
filter | Function | undefined | Custom function (route: Route) => boolean for filtering. |
addDebugEndpoint | boolean | false | Add a GET /<mountPath>/tools endpoint listing generated tools. |
Route Configuration (config.mcp
)
You can add specific MCP configurations directly within a route's config
object. The following options are available:
Option | Type | Default | Description |
---|---|---|---|
hidden | boolean | false | Hide this route from the MCP Server |
name | string | operationId or method_url | Override the default tool name |
description | string | Route's schema description | Override the tool description |
Example usage:
Accessing the MCP Server Instance
This plugin decorates the Fastify instance with the underlying MCP Server
instance from @modelcontextprotocol/sdk
. You can access it via fastify.mcpServer
after the plugin has been registered.
This might be useful for advanced scenarios, such as:
- Directly interacting with the MCP server's lifecycle or methods.
- Adding custom request handlers or capabilities beyond basic tool exposure.
Examples
See the examples directory for complete working examples demonstrating various features.
Client Configuration
Cursor
In Cursor settings (Settings -> MCP), add a new SSE connection with the URL:
(Replace localhost:3000
with your server's address and mcp
with your mountPath
if customized).
Claude Desktop
Use mcp-proxy to bridge between Claude Desktop (which expects stdio) and the SSE endpoint.
Add the following to your Claude Desktop MCP config file (claude_desktop_config.json
):
(Replace localhost:3000
with your server's address and mcp
with your mountPath
if customized).
Alternatively, you can use the Streamable HTTP endpoint if your client supports it (Cursor might require configuration or proxying for non-SSE endpoints).
This server cannot be installed
A Fastify plugin that automatically converts API routes into Model Context Protocol tools, enabling AI assistants to directly interact with your API.