force_terminate
Terminate any active terminal session by specifying its process ID using this MCP server command. Ideal for stopping unresponsive or unwanted processes directly from the Claude Desktop Commander 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 tool handler: parses arguments using schema and delegates to forceTerminate tool function/** * Handle force_terminate command */ export async function handleForceTerminate(args: unknown): Promise<ServerResult> { const parsed = ForceTerminateArgsSchema.parse(args); return forceTerminate(parsed); }
- Core tool function: validates args, calls terminalManager.forceTerminate(pid), returns success messageexport 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)TerminalManager method: sends SIGINT to process, falls back to SIGKILL after 1s if still runningforceTerminate(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 input schema requiring 'pid' numberexport const ForceTerminateArgsSchema = z.object({ pid: z.number(), });
- src/server.ts:1217-1220 (registration)Dispatch in MCP call_tool request handler to terminal-handlers.handleForceTerminateresult = await handlers.handleForceTerminate(args); break; case "list_sessions":
- src/server.ts:868-881 (registration)Tool definition in MCP list_tools response: name, description, schema reference, annotationsname: "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, }, }, {