index.js•3.55 kB
export const TOOLS = [
{
name: "start_tomcat",
description: "Launch Tomcat via Gradle",
inputSchema: {
type: "object",
properties: {
gradle_command: {
type: "string",
description: "Gradle command to run (default: appRun)",
default: "appRun"
},
working_directory: {
type: "string",
description: "Working directory for the Gradle command"
}
}
}
},
{
name: "stop_tomcat",
description: "Terminate Tomcat process",
inputSchema: {
type: "object",
properties: {
force: {
type: "boolean",
description: "Force termination with SIGKILL",
default: false
}
}
}
},
{
name: "restart_tomcat",
description: "Stop and start Tomcat",
inputSchema: {
type: "object",
properties: {
force: {
type: "boolean",
description: "Force termination during stop",
default: false
},
gradle_command: {
type: "string",
description: "Gradle command for restart (default: appRun)"
}
}
}
},
{
name: "get_tomcat_status",
description: "Check Tomcat process status",
inputSchema: {
type: "object",
properties: {}
}
},
{
name: "get_logs",
description: "Retrieve log entries",
inputSchema: {
type: "object",
properties: {
lines: {
type: "number",
description: "Number of recent log lines to retrieve (default: 100)",
default: 100
},
level: {
type: "string",
description: "Minimum log level (DEBUG, INFO, WARN, ERROR)",
enum: ["DEBUG", "INFO", "WARN", "ERROR"]
},
since: {
type: "string",
description: "ISO 8601 timestamp to filter logs from"
},
source: {
type: "string",
description: "Filter by log source (stdout, stderr)",
enum: ["stdout", "stderr"]
}
}
}
},
{
name: "clear_logs",
description: "Clear log buffer and files",
inputSchema: {
type: "object",
properties: {
confirm: {
type: "boolean",
description: "Confirmation required to clear logs",
default: false
}
},
required: ["confirm"]
}
}
];
export async function handleToolCall(name, args, processManager, logManager) {
try {
switch (name) {
case "start_tomcat":
return await processManager.startTomcat(
args.gradle_command,
args.working_directory
);
case "stop_tomcat":
return await processManager.stopTomcat(args.force);
case "restart_tomcat":
return await processManager.restartTomcat(
args.force,
args.gradle_command
);
case "get_tomcat_status":
return processManager.getStatus();
case "get_logs":
return logManager.getLogs({
lines: args.lines,
level: args.level,
since: args.since,
source: args.source
});
case "clear_logs":
if (!args.confirm) {
throw new Error("Confirmation required to clear logs. Set confirm=true");
}
return logManager.clearLogs();
default:
throw new Error(`Unknown tool: ${name}`);
}
} catch (error) {
return {
error: true,
message: error.message,
stack: error.stack
};
}
}