mirror of
https://github.com/jtang613/GhidrAssistMCP
synced 2026-06-21 13:54:56 +00:00
77 lines
2.7 KiB
Java
77 lines
2.7 KiB
Java
/*
|
|
*
|
|
*/
|
|
package ghidrassistmcp.tools;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import ghidra.program.model.listing.Program;
|
|
import ghidrassistmcp.McpTool;
|
|
import io.modelcontextprotocol.spec.McpSchema;
|
|
|
|
/**
|
|
* MCP tool that provides detailed information about a specific function.
|
|
*/
|
|
public class GetFunctionInfoTool implements McpTool {
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "get_function_info";
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Get detailed information about a specific function";
|
|
}
|
|
|
|
@Override
|
|
public McpSchema.JsonSchema getInputSchema() {
|
|
return new McpSchema.JsonSchema("object",
|
|
Map.of("function_name", new McpSchema.JsonSchema("string", null, null, null, null, null)),
|
|
List.of("function_name"), null, null, null);
|
|
}
|
|
|
|
@Override
|
|
public McpSchema.CallToolResult execute(Map<String, Object> arguments, Program currentProgram) {
|
|
if (currentProgram == null) {
|
|
return McpSchema.CallToolResult.builder()
|
|
.addTextContent("No program currently loaded")
|
|
.build();
|
|
}
|
|
|
|
String functionName = (String) arguments.get("function_name");
|
|
if (functionName == null) {
|
|
return McpSchema.CallToolResult.builder()
|
|
.addTextContent("Function name is required")
|
|
.build();
|
|
}
|
|
|
|
String info = getFunctionInfo(currentProgram, functionName);
|
|
return McpSchema.CallToolResult.builder()
|
|
.addTextContent(info)
|
|
.build();
|
|
}
|
|
|
|
private String getFunctionInfo(Program program, String functionName) {
|
|
var functionManager = program.getFunctionManager();
|
|
var functions = functionManager.getFunctions(true);
|
|
|
|
for (var function : functions) {
|
|
if (function.getName().equals(functionName)) {
|
|
StringBuilder info = new StringBuilder();
|
|
info.append("Function Information:\n");
|
|
info.append("Name: ").append(function.getName()).append("\n");
|
|
info.append("Entry Point: ").append(function.getEntryPoint()).append("\n");
|
|
info.append("Body: ").append(function.getBody()).append("\n");
|
|
info.append("Parameter Count: ").append(function.getParameterCount()).append("\n");
|
|
info.append("Return Type: ").append(function.getReturnType()).append("\n");
|
|
info.append("Signature: ").append(function.getSignature()).append("\n");
|
|
|
|
return info.toString();
|
|
}
|
|
}
|
|
|
|
return "Function not found: " + functionName;
|
|
}
|
|
} |