forked from AtomDancing/tlbm-mcp
refactor: 移除写入类接口,仅保留只读查询能力
移除的接口: - bind_vehicle_to_order(绑定车辆) - register_user(注册用户) - wx_login(微信登录) - wx_get_phone(获取手机号) - admin_*(内部管理接口) 移除 ADMIN_KEY 配置,保留 TLBM_TOKEN 用于用户认证 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,10 +6,8 @@ TLBM 无人车运营 API 的 MCP 封装,支持 Hermes、Claude Code 等 AI Age
|
||||
|
||||
- **车辆状态查询**:实时状态、不可用统计、工作时长指标、行驶距离
|
||||
- **车辆轨迹回放**:指定日期的轨迹和状态信息
|
||||
- **订单管理**:运单汇总查询、SDK订单操作、车辆绑定
|
||||
- **用户管理**:用户注册、角色查询
|
||||
- **微信登录**:小程序登录、手机号获取
|
||||
- **内部管理**:重新聚合、状态推导(需Admin Key)
|
||||
- **订单查询**:运单汇总查询、SDK订单详情
|
||||
- **用户查询**:角色查询、OpenID查询用户
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -86,7 +84,7 @@ mcp_servers:
|
||||
args: ["-y", "tlbm-mcp"]
|
||||
env:
|
||||
TLBM_API_URL: "https://www.atomdancing.com/pm"
|
||||
TLBM_ADMIN_KEY: "" # 可选,用于内部管理接口
|
||||
TLBM_TOKEN: "" # 可选,用于用户认证
|
||||
```
|
||||
|
||||
### Claude Code / Claude Desktop
|
||||
@@ -101,7 +99,7 @@ mcp_servers:
|
||||
"args": ["-y", "tlbm-mcp"],
|
||||
"env": {
|
||||
"TLBM_API_URL": "https://www.atomdancing.com/pm",
|
||||
"TLBM_ADMIN_KEY": ""
|
||||
"TLBM_TOKEN": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,12 +125,8 @@ mcp_servers:
|
||||
| `mcp_tlbm_get_unfinished_orders` | 未完成运单 |
|
||||
| `mcp_tlbm_get_sdk_order_list` | SDK订单列表 |
|
||||
| `mcp_tlbm_get_sdk_order_detail` | SDK订单详情 |
|
||||
| `mcp_tlbm_bind_vehicle_to_order` | 绑定车辆到订单 |
|
||||
| `mcp_tlbm_get_user_roles` | 查询用户角色 |
|
||||
| `mcp_tlbm_get_user_by_openid` | 按OpenID查询用户 |
|
||||
| `mcp_tlbm_register_user` | 注册用户 |
|
||||
| `mcp_tlbm_wx_login` | 微信小程序登录 |
|
||||
| `mcp_tlbm_wx_get_phone` | 获取微信手机号 |
|
||||
|
||||
## 车辆状态码说明
|
||||
|
||||
|
||||
+3
-104
@@ -15,7 +15,6 @@ import {
|
||||
|
||||
// API 配置
|
||||
const API_BASE_URL = process.env.TLBM_API_URL || "https://www.atomdancing.com/pm";
|
||||
const ADMIN_KEY = process.env.TLBM_ADMIN_KEY || "";
|
||||
const USER_TOKEN = process.env.TLBM_TOKEN || "";
|
||||
|
||||
// HTTP 请求函数
|
||||
@@ -36,16 +35,11 @@ async function httpRequest(method: string, path: string, params?: Record<string,
|
||||
...headers,
|
||||
};
|
||||
|
||||
// 用户 Token 认证(所有非 admin 接口)
|
||||
if (USER_TOKEN && !path.startsWith("/api/admin")) {
|
||||
// 用户 Token 认证
|
||||
if (USER_TOKEN) {
|
||||
fetchHeaders["Authorization"] = `Bearer ${USER_TOKEN}`;
|
||||
}
|
||||
|
||||
// Admin Key 认证(admin 接口)
|
||||
if (ADMIN_KEY && path.startsWith("/api/admin")) {
|
||||
fetchHeaders["X-Admin-Key"] = ADMIN_KEY;
|
||||
}
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
method,
|
||||
headers: fetchHeaders,
|
||||
@@ -233,20 +227,6 @@ const TOOLS = [
|
||||
},
|
||||
endpoint: { method: "GET", path: "/api/order/sdk/detail/{orderId}" },
|
||||
},
|
||||
{
|
||||
name: "bind_vehicle_to_order",
|
||||
description: "绑定车辆到订单",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
orderId: { type: "string", description: "订单号" },
|
||||
vinId: { type: "string", description: "车牌号" },
|
||||
vin: { type: "string", description: "车辆识别码(可选)" },
|
||||
},
|
||||
required: ["orderId", "vinId"],
|
||||
},
|
||||
endpoint: { method: "GET", path: "/api/order/sdk/bindVehicle" },
|
||||
},
|
||||
|
||||
// === 用户管理 ===
|
||||
{
|
||||
@@ -267,83 +247,9 @@ const TOOLS = [
|
||||
},
|
||||
endpoint: { method: "GET", path: "/api/user/openId/{wxOpenId}" },
|
||||
},
|
||||
{
|
||||
name: "register_user",
|
||||
description: "注册新用户(已存在则更新信息)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
wxOpenId: { type: "string", description: "微信OpenID" },
|
||||
wxUnionId: { type: "string", description: "微信UnionID" },
|
||||
wxNickname: { type: "string", description: "微信昵称" },
|
||||
phone: { type: "string", description: "手机号" },
|
||||
},
|
||||
required: ["wxOpenId", "wxUnionId"],
|
||||
},
|
||||
endpoint: { method: "POST", path: "/api/user/register" },
|
||||
},
|
||||
|
||||
// === 微信登录 ===
|
||||
{
|
||||
name: "wx_login",
|
||||
description: "微信小程序登录",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
appKey: { type: "string", description: "小程序标识(如:tlbc、tlbm)" },
|
||||
code: { type: "string", description: "微信登录code" },
|
||||
wxNickname: { type: "string", description: "微信昵称" },
|
||||
phone: { type: "string", description: "手机号" },
|
||||
phoneCode: { type: "string", description: "微信获取手机号的code" },
|
||||
},
|
||||
required: ["appKey", "code"],
|
||||
},
|
||||
endpoint: { method: "POST", path: "/api/wx/login" },
|
||||
},
|
||||
{
|
||||
name: "wx_get_phone",
|
||||
description: "通过微信code获取手机号",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
appKey: { type: "string", description: "小程序标识" },
|
||||
phoneCode: { type: "string", description: "微信手机号code" },
|
||||
},
|
||||
required: ["appKey", "phoneCode"],
|
||||
},
|
||||
endpoint: { method: "POST", path: "/api/wx/phone" },
|
||||
},
|
||||
|
||||
// === 内部管理(需要Admin Key)===
|
||||
{
|
||||
name: "admin_reaggregate_order_summary",
|
||||
description: "重新聚合运单汇总(清空水位点和order_summary表,从头重新聚合),异步执行",
|
||||
inputSchema: { type: "object", properties: {} },
|
||||
endpoint: { method: "POST", path: "/api/admin/reaggregate-order-summary" },
|
||||
requiresAdmin: true,
|
||||
},
|
||||
{
|
||||
name: "admin_reconvert_order_status",
|
||||
description: "重新推导订单状态(清空旧数据,从vehicle_status_duration重新推导),异步执行",
|
||||
inputSchema: { type: "object", properties: {} },
|
||||
endpoint: { method: "POST", path: "/api/admin/reconvert-order-status" },
|
||||
requiresAdmin: true,
|
||||
},
|
||||
{
|
||||
name: "admin_reconvert_stream_processor",
|
||||
description: "重新推导订单状态(逐笔方式),清空上下文从头处理,异步执行",
|
||||
inputSchema: { type: "object", properties: {} },
|
||||
endpoint: { method: "POST", path: "/api/admin/reconvert-stream-processor" },
|
||||
requiresAdmin: true,
|
||||
},
|
||||
{
|
||||
name: "admin_reset_stream_processor",
|
||||
description: "重置逐笔处理器上下文(清空水位点和所有上下文)",
|
||||
inputSchema: { type: "object", properties: {} },
|
||||
endpoint: { method: "POST", path: "/api/admin/reset-stream-processor" },
|
||||
requiresAdmin: true,
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
// 创建 Server
|
||||
const server = new Server(
|
||||
@@ -371,13 +277,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
throw new Error(`Unknown tool: ${name}`);
|
||||
}
|
||||
|
||||
// 检查 Admin Key
|
||||
if (tool.requiresAdmin && !ADMIN_KEY) {
|
||||
return {
|
||||
content: [{ type: "text", text: "错误:需要设置 TLBM_ADMIN_KEY 环境变量才能调用内部管理接口" }],
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
// 处理路径参数
|
||||
let path = tool.endpoint.path;
|
||||
|
||||
Reference in New Issue
Block a user