Back to MCP directory
publicPublicdnsLocal runtime

MCP Server Starter

一个基于TypeScript的MCP服务器生产级启动模板,提供快速开发和测试工具。

article

README

🚀 MCP 服务器启动器

一个适合生产的起始模板,用于使用 TypeScript 构建 Model Context Protocol (MCP) 服务器,能帮助开发者快速搭建和启动 MCP 服务器。

smithery badge

🚀 快速开始

克隆与安装

  1. 克隆仓库。
  2. 安装依赖:
    bun install
    

✨ 主要特性

  • 高效开发:使用 Bun 进行快速测试和开发,提升开发效率。
  • 代码规范:使用 Biome 进行代码检查和格式化,保证代码质量。
  • 版本管理:借助 standard - version 实现自动版本管理。
  • 结构清晰:项目结构清晰、易于维护。

📦 安装指南

项目结构

mcp-starter/
├── src/
│   ├── tools/          # MCP 工具实现
│   ├── utils/          # 共用工具类
│   ├── main.ts         # 服务器入口点
│   └── types.ts        # 共用类型定义
├── tests/              # 测试文件
├── biome.json          # 代码检查配置
├── tsconfig.json       # TypeScript 配置
└── package.json        # 项目依赖

创建新工具

该项目提供一个脚本以帮助创建新的 MCP 工具:

bun run scripts/create-tool.ts <tool-name>

此命令将执行以下操作:

  1. src/tools/<tool-name> 下创建一个新的工具目录。
  2. 生成基本工具结构,包括:
    • index.ts (主要实现)
    • schema.ts (工具参数的 JSON 模式)
    • test.ts (测试文件)
  3. 更新工具索引文件以导出新工具。

示例:

bun run scripts/create-tool.ts weather

💻 使用示例

基础用法

src/main.ts 中:

import { createServer } from 'http';

const server = createServer((req, res) => {
  res.writeHead(200);
  res.end('Hello MCP Server!');
});

server.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

构建并运行:

bun run build && bun run start

📚 详细文档

开发相关命令

  • 运行测试bun test
  • 格式化代码bun run format
  • 检查代码bun run lint
  • 构建项目bun run build

添加到 Claude Desktop

要将你的开发 MCP 服务器添加到 Claude Desktop:

  1. 构建项目:
    bun run build
    
  2. 添加到你的 Claude Desktop 配置中:
    // 只有在你需要传递参数给服务器时才需要此参数
    {
      "mcpServers": {
        "your-server-name": {
          "command": "node",
          "args": ["/path/to/your/project/dist/main.js", "some_argument"]
        }
      }
    }
    

版本管理

该项目使用 standard - version 进行自动化版本管理。运行 bun run release 创建新版本。

提交信息格式

  • feat:新功能(递增次版本号)
  • fix:修复问题(递增补丁版本号)
  • BREAKING CHANGE:破坏性变更(递增主版本号)

发布到 npm

  1. 确保已登录 npm:
    npm login
    
  2. 构建项目:
    bun run build
    
  3. 发布包:
    npm publish
    

在发布新版本之前,请使用 bun run release 更新版本号。

从 npm 安装(在发布后)

将以下内容添加到你的 Claude Desktop 配置中:

// 只有在你需要传递参数给服务器时才需要此参数
{
  "mcpServers": {
    "your-server-name": {
      "command": "npx",
      "args": ["-y", "your-package-name", "some_argument"]
    }
  }
}

要启动服务器,请运行:

npx your-package-name
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client