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:
2026-06-07 11:52:01 +08:00
co-authored by Claude Opus 4.6
parent 0f28e31ba2
commit 388d1e8e99
2 changed files with 11 additions and 118 deletions
+7 -108
View File
@@ -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,21 +227,7 @@ 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" },
},
// === 用户管理 ===
{
name: "get_user_roles",
@@ -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(
@@ -370,14 +276,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (!tool) {
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;