force_terminate
Terminate a running terminal session by specifying the process ID (PID). Use this tool in Claude Desktop Commander MCP to manage active processes.
Instructions
Force terminate a running terminal session.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes |
Implementation Reference
- src/tools/execute.ts:47-62 (handler)The main handler function for the 'force_terminate' MCP tool. It validates input arguments using the schema, calls the terminal manager's forceTerminate method, and returns a formatted response with success or failure message.export async function forceTerminate(args: unknown) { const parsed = ForceTerminateArgsSchema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments for force_terminate: ${parsed.error}`); } 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/tools/schemas.ts:13-15 (schema)Zod schema defining the input structure for the force_terminate tool, requiring a single 'pid' property of type number.export const ForceTerminateArgsSchema = z.object({ pid: z.number(), });
- src/server.ts:72-77 (registration)Registration of the 'force_terminate' tool in the MCP server's tool list, specifying name, description, and input schema.{ name: "force_terminate", description: "Force terminate a running terminal session.", inputSchema: zodToJsonSchema(ForceTerminateArgsSchema), },
- src/terminal-manager.ts:106-123 (helper)Core implementation in TerminalManager that force-terminates a process by PID: first sends SIGINT, then SIGKILL after 1 second 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) { console.error(`Failed to terminate process ${pid}:`, error); return false; }