convez.ai
MCP ServerIntegração & APIsIntermediário
haroldadmin

Fastify MCP

haroldadmin/fastify-mcp

Integre servidores MCP em Fastify com suporte a múltiplas sessões

Ver no GitHub
BomPluginScore · de 0 a 100

Plugin Fastify para integrar servidores Model Context Protocol (MCP) diretamente em aplicações Fastify. Suporta os transportes HTTP Streamable e HTTP+SSE legado, com gerenciamento automático de sessões múltiplas.

Instalação

$npx convez-ai haroldadmin/fastify-mcp

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
27
Forks
8
Acompanhando
1
Saúde
42%
Último commit
há 6 meses
Versão
3.0.0
Issues abertas
4
Contribuidores
2

Casos de uso

  • Expor ferramentas e recursos MCP via HTTP em aplicações Fastify
  • Implementar servidores MCP stateful ou stateless em produção
  • Gerenciar múltiplas sessões MCP concorrentes
  • Integrar LLMs com capacidades MCP em plataformas web

Veredito

Solução prática e bem estruturada para quem precisa expor servidores MCP em produção via Fastify. Resolve o problema real de gerenciamento de sessões que o SDK oficial não endereça nativamente, com suporte a múltiplos transportes.

README

A tradução para o português deste README ainda está na fila.

fastify-mcp

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.

Ver o original no GitHub

Bom para

Relacionados