mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(LocalRunnerClient): support loading primary fileMcpCache when CommonMcp launched
This commit is contained in:
@@ -1025,7 +1025,28 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
if (!normalFile(file)) {
|
||||
continue;
|
||||
}
|
||||
registerMcpClients(file);
|
||||
|
||||
val json = readJson(file);
|
||||
if (json == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
val newFileRecord = new McpConfigFileRecord(file.lastModified(), file.length());
|
||||
for (String id : json.keySet()) {
|
||||
val mcp = readMcp(json, id);
|
||||
if (mcp == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
val params = readParams(mcp);
|
||||
if (params == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registerMcpClient(id, params);
|
||||
newFileRecord.paramsCacheMap().put(id, params);
|
||||
}
|
||||
mcpConfigFileCache.put(file, newFileRecord);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1044,27 +1065,6 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
return (thisDir, context) -> checkAndReload(true);
|
||||
}
|
||||
|
||||
private void registerMcpClients(File file) {
|
||||
val json = readJson(file);
|
||||
if (json == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String id : json.keySet()) {
|
||||
val mcp = readMcp(json, id);
|
||||
if (mcp == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
val params = readParams(mcp);
|
||||
if (params == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registerMcpClient(id, params);
|
||||
}
|
||||
}
|
||||
|
||||
private cn.hutool.json.JSONObject readJson(File file) {
|
||||
try {
|
||||
return JSONUtil.readJSONObject(file, StandardCharsets.UTF_8);
|
||||
@@ -1231,6 +1231,9 @@ public class LocalRunnerClient extends RunnerClient {
|
||||
|
||||
private record McpConfigFileRecord(long lastModified, long length,
|
||||
Map<String, McpClientTransportParams> paramsCacheMap) {
|
||||
public McpConfigFileRecord(long lastModified, long length) {
|
||||
this(lastModified, length, new HashMap<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user