Day 4 · MCP 实战
预计时间:3 小时
学习材料
| # | 资料 | 时间 | 类型 |
|---|---|---|---|
| 1 | Build Your First MCP Server - Step by Step | 1.5h | 动手教程 |
| 2 | MCP TypeScript SDK | 30min | 源码浏览 |
MCP Server 最小实现
typescript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({
name: "my-server",
version: "1.0.0",
});
// 定义 Tool
server.tool("hello", { name: "string" }, async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}));
// 启动
const transport = new StdioServerTransport();
await server.connect(transport);实践任务(1h)
给自己的一个项目写一个 MCP Server,推荐选项:
选项 A:清算机器人状态查询
Tools:
- get_health_factors: 查询监控中的仓位健康因子
- get_profit_history: 查询清算利润历史
- get_pending_liquidations: 查询待清算列表选项 B:做市策略参数
Tools:
- get_spread_config: 查询当前 spread 配置
- get_inventory: 查询库存状态
- update_params: 调整做市参数选项 C:站群部署状态
Tools:
- get_site_status: 查询各站点构建/部署状态
- get_traffic_stats: 查询流量数据
- trigger_deploy: 触发重新部署自检问题
- [ ] 你能独立从零写一个 MCP Server 并接入 Claude Code 吗?
- [ ] Tool 的参数校验怎么做?错误怎么返回?
- [ ] 如何把 MCP Server 注册到 Claude Code 的配置中?