PM

platformatic/mcp

分析与监控

本页由 AI 翻译,技术细节请以原文为准。 查看原文

62 stars 16 forks 质量 75 趋势 34Apache-2.0

一个使用 JSON-RPC 2.0 实现模型上下文协议(MCP)服务器的 Fastify 插件。该插件使 Fastify 应用程序能够在 MCP 之后暴露工具、资源和提示符......

概览

一个使用 JSON-RPC 2.0 实现模型上下文协议(MCP)服务器的 Fastify 插件。该插件使 Fastify 应用程序能够按照 MCP 2025-06-18 规范暴露工具、资源和提示,并支持完整的引发功能。 为了类型安全模式验证,安装TypeBox: - : 实现完整的模型上下文协议规范并引出 - : 服务器到客户端信息请求带模式验证 - : 类型安全模式验证及自动 TypeScript 推断 - : 输入清理、速率限制和安全评估 - : HTTP/SSE 和 stdio 传输以实现灵活通信 - : 服务器发送事件实现实时通信 - : Resid 支持会话管理和消息广播 - : 支持消息历史和通过 Last-Event-ID 的重连 - : 本地与分布式存储的无缝切换 - : 全面的测试覆盖、安全功能和认证支持 该插件支持引发功能,...

概述(AI 翻译)

一个使用 JSON-RPC 2.0 实现模型上下文协议(MCP)服务器的 Fastify 插件。该插件使 Fastify 应用程序能够按照 MCP 2025-06-18 规范暴露工具、资源和提示,并支持完整的引发功能。

安装

TypeBox 支持(可选)

为了类型安全模式验证,安装TypeBox:

特色

  • 完整MCP 2025-11-25支持:实现当前模型上下文协议修订版,针对较旧客户端可协商至2025-06-18、2025-03-26和2024-11-05。
  • 任务(实验):任务增强工具调用,包含轮询、延迟结果检索和取消
  • 引出支持:服务器到客户端的表单和URL两种信息请求,支持模式验证
  • 图标:工具、资源、资源模板和提示词上的可选图标元数据
  • TypeBox 验证:带有自动 TypeScript 推断的类型安全模式验证
  • 安全增强:输入净化、速率限制和安全评估
  • 多重传输支持:HTTP/SSE和标准传输支持灵活通信
  • SSE 流式传输:服务器发送事件用于实时通信

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Fastify MCP Server

A Fastify plugin that implements the Model Context Protocol (MCP) server using JSON-RPC 2.0. This plugin enables Fastify applications to expose tools, resources, and prompts following the MCP 2025-06-18 specification with full elicitation support.

Installation

npm install @platformatic/mcp

TypeBox Support (Optional)

For type-safe schema validation, install TypeBox:

npm install @sinclair/typebox

Features

  • Complete MCP 2025-11-25 Support: Implements the current Model Context Protocol revision, negotiating down to 2025-06-18, 2025-03-26 and 2024-11-05 for older clients
  • Tasks (experimental): Task-augmented tool calls with polling, deferred result retrieval and cancellation
  • Elicitation Support: Server-to-client information requests in both form and URL mode, with schema validation
  • Icons: Optional icon metadata on tools, resources, resource templates and prompts
  • TypeBox Validation: Type-safe schema validation with automatic TypeScript inference
  • Security Enhancements: Input sanitization, rate limiting, and security assessment
  • Multiple Transport Support: HTTP/SSE and stdio transports for flexible communication
  • SSE Streaming: Server-Sent Events for real-time communication
  • Horizontal Scaling: Redis-backed session management and message broadcasting
  • Session Persistence: Message history and reconnection support with Last-Event-ID
  • Memory & Redis Backends: Seamless switching between local and distributed storage
  • Production Ready: Comprehensive test coverage, security features, and authentication support

Quick Start

import Fastify from 'fastify'
import mcpPlugin from '@platformatic/mcp'
// Or use named import:
// import { mcpPlugin } from '@platformatic/mcp'

const app = Fastify({ logger: true })

// Register the MCP plugin
await app.register(mcpPlugin, {
  serverInfo: {
    name: 'my-mcp-server',
    version: '1.0.0'
  },
  capabilities: {
    tools: { listChanged: true },
    resources: { subscribe: true },
    prompts: {}
  },
  instructions: 'This server provides custom tools and resources'
})

// Add tools, resources, and prompts with handlers
app.mcpAddTool({
  name: 'calculator',
  description: 'Performs basic arithmetic operations',
  inputSchema: {
    type: 'object',
    properties: {
      operation: { type: 'string', enum: ['add', 'subtract', 'multiply', 'divide'] },
      a: { type: 'number' },
      b: { type: 'number' }
    },
    required: ['operation', 'a', 'b']
  }
}, async (params) => {
  const { operation, a, b } = params
  let result
  switch (operation) {
    case 'add': result = a + b; break
    case 'subtract': result = a - b; break
    case 'multiply': result = a * b; break
    case 'divide': result = a / b; break
    default: throw new Error('Invalid operation')
  }
  return {
    content: [{ type: 'text', text: `Result: ${result}` }]
  }
})

app.mcpAddResource({
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →