MCP服务器

一个基于TypeScript构建的简单MCP(模型上下文协议)服务器,提供问候和加法功能。

  • by gemyago
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 gemyago/typescript-mcp-boilerplate

使用说明

HelloWorld MCP服务器

用TypeScript构建的简单HelloWorld MCP(模型上下文协议)服务器实验。

特性

此MCP服务器提供两个简单的工具:

  • 你好:向某人问好(默认:“World”)
  • 添加:将两个数字相加

先决条件

  • Node.js 22+(LTS)
  • npm
  • nvm(建议用于Node.js版本管理)
  • direnv(用于环境管理)

设置

  1. Node.js版本管理

    # If you have nvm installed:
    nvm use
    
    # This will use Node.js version 22 as specified in .nvmrc
    
  2. 使用direnv进行环境设置

    # Allow direnv for this directory
    direnv allow
    
    # This will automatically add node_modules/.bin to your PATH
    
  3. 再进行

    npm install
    

发展

可用脚本

  • npm run dev -使用tsx在开发模式下运行服务器
  • npm run build -将TypeScript编译为JavaScript
  • npm start -运行已编译的服务器
  • npm run lint -在源代码上运行ESLint
  • npm run lint:fix -运行ESLint并自动修复问题
  • npm run clean -删除dist目录

运行服务器

发展:

npm run dev

生产:

npm run build
npm start

MCP服务器使用情况

此服务器通过stdio进行通信,并实现模型上下文协议。它提供:

工具

  1. 你好

    • 描述:向某人打招呼
    • 参数:
      • name (可选):要问候的人的姓名(默认:“World”)
    • 例子: {"name": "Alice"} → “你好,爱丽丝!👋 欢迎来到HelloWorld MCP服务器!"
  2. 添加

    • 说明:将两个数字相加
    • 参数:
      • a (必填):第一个数字
      • b (必填):第二个数字
    • 例子: {"a": 5, "b": 3} → "5 + 3 = 8"

项目结构

├── src/
│   └── index.ts          # Main MCP server implementation
├── dist/                 # Compiled JavaScript (after build)
├── .nvmrc               # Node.js version specification
├── .envrc               # direnv configuration
├── eslint.config.js     # ESLint configuration
├── tsconfig.json        # TypeScript configuration
├── package.json         # Node.js project configuration
└── README.md           # This file

代码质量

本项目使用:

  • TypeScript 用于类型安全
  • ESLint 支持TypeScript以提高代码质量
  • 严格的TypeScript配置 为了更好地进行类型检查

许可证

麻省理工学院