Token导航 LogoToken导航TokenDH.com
MCP Fastify logo
AI代理未说明官方级别未说明来源级核验

MCP Fastify

MCP Server

一个基于Node.js和Fastify框架的MCP协议服务器模板,提供TypeScript支持、错误处理和会话管理功能,适用于构建符合MCP规范的服务器。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
服务器模板JavaScriptTypeScript本地部署

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

karankraina

提供方

karankraina

最后核验

2026/5/17 20:23

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP快速服务器模板

一个强大的建筑模板 模型上下文协议(MCP) 使用Node.js和Fastify框架的服务器。此模板为创建具有TypeScript支持、正确错误处理和会话管理的MCP兼容服务器提供了坚实的基础。

🚀 特性

  • MCP协议合规性:完全支持模型上下文协议规范
  • Fastify框架:高性能、低开销的web框架
  • TypeScript支持:具有全面类型定义的类型安全开发

📋 先决条件

  • Node.js 22+
  • npm或yarn包管理器
  • TypeScript知识(推荐)

🛠️ 安装

  1. 克隆存储库
   git clone https://github.com/karankraina/mcp-fastify.git
   cd mcp-fastify
  1. 安装依赖项
   npm install
  1. 设置环境变量
   cp sample.env .env
   # Edit .env with your configuration
  1. 构建项目
   npm run build
  1. 启动服务器
   npm start

🏗️ 项目结构

mcp-fastify/
├── src/                    # Source TypeScript files
│   ├── server.ts          # Main server implementation
│   └── tools/             # MCP tools directory
│       ├── index.ts       # Tool registration hub
│       └── divide-numbers.ts # Example divide tool with error handling
├── build/                 # Compiled JavaScript output
├── tests/                 # Test files
├── package.json          # Project configuration
├── tsconfig.json         # TypeScript configuration
├── sample.env            # Environment variables template
└── README.md             # This file

🔧 配置

环境变量

变量描述默认值必填
PORT服务器端口号3001没有
ENVIRONMENT运行时环境(development, production, test)production没有

服务器配置

服务器根据环境支持不同的日志记录配置:

  • 发展:带有时间戳的漂亮打印日志
  • 生产:JSON结构化日志
  • 测试:已禁用日志记录

🛠️ 添加新工具

要添加新的MCP工具:

  1. 创建新的工具文件 在……里面 src/tools/:
   // src/tools/your-new-tool.ts
   import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
   import { z } from "zod";

   export function registerYourNewTool(server: McpServer) {
       server.registerTool(
           "your_tool_name",
           {
               title: "Your Tool Title",
               description: "Description of what your tool does",
               annotations: {
                   destructiveHint: false,
                   openWorldHint: false,
               },
               inputSchema: {
                   param1: z.string().describe("First parameter"),
                   param2: z.number().describe("Second parameter"),
               },
           },
           async ({ param1, param2 }) => {
               try {
                   // Your tool logic here
                   const result = `Processed: ${param1} with ${param2}`;
                   
                   return {
                       content: [{
                           type: "text",
                           text: result,
                       }]
                   };
               } catch (error) {
                   console.error('Error in your tool:', error);
                   return {
                       content: [{
                           type: "text",
                           text: `Error: ${error instanceof Error ? error.message : String(error)}`,
                       }]
                   };
               }
           }
       );
   }
  1. 注册该工具 在……里面 src/tools/index.ts:
   import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
   import { registerMultiplyNumbersTool } from "./multiply-numbers.js";
   import { registerYourNewTool } from "./your-new-tool.js";

   export async function registerTools(server: McpServer) {
       await registerMultiplyNumbersTool(server);
       await registerYourNewTool(server);
   }
  1. 重建和测试:
   npm run build
   npm start

🧪 测试

运行测试套件:

npm test

在监视模式下运行测试:

npm run test:watch

运行覆盖率测试:

npm run test:coverage

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

访问存储库:https://github.com/karankraina/mcp-fastify

📄 许可证

此项目根据ISC许可证获得许可-请参阅 许可证 文件以获取详细信息。

🔗 链接

🙏 致谢

目录标签

目录标签

服务器模板JavaScriptTypeScript本地部署MCP协议Node.jsFastify

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP