package com.zy.ai.mcp.config;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.zy.ai.mcp.dto.McpToolHandler;
|
import com.zy.ai.mcp.dto.ToolDefinition;
|
import com.zy.ai.mcp.dto.ToolRegistry;
|
import com.zy.ai.mcp.service.WcsDataFacade;
|
|
import java.util.*;
|
|
public class McpToolsBootstrap {
|
|
public static void registerAll(ToolRegistry registry, final WcsDataFacade facade) {
|
|
registry.register(tool(
|
"device.get_crn_status",
|
"Query realtime status of a crn device by deviceNo.",
|
schemaObj(
|
propInt("crnNos", true)
|
),
|
schemaObj(
|
propObj("devices", true)
|
),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getCrnDeviceStatus(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"device.get_station_status",
|
"Query realtime status of a station device",
|
schemaObj(
|
|
),
|
schemaObj(
|
propObj("stations", true)
|
),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getStationDeviceStatus(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"device.get_rgv_status",
|
"Query realtime status of a rgv device by deviceNo.",
|
schemaObj(
|
propInt("rgvNos", true)
|
),
|
schemaObj(
|
propObj("devices", true)
|
),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getRgvDeviceStatus(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"task.list",
|
"List tasks by filters (status/CrnDevice/RgvDevice//time window).",
|
schemaObj(
|
propInt("crnNo", false),
|
propInt("rgvNo", false),
|
propArr("taskNos", false, "integer"),
|
propInt("limit", false)
|
),
|
schemaObj(propArr("tasks", true, "object")),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getTasks(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"log.query",
|
"Query logs by keyword/level/time window/device/task. Return clipped log lines.",
|
schemaObj(
|
propInt("limit", false)
|
),
|
schemaObj(propArr("logs", true, "object")),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getLogs(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"config.get_device_config",
|
"Get device config by deviceCode.",
|
schemaObj(
|
propArr("crnNos", false, "integer"),
|
propArr("rgvNos", false, "integer"),
|
propArr("devpNos", false, "integer")
|
),
|
schemaObj(propObj("deviceConfigs", true)),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getDeviceConfig(args);
|
}
|
}
|
));
|
|
registry.register(tool(
|
"config.get_system_config",
|
"Get key system configs for diagnosis.",
|
schemaObj(
|
|
),
|
schemaObj(
|
propObj("systemConfigs", true)
|
),
|
new McpToolHandler() {
|
public Object handle(JSONObject args) {
|
return facade.getSystemConfig(args);
|
}
|
}
|
));
|
|
// // ★ 诊断聚合快照:一次拿全
|
// registry.register(tool(
|
// "build_diagnosis_snapshot",
|
// "Aggregate diagnosis snapshot: tasks + device realtime + configs + clipped logs for diagnosis.",
|
// schemaObj(
|
// propStr("warehouseCode", true),
|
// propArr("deviceCodes", false, "string"), // 不传则按任务涉及设备推导
|
// propStr("taskNo", false),
|
// propStr("fromTime", true),
|
// propStr("toTime", true),
|
// propInt("taskLimit", false),
|
// propInt("logLimit", false),
|
// propArr("logKeywords", false, "string"),
|
// propBool("includeSystemConfig", false),
|
// propBool("includeDeviceConfig", false)
|
// ),
|
// schemaObj(
|
// propObj("snapshot", true),
|
// propArr("hints", false, "string")
|
// ),
|
// new McpToolHandler() {
|
// public Object handle(JSONObject args) {
|
// return facade.buildDiagnosisSnapshot(args);
|
// }
|
// }
|
// ));
|
}
|
|
// ---------- schema helpers ----------
|
private static ToolDefinition tool(String name, String desc,
|
Map<String, Object> in, Map<String, Object> out,
|
McpToolHandler handler) {
|
ToolDefinition d = new ToolDefinition();
|
d.setName(name);
|
d.setDescription(desc);
|
d.setInputSchema(in);
|
d.setOutputSchema(out);
|
d.setHandler(handler);
|
return d;
|
}
|
|
private static Map<String, Object> schemaObj(Object... props) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("type", "object");
|
|
Map<String, Object> properties = new LinkedHashMap<String, Object>();
|
List<String> required = new ArrayList<String>();
|
|
for (Object p : props) {
|
@SuppressWarnings("unchecked")
|
Map<String, Object> pm = (Map<String, Object>) p;
|
String name = String.valueOf(pm.get("name"));
|
boolean req = Boolean.TRUE.equals(pm.get("required"));
|
pm.remove("name");
|
pm.remove("required");
|
properties.put(name, pm);
|
if (req) required.add(name);
|
}
|
|
m.put("properties", properties);
|
if (!required.isEmpty()) m.put("required", required);
|
return m;
|
}
|
|
private static Map<String, Object> propStr(String name, boolean required) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("name", name);
|
m.put("required", required);
|
m.put("type", "string");
|
return m;
|
}
|
|
private static Map<String, Object> propInt(String name, boolean required) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("name", name);
|
m.put("required", required);
|
m.put("type", "integer");
|
return m;
|
}
|
|
private static Map<String, Object> propBool(String name, boolean required) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("name", name);
|
m.put("required", required);
|
m.put("type", "boolean");
|
return m;
|
}
|
|
private static Map<String, Object> propObj(String name, boolean required) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("name", name);
|
m.put("required", required);
|
m.put("type", "object");
|
return m;
|
}
|
|
private static Map<String, Object> propArr(String name, boolean required, String itemType) {
|
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
m.put("name", name);
|
m.put("required", required);
|
m.put("type", "array");
|
Map<String, Object> items = new LinkedHashMap<String, Object>();
|
items.put("type", itemType);
|
m.put("items", items);
|
return m;
|
}
|
}
|