force_terminate
Terminate unresponsive terminal sessions by process ID to free system resources and regain control of your command line interface.
Instructions
Force terminate a running terminal session.
This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes |
Implementation Reference
- src/handlers/terminal-handlers.ts:42-48 (handler)MCP handler function for the 'force_terminate' tool. Parses input arguments using the schema and delegates to the tool implementation./** * Handle force_terminate command */ export async function handleForceTerminate(args: unknown): Promise<ServerResult> { const parsed = ForceTerminateArgsSchema.parse(args); return forceTerminate(parsed); }
- Tool implementation that validates arguments, calls terminalManager.forceTerminate(pid), and formats the response.export async function forceTerminate(args: unknown): Promise<ServerResult> { const parsed = ForceTerminateArgsSchema.safeParse(args); if (!parsed.success) { return { content: [{ type: "text", text: `Error: Invalid arguments for force_terminate: ${parsed.error}` }], isError: true, }; } const success = terminalManager.forceTerminate(parsed.data.pid); return { content: [{ type: "text", text: success ? `Successfully initiated termination of session ${parsed.data.pid}` : `No active session found for PID ${parsed.data.pid}` }], }; }
- src/terminal-manager.ts:386-406 (helper)Core method in TerminalManager that force-terminates a process by PID: sends SIGINT, then SIGKILL after 1s if still active.forceTerminate(pid: number): boolean { const session = this.sessions.get(pid); if (!session) { return false; } try { session.process.kill('SIGINT'); setTimeout(() => { if (this.sessions.has(pid)) { session.process.kill('SIGKILL'); } }, 1000); return true; } catch (error) { // Convert error to string, handling both Error objects and other types const errorMessage = error instanceof Error ? error.message : String(error); capture('server_request_error', {error: errorMessage, message: `Failed to terminate process ${pid}:`}); return false; } }
- src/tools/schemas.ts:34-36 (schema)Zod schema defining the input for force_terminate: requires a numeric PID.export const ForceTerminateArgsSchema = z.object({ pid: z.number(), });