Integrations
Provides the runtime environment for the MCP server, enabling server-side execution of the tools and communication via standard I/O.
Supports package management for the MCP server, allowing easy installation of dependencies and execution of build scripts.
Serves as the foundation for building custom MCP tools, providing type safety and structure for implementing tools that can be integrated with AI systems.
MCP TypeScript 简单模板
一个用于构建模型上下文协议 (MCP) 服务器的简单 TypeScript 模板。该项目为创建可与 AI 系统集成的自定义 MCP 工具奠定了基础。
概述
此模板实现了一个基本的 MCP 服务器,其中包含一个示例 BMI 计算器工具。它演示了如何:
- 使用 TypeScript 设置 MCP 服务器
- 使用 Zod 定义并实现具有输入验证的 MCP 工具
- 将服务器连接到标准 I/O 进行通信
先决条件
- Node.js(建议使用 v20 或更高版本)
- npm 或 yarn
安装
- 克隆此存储库
- 安装依赖项:
Copy
项目结构
index.ts
- 带有示例工具的主服务器实现package.json
- 项目依赖项和脚本tsconfig.json
- TypeScript 配置
用法
构建和运行
构建并启动服务器:
Copy
这将编译 TypeScript 代码并启动 MCP 服务器。
发展
对于开发,您可以:
- 修改
index.ts
以添加您自己的工具 - 运行build命令进行编译:
Copy
创建自定义工具
要创建新工具,请在index.ts
中遵循以下模式:
Copy
依赖项
@modelcontextprotocol/sdk
- 核心 MCP SDKzod
- 模式验证dotenv
环境变量管理typescript
- TypeScript 编译器
执照
国际学习中心
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
This server cannot be installed
创建可与 AI 系统集成的自定义模型上下文协议服务器的基础,提供一个简单的 BMI 计算器工具作为示例实现。