MCP协议服务器模板

一个基于Node.js/TypeScript的MCP协议服务器模板,提供简单的笔记管理系统和MCP协议实现示例。

  • by Rethunk-AI
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Rethunk-Tech/mcp-template-node

使用说明

MCP模板节点

用于在Node.js/TypeScript中创建模型上下文协议(MCP)服务器的模板存储库。此模板演示了一个使用MCP协议的简单笔记管理系统。

什么是MCP?

模型上下文协议(MCP)是应用程序向大型语言模型(LLM)提供上下文的标准化方法。更多信息请访问 模型上下文协议网站.

特性

  • 具有严格类型检查的TypeScript实现
  • 具有基本CRUD操作的简单笔记管理系统
  • MCP概念的完整示例(工具、资源、提示)
  • 用于存储笔记的内存
  • 全面的错误处理和验证
  • 使用Vitest进行单元测试
  • VS代码调试配置
  • 用于测试和构建的GitHub Actions CI工作流

先决条件

  • Node.js 18或更高版本
  • npm或纱线

项目结构

mcp-template-node/
├── build/                # Compiled JavaScript files
├── src/
│   ├── __tests__/        # Integration tests and test utilities
│   ├── errors/           # Custom error classes
│   ├── tools/            # MCP tool implementations
│   │   └── __tests__/    # Tool unit tests
│   ├── types/            # TypeScript type definitions
│   │   └── __tests__/    # Type tests
│   └── index.ts          # Main server entry point with MCP examples
├── package.json          # Project configuration
├── tsconfig.json         # TypeScript configuration
├── eslint.config.mjs     # ESLint flat configuration
└── README.md             # Project documentation

入门指南

  1. 克隆存储库:

    git clone https://github.com/Rethunk-Tech/mcp-template-node.git
    cd mcp-template-node
    
  2. 安装依赖项:

    yarn install
    
  3. 构建并运行服务器:

    yarn build
    yarn start
    

发展

  • 在监视模式下启动TypeScript编译器: yarn dev
  • 打开你的代码: yarn lint
  • 修复掉毛问题: yarn lint:fix
  • 运行测试: yarn test

测试

该项目包括全面的测试,以验证MCP服务器及其工具的功能。

运行测试

运行所有测试:

yarn test

在监视模式下运行测试(文件更改时重新运行测试):

yarn test:watch

运行覆盖率测试:

yarn test:coverage

测试结构

  • 单元测试:位于 __tests__ 他们测试的代码附近的目录
  • 集成测试:位于 src/__tests__/
  • 公共应用接口模块:常见的测试助手 src/__tests__/test-utils.ts

写作测试

该项目包括一个MockMcpServer,用于测试没有真正MCP依赖关系的工具:

import { MockMcpServer } from '../__tests__/test-utils.js';

describe('My Tool Tests', () => {
  let server: MockMcpServer;

  beforeEach(() => {
    server = new MockMcpServer();
    // Register tools
    registerMyTools(server as any);
  });

  it('should perform some action', async () => {
    const result = await server.callTool('my_tool', { param: 'value' });
    expect(result.content[0].text).toContain('Expected text');
  });
});

MCP检验员测试

对于独立测试,请使用MCP检查器工具:

yarn inspector

这将打开一个交互式会话,您可以在其中测试MCP工具。

可用工具

创建便笺

创建带有标题和内容的新注释。

列表注释

列出所有可用的笔记及其ID和标题。

获取注释

按ID检索特定笔记。

更新说明

更新现有笔记的标题、内容或标签。

删除注释

按ID删除笔记。

扩展模板

要扩展此模板,请执行以下操作:

  1. 在中添加新类型 src/types/
  2. 在中实施新工具 src/tools/
  3. 在中添加新资源 src/index.ts
  4. 根据需要创建新的提示模板
  5. 为新功能添加测试

贡献

看 贡献.md 了解如何为这个项目做出贡献的指导方针。

许可证

麻省理工学院