feat(LocalRunnerClient): support executing MetaActions via MCP type

This commit is contained in:
2025-12-19 22:29:03 +08:00
parent 4dea948f82
commit 5ba36ed3e8
4 changed files with 15 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ public class MetaAction {
/** /**
* 行动程序可接受的参数,由调用处设置 * 行动程序可接受的参数,由调用处设置
*/ */
private Map<String, String> params; private Map<String, Object> params;
/** /**
* 行动结果,包括执行状态和相应内容(执行结果或者错误信息) * 行动结果,包括执行状态和相应内容(执行结果或者错误信息)
*/ */

View File

@@ -11,7 +11,7 @@ public class MetaActionInfo {
private boolean io; private boolean io;
private MetaActionType type; private MetaActionType type;
private Map<String, String> params; private Map<String, Object> params;
private String description; private String description;
private List<String> tags; private List<String> tags;

View File

@@ -3,6 +3,8 @@ package work.slhaf.partner.core.action.runner;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.spec.McpSchema;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -72,7 +74,7 @@ public class LocalRunnerClient extends RunnerClient {
} }
//TODO 后续需在加载时、或者通过配置文件获取可用命令并注册匹配 //TODO 后续需在加载时、或者通过配置文件获取可用命令并注册匹配
private String[] buildCommands(String ext, Map<String, String> params, String absolutePath) { private String[] buildCommands(String ext, Map<String, Object> params, String absolutePath) {
String command = switch (ext) { String command = switch (ext) {
case "py" -> "python"; case "py" -> "python";
case "sh" -> "bash"; case "sh" -> "bash";
@@ -86,14 +88,21 @@ public class LocalRunnerClient extends RunnerClient {
commands[1] = absolutePath; commands[1] = absolutePath;
AtomicInteger paramCount = new AtomicInteger(2); AtomicInteger paramCount = new AtomicInteger(2);
params.forEach((param, value) -> { params.forEach((param, value) -> {
commands[paramCount.getAndIncrement()] = "--" + param + "=" + value; commands[paramCount.getAndIncrement()] = "--" + param + "=" + value.toString();
}); });
return commands; return commands;
} }
private RunnerResponse doRunWithMcp(MetaAction metaAction) { private RunnerResponse doRunWithMcp(MetaAction metaAction) {
RunnerResponse response = new RunnerResponse(); RunnerResponse response = new RunnerResponse();
McpSyncClient mcpClient = mcpClients.get(metaAction.getLocation());
McpSchema.CallToolRequest callToolRequest = McpSchema.CallToolRequest.builder()
.name(metaAction.getName())
.arguments(metaAction.getParams())
.build();
McpSchema.CallToolResult callToolResult = mcpClient.callTool(callToolRequest);
response.setOk(callToolResult.isError());
response.setData(callToolResult.structuredContent().toString());
return response; return response;
} }

View File

@@ -7,7 +7,7 @@ import java.util.Map;
@Data @Data
public class GeneratorInput { public class GeneratorInput {
private String actionName; private String actionName;
private Map<String, String> params; private Map<String, Object> params;
private String description; private String description;
private Map<String, String> paramsDescription; private Map<String, String> paramsDescription;
} }