MCP TypeScript Simple Template

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

安装

  1. 克隆此存储库
  2. 安装依赖项:
npm install

项目结构

  • index.ts - 带有示例工具的主服务器实现
  • package.json - 项目依赖项和脚本
  • tsconfig.json - TypeScript 配置

用法

构建和运行

构建并启动服务器:

npm start

这将编译 TypeScript 代码并启动 MCP 服务器。

发展

对于开发,您可以:

  1. 修改index.ts以添加您自己的工具
  2. 运行build命令进行编译:
npm run build

创建自定义工具

要创建新工具,请在index.ts中遵循以下模式:

server.tool( "your-tool-name", { // Define input schema using Zod paramName: z.string(), // Add more parameters as needed }, async ({ paramName }) => ({ content: [{ type: "text", text: "Your tool's response" }] }) );

依赖项

  • @modelcontextprotocol/sdk - 核心 MCP SDK
  • zod - 模式验证
  • dotenv环境变量管理
  • typescript - TypeScript 编译器

执照

国际学习中心

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

-
security - not tested
F
license - not found
-
quality - not tested

创建可与 AI 系统集成的自定义模型上下文协议服务器的基础,提供一个简单的 BMI 计算器工具作为示例实现。

  1. Overview
    1. Prerequisites
      1. Installation
        1. Project Structure
          1. Usage
            1. Building and Running
            2. Development
          2. Creating Custom Tools
            1. Dependencies
              1. License
                1. Contributing
                  ID: 50o10f60hi