@mcp-it/fastify logo

@mcp-it/fastify

Community
AdirAmsalem

🤖 Automatically generate MCP tools from your Fastify API routes.

PublisherAdirAmsalem
Repositorymcp-it
LanguageTypeScript
Forks
8
Stars
39
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    @mcp-it/fastify exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    39 stars and 8 forks from the linked repository.

@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

bash
npm install @mcp-it/fastify
# or
yarn add @mcp-it/fastify
# or
pnpm add @mcp-it/fastify

Usage

typescript
import Fastify from "fastify";
import mcpPlugin from "@mcp-it/fastify";

const fastify = Fastify();

// Register the MCP plugin
await fastify.register(mcpPlugin, {
  name: "My API",
  description: "My API with MCP support",
});

// Define your routes with schemas and operation IDs
fastify.get(
  "/users/:id",
  {
    schema: {
      operationId: "get_user", // Used as the tool name
      summary: "Get user by ID",
      description: "Returns a user by their ID",
      params: {
        type: "object",
        required: ["id"],
        properties: {
          id: { type: "number", description: "User ID" },
        },
      },
      response: {
        200: {
          description: "Successful response",
          type: "object",
          properties: {
            id: { type: "number" },
            name: { type: "string" },
            email: { type: "string" },
          },
        },
      },
    },
    // Add MCP-specific config if needed, e.g.:
    // config: {
    //   mcp: { hidden: true }
    // }
  },
  async (request) => {
    // Implementation...
    const userId = (request.params as any).id;
    // ... fetch user
    return { id: userId, name: "Example User", email: "user@example.com" };
  }
);

await fastify.listen({ port: 3000 });

console.log("MCP SSE server running at http://localhost:3000/mcp/sse");

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

OptionTypeDefaultDescription
namestring"Fastify MCP"Name for the MCP server displayed to the client.
descriptionstring"MCP server for Fastify"Description for the MCP server.
transportTypestring"sse"Transport protocol to use: "sse" or "streamableHttp".
describeFullSchemabooleanfalseInclude detailed input/output schemas and examples in descriptions.
skipHeadRoutesbooleantrueExclude HEAD routes from the generated MCP tools.
skipOptionsRoutesbooleantrueExclude OPTIONS routes from the generated MCP tools.
mountPathstring"/mcp"Base path prefix where MCP SSE and message endpoints are mounted.
filterFunctionundefinedCustom function (route: Route) => boolean for filtering.
addDebugEndpointbooleanfalseAdd 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:

OptionTypeDefaultDescription
hiddenbooleanfalseHide this route from the MCP Server
namestringoperationId or method_urlOverride the default tool name
descriptionstringRoute's schema descriptionOverride the tool description

Example usage:

typescript
fastify.get(
  "/some-route",
  {
    config: {
      mcp: {
        name: "custom_tool_name", // Override the default tool name
        description: "Custom description for this tool", // Override the default description
      },
    },
    // ... other route options
  },
  async (request, reply) => {
    /* ... */
  }
);

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.
typescript
import Fastify from "fastify";
import mcpPlugin from "@mcp-it/fastify";
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";

const fastify = Fastify();

await fastify.register(mcpPlugin, {
  /* options */
});

// Now you can access the MCP server instance
console.log("MCP Server:", fastify.mcpServer);

// Example: Add a custom handler (use with caution)
// fastify.mcpServer.setRequestHandler(...);

// ... rest of your application setup

await fastify.listen({ port: 3000 });

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:

http://localhost:3000/mcp/sse

(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):

json
{
  "mcpServers": {
    "my-fastify-api": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:3000/mcp/sse"]
    }
  }
}

(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).

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "adiramsalem-mcp-it": {
      "command": "npx",
      "args": [
        "-y",
        "@mcp-it/fastify"
      ]
    }
  }
}

Use @mcp-it/fastify MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once @mcp-it/fastify is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add @mcp-it/fastify as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the @mcp-it/fastify MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "adiramsalem-mcp-it": {
      "command": "npx",
      "args": [
        "-y",
        "@mcp-it/fastify"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the @mcp-it/fastify MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the @mcp-it/fastify MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use @mcp-it/fastify to help me with this task?
@mcp-it/fastify
Sure. I read it.
Here is what I found using @mcp-it/fastify.

Frequently asked questions

What is the @mcp-it/fastify MCP server used for?

@mcp-it/fastify is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use @mcp-it/fastify MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use @mcp-it/fastify with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use @mcp-it/fastify MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With @mcp-it/fastify connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect @mcp-it/fastify MCP to TypingMind?

@mcp-it/fastify runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does @mcp-it/fastify MCP provide in TypingMind?

@mcp-it/fastify exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use @mcp-it/fastify MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If @mcp-it/fastify requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇