使用说明
MCP服务器TypeScript模板
使用TypeScript创建模型上下文协议(MCP)服务器的模板。此项目展示了如何使用自定义工具实现一个简单的MCP服务器。
概述
这个模板实现了一个基本的MCP服务器,提供了以下工具:
- 示例操作:一个简单的演示操作
- 附加:一个用于将两个数字相加的工具
服务器使用模型上下文协议SDK来处理人工智能模型与外部工具之间的通信。
先决条件
- Node.js(v16或更高版本)
- npm 或 yarn
项目结构
该项目的结构如下:
mcp-server-typescript-template/
├── common/
│ ├── constant.ts # Project constants
│ ├── errors.ts # Error handling utilities
│ └── types.ts # Type definitions
│ └── utils.ts # Utility functions
├── operations/
│ └── example-operation.ts # Implementation of example operations
├── index.ts # Main server implementation
├── package.json
└── tsconfig.json
安装
克隆仓库并安装依赖项:
git clone <repository-url>
cd mcp-server-typescript-template
npm install
npm run test
npm run build
npm run start # this will start the server for testing
配置MCP客户端(Claude桌面版)
编辑你的 claude_desktop_config.json 文件需添加以下内容:
{
"mcpServers": {
"example": {
"command": "node",
"args": [
"/path/to/mcp-server-typescript-template/dist/index.js"
]
}
}
}