kill_process
Stop a background AI agent process by specifying its PID for lifecycle control.
Instructions
Terminate a running AI agent process by PID.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | The process ID to terminate. |
Implementation Reference
- src/app/mcp.ts:272-283 (schema)Schema definition (name, description, inputSchema) for the 'kill_process' tool, registered alongside other tools.
name: 'kill_process', description: 'Terminate a running AI agent process by PID.', inputSchema: { type: 'object', properties: { pid: { type: 'number', description: 'The process ID to terminate.', }, }, required: ['pid'], }, - src/app/mcp.ts:329-330 (registration)Registration: dispatches the 'kill_process' tool name to handleKillProcess in the CallToolRequest handler.
case 'kill_process': return this.handleKillProcess(toolArguments); - src/app/mcp.ts:456-477 (handler)Handler function that validates the 'pid' argument and delegates to processService.killProcess(). Returns the response as JSON.
private async handleKillProcess(toolArguments: any): Promise<ServerResult> { if (!toolArguments.pid || typeof toolArguments.pid !== 'number') { throw new McpError(ErrorCode.InvalidParams, 'Missing or invalid required parameter: pid'); } const pid = toolArguments.pid; try { const response = this.processService.killProcess(pid); return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }] }; } catch (error: any) { const code = /not found/.test(error.message) ? ErrorCode.InvalidParams : ErrorCode.InternalError; const message = code === ErrorCode.InternalError ? `Failed to terminate process: ${error.message}` : error.message; throw new McpError(code, message); } } - src/process-service.ts:327-350 (helper)Helper/implementation method in ProcessService that looks up the tracked process by PID, kills it with SIGTERM, marks it as 'failed', appends termination message to stderr, and returns the result.
killProcess(pid: number): { pid: number; status: string; message: string } { const processEntry = this.processManager.get(pid); if (!processEntry) { throw new Error(`Process with PID ${pid} not found`); } if (processEntry.status !== 'running') { return { pid, status: processEntry.status, message: 'Process already terminated', }; } processEntry.process.kill('SIGTERM'); processEntry.status = 'failed'; processEntry.stderr += '\nProcess terminated by user'; return { pid, status: 'terminated', message: 'Process terminated successfully', }; }