# API Server Pattern — 页面直连MCP

工作台页面通过本地HTTP服务器代理MCP调用，避免CORS和Token暴露。

## 架构
```
浏览器 fetch('/api/activities')
  → 127.0.0.1:8765 (Python http.server)
    → curl https://project.feishu.cn/mcp_server/v1 (X-Mcp-Token header)
      → 返回JSON
```

## 端点
| 路径 | 功能 | MCP调用 |
|------|------|---------|
| /api/activities | 最近100条商机活动 | search_by_mql → story |
| /api/complaints | 客诉列表 | list_todo → 售后管理 |
| /api/sales | 今日销售单 | search_by_mql → 销售订单 |
| /api/ping | 健康检查 | 无 |

## 启动
```bash
cd ~/Desktop/Hermes输出-工作类
lsof -ti:8765 | xargs kill -9 2>/dev/null  # 杀掉旧进程
python3 api_server.py &  # 启动新进程
```

## 前端使用
```javascript
fetch('/api/activities').then(r=>r.json()).then(d=>{
  // d = {items: [...], count: N, updated: 'HH:MM'}
})
```

## 容错
页面fetch失败时自动降级到JSON缓存文件。
