docs: translate README into Chinese

This commit is contained in:
Jax 2026-03-13 16:37:24 +08:00
parent 8df0a58dfa
commit c825f59e4d

109
README.md
View File

@ -1,86 +1,91 @@
# TS MCP Template (V1) # TS MCP 模板V1
A Node.js template for building Model Context Protocol (MCP) servers with TypeScript. This template focuses on a local-first development experience, protocol-safe stdio execution, and explicit capability registration. 这是一个用于构建 Model Context ProtocolMCP服务端的 Node.js + TypeScript 模板。该模板重点关注本地优先的开发体验、协议安全的 stdio 执行方式,以及显式的能力注册模式。
## Status: V1 Alpha ## 当前状态V1 Alpha
This template supports:
- Node.js 20+ runtime
- Single-package architecture
- Protocol-safe Local Stdio transport (Primary)
- Streamable HTTP transport (Secondary)
- Explicit, function-based tool, resource, and prompt registration
- Vitest-powered transport and core logic testing
It does not currently support Bun, Deno, edge runtimes, built-in authentication, or telemetry. 当前模板支持:
- Node.js 20+ 运行时
- 单包架构
- 协议安全的本地 Stdio 传输(主要方式)
- Streamable HTTP 传输(次要方式)
- 显式的、基于函数的 tool、resource 和 prompt 注册方式
- 基于 Vitest 的传输层与核心逻辑测试
## Quickstart: Local Stdio 当前尚不支持 Bun、Deno、边缘运行时、内置鉴权或遥测能力。
Stdio is the primary transport for local development and integration with desktop LLM clients like Claude. ## 快速开始:本地 Stdio
1. **Install dependencies** Stdio 是本模板在本地开发以及与 Claude 等桌面 LLM 客户端集成时的主要传输方式。
1. **安装依赖**
```bash ```bash
npm install npm install
``` ```
2. **Run with MCP Inspector** 2. **使用 MCP Inspector 运行**
The template includes a protocol-safe launch configuration in `package.json` to avoid stdout pollution. Use this command to test your server: 模板在 `package.json` 中提供了协议安全的启动配置,用于避免 stdout 被污染。你可以使用以下命令测试服务端:
```bash ```bash
npx @modelcontextprotocol/inspector node ./node_modules/tsx/dist/cli.mjs src/stdio.ts npx @modelcontextprotocol/inspector node ./node_modules/tsx/dist/cli.mjs src/stdio.ts
``` ```
3. **Build the project** 3. **构建项目**
To prepare for production or use with a compiled entry point: 如果你要为生产环境做准备,或使用编译后的入口文件,可以执行:
```bash ```bash
npm run build npm run build
``` ```
## Usage: HTTP ## 使用方式:HTTP
The HTTP transport uses the Node-native `StreamableHTTPServerTransport` for remote or web-based connections. HTTP 传输基于 Node 原生的 `StreamableHTTPServerTransport`,适用于远程连接或基于 Web 的接入场景。
1. **Start the HTTP server** 1. **启动 HTTP 服务**
```bash ```bash
npm run dev:http npm run dev:http
``` ```
The server defaults to `127.0.0.1:3000`. You can configure the port via the `HTTP_PORT` environment variable. 服务默认监听 `127.0.0.1:3000`。你也可以通过 `HTTP_PORT` 环境变量自定义端口。
2. **Endpoints** 2. **接口端点**
- `POST /mcp`: Initialize a new session and handle requests. - `POST /mcp`:初始化一个新会话并处理请求。
- `GET /mcp`: Handle ongoing session requests. - `GET /mcp`:处理已有会话中的后续请求。
## Development and Testing ## 开发与测试
- **Typecheck**: `npm run typecheck` - **类型检查**`npm run typecheck`
- **Test**: `npm test` (Runs Vitest smoke tests for stdio, HTTP, and core logic) - **测试**`npm test`(运行 stdio、HTTP 和核心逻辑的 Vitest smoke tests
- **Dev (Core Logic)**: `npm run dev` (Executes `src/index.ts`) - **开发模式(核心逻辑)**`npm run dev`(执行 `src/index.ts`
## Repository Structure ## 仓库结构
- `src/core/`: The shared MCP core factory (`createMcpCore`) that builds the server and registry. - `src/core/`:共享的 MCP 核心工厂 `createMcpCore`,负责构建服务端与注册表。
- `src/capabilities/`: Definitions and handlers for tools, resources, and prompts. - `src/capabilities/`tools、resources 与 prompts 的定义及处理逻辑。
- `src/stdio.ts`: The stdio entry point and transport setup. - `src/stdio.ts`stdio 入口文件及其传输层配置。
- `src/http.ts`: The HTTP entry point and session management. - `src/http.ts`HTTP 入口文件与会话管理逻辑。
- `src/config/`: Runtime configuration and environment variable parsing. - `src/config/`:运行时配置与环境变量解析。
- `src/lib/`: Internal utilities, stderr-safe logging, and error handling. - `src/lib/`内部工具函数、stderr 安全日志以及错误处理。
## Extension Guidance ## 扩展指引
This template uses an explicit, function-based registration pattern instead of decorators or reflection. 该模板使用显式的、基于函数的注册模式,而不是装饰器或反射机制。
### 1. Define Contracts ### 1. 定义契约
Add new tool or prompt schemas in `src/capabilities/contracts.ts` to share types between handlers and tests.
### 2. Implement Handlers `src/capabilities/contracts.ts` 中新增 tool 或 prompt 的 schema以便在处理逻辑和测试之间共享类型。
Create or update files in `src/capabilities/` (e.g., `tools.ts`):
1. Define the handler logic.
2. Update the `register...Capabilities` function to add descriptors to the registry.
3. Update the `register...Handlers` function to wire the logic to the `McpServer` instance.
### 3. Register with Core ### 2. 实现处理器
If you create new capability modules, ensure they are called within `src/capabilities/index.ts` in the `registerCoreCapabilities` and `registerCoreMcpCapabilities` functions.
## V1 Limitations `src/capabilities/` 中创建或更新文件(例如 `tools.ts`
- **No Auth**: HTTP transport does not include built-in authentication. 1. 定义处理器逻辑。
- **Node-only**: Specifically tuned for Node.js 20+. 2. 更新 `register...Capabilities` 函数,将描述信息加入注册表。
- **No Monorepo**: Designed as a standalone project template. 3. 更新 `register...Handlers` 函数,将逻辑挂接到 `McpServer` 实例上。
- **Local Focus**: Deployment guides for cloud providers are not provided in V1.
### 3. 注册到核心模块
如果你创建了新的 capability 模块,请确保它们已在 `src/capabilities/index.ts``registerCoreCapabilities``registerCoreMcpCapabilities` 函数中被调用。
## V1 限制
- **无鉴权**HTTP 传输不包含内置鉴权能力。
- **仅支持 Node**:当前专门针对 Node.js 20+ 进行适配。
- **非 Monorepo**:设计目标是独立项目模板,而不是多包仓库。
- **本地优先**V1 暂未提供面向云服务商的部署指南。