chore: 初始化仓库

This commit is contained in:
Lydanne
2026-02-15 22:02:21 +08:00
commit 08d011d63f
381 changed files with 87202 additions and 0 deletions

100
docs/guide/commands/mcp.md Normal file
View File

@@ -0,0 +1,100 @@
# mcp — MCP 服务
启动 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 服务器,聚合所有已安装 Extension 提供的 MCP 工具。
## 基本用法
```bash
# 启动 MCP Server
spaceflow mcp
# 启动 MCP Inspector调试模式
spaceflow mcp --inspector
```
## 工作原理
1. **扫描 Extension** — 加载所有已安装的 Extension
2. **收集工具** — 查找带有 `@McpServer` 装饰器的类,提取其 MCP 工具定义
3. **启动服务** — 通过 stdio 传输协议启动 MCP Server
4. **注册工具** — 将所有工具注册到 MCP Server支持 JSON Schema 参数校验
## MCP Inspector
使用 `--inspector` 启动 MCP Inspector提供 Web UI 调试界面:
```bash
spaceflow mcp --inspector
```
Inspector 会自动下载并启动 `@modelcontextprotocol/inspector`,提供:
- 工具列表查看
- 工具调用测试
- 请求/响应日志
## 在编辑器中配置
### Claude Desktop
`claude_desktop_config.json` 中添加:
```json
{
"mcpServers": {
"spaceflow": {
"command": "spaceflow",
"args": ["mcp"]
}
}
}
```
### Cursor
`.cursor/mcp.json` 中添加:
```json
{
"mcpServers": {
"spaceflow": {
"command": "spaceflow",
"args": ["mcp"]
}
}
}
```
## 开发 MCP 工具
Extension 可以通过 `@McpServer``@McpTool` 装饰器暴露 MCP 工具:
```typescript
import { McpServer, McpTool, Injectable } from "@spaceflow/core";
@McpServer({ name: "my-tools", description: "我的工具集" })
@Injectable()
export class MyMcpTools {
@McpTool({
name: "hello",
description: "打招呼",
inputSchema: {
type: "object",
properties: {
name: { type: "string", description: "名字" },
},
required: ["name"],
},
})
async hello(args: { name: string }): Promise<string> {
return `Hello, ${args.name}!`;
}
}
```
## 命令行选项
| 选项 | 简写 | 说明 |
|------|------|------|
| `--inspector` | `-i` | 启动 MCP Inspector 调试模式 |
| `--verbose` | `-v` | 详细日志(`-v` 基本,`-vv` 详细,`-vvv` 调试) |