force_terminate
Terminate a running terminal session by specifying its process ID to stop unresponsive or unwanted processes.
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/server.ts:1254-1256 (registration)Dispatch handler for the 'force_terminate' tool call in MCP server request handlercase "force_terminate": result = await handlers.handleForceTerminate(args); break;
- src/server.ts:908-921 (registration)Tool registration in list_tools handler defining name, description, input schema, and annotations for 'force_terminate'{ name: "force_terminate", description: ` Force terminate a running terminal session. ${CMD_PREFIX_DESCRIPTION}`, inputSchema: zodToJsonSchema(ForceTerminateArgsSchema), annotations: { title: "Force Terminate Process", readOnlyHint: false, destructiveHint: true, openWorldHint: false, }, },
- src/handlers/terminal-handlers.ts:42-48 (handler)MCP tool handler function that validates input with schema and delegates to forceTerminate implementation/** * Handle force_terminate command */ export async function handleForceTerminate(args: unknown): Promise<ServerResult> { const parsed = ForceTerminateArgsSchema.parse(args); return forceTerminate(parsed); }
- src/tools/schemas.ts:36-38 (schema)Zod schema defining input parameters for force_terminate tool (requires pid: number)export const ForceTerminateArgsSchema = z.object({ pid: z.number(), });
- Core forceTerminate function that handles argument parsing, virtual sessions, and delegates to terminalManager.forceTerminateexport 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 pid = parsed.data.pid; // Handle virtual Node.js sessions (node:local) if (virtualNodeSessions.has(pid)) { virtualNodeSessions.delete(pid); return { content: [{ type: "text", text: `Cleared virtual Node.js session ${pid}` }], }; } const success = terminalManager.forceTerminate(pid); return { content: [{ type: "text", text: success ? `Successfully initiated termination of session ${pid}` : `No active session found for PID ${pid}` }], }; }
- src/terminal-manager.ts:591-611 (helper)TerminalManager.forceTerminate method that sends SIGINT followed by SIGKILL if needed to terminate the processforceTerminate(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; } }