M

MCP-TS 模板

@yhwancha/mcp_ts_starter
0 Stars 17 次浏览 yhwancha 更新于 2026-08-23

一个用于使用 TypeScript 创建模型上下文协议(MCP)服务器的启动模板,为开发者提供了基本的设置和示例工具实现,以便构建自己的 MCP 服务器。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

MCP TypeScript Starter

这是一个用于创建使用TypeScript编写的Model Context Protocol (MCP) 服务器的启动模板。它提供了一个基本设置和示例工具实现,以帮助您开始构建自己的MCP服务器。

特性

  • TypeScript配置
  • 基本的MCP服务器设置
  • 示例工具实现
  • 类型安全的开发环境

开始

按照以下步骤创建您自己的MCP服务器:

# Create a new directory for your project
mkdir <project_name>
cd <project_name>

# Initialize a new npm project
npm init -y

# Install dependencies
npm install @modelcontextprotocol/sdk zod
npm install -D @types/node typescript

# Create source directory and main file
mkdir src
touch src/index.ts

项目结构

.
├── src/
│   └── index.ts    # Main server implementation
├── package.json    # Project dependencies and scripts
└── tsconfig.json   # TypeScript configuration

开发

  1. src/index.ts中实现您的工具。
  2. 构建项目:
    npm run build
    

添加新工具

要添加一个新的工具,请使用server.tool()方法。例如:

server.tool(
  "tool-name",
  "tool-description",
  { 
    // Define your tool's parameters using Zod schema
    param: z.string().describe("parameter description") 
  },
  async ({ param }) => {
    // Implement your tool logic here
    return {
      content: [
        {
          type: "text",
          text: `Tool executed with parameter: ${param}`,
        },
      ],
    };
  },
);

许可证

ISC