force_terminate
Terminate a running process by its PID to stop unresponsive tasks or free system resources.
Instructions
Force terminate
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes |
Implementation Reference
- src/tools/terminal_tools.js:267-310 (handler)Core implementation of forceTerminate - finds session by PID, kills the process tree using tree-kill, marks session as terminated, and returns success/failure.
async function forceTerminate(pid) { try { // Find session by PID let session = null; for (const [id, s] of sessions) { if (s.pid === pid) { session = s; break; } } if (!session) { return { success: false, message: `No session found with PID ${pid}` }; } // Kill the process tree (cross-platform) await new Promise((resolve, reject) => { treeKill(pid, undefined, (err) => { if (err) reject(err); else resolve(); }); }); session.status = 'terminated'; session.endTime = Date.now(); return { success: true, message: `Process ${pid} terminated successfully`, pid, sessionId: session.id }; } catch (error) { logger.error(`Error terminating process: ${error.message}`); return { success: false, message: error.message }; } } - src/mcp/server.js:99-99 (schema)Input schema for force_terminate tool - requires pid (number) as input.
{ name:'force_terminate', description:'Force terminate', inputSchema:{ type:'object', properties:{ pid:{type:'number'} }, required:['pid'] } }, - src/mcp/server.js:261-261 (registration)Registration/dispatch for force_terminate - routes incoming 'force_terminate' calls to terminalTools.forceTerminate(args.pid).
case 'force_terminate': data = await terminalTools.forceTerminate(args.pid); break; - src/tools/terminal_tools.js:2-2 (helper)Import of tree-kill library used by forceTerminate to kill process trees cross-platform.
const treeKill = require('tree-kill'); - src/tools/terminal_tools.js:459-468 (registration)Module export that exposes forceTerminate for use by server.js.
module.exports = { getConfig, setConfigValue, executeCommand, readOutput, forceTerminate, listSessions, listProcesses, killProcess };