Files
mcp-windows/src/tools/process_kill.ts
T
Jonathan Miller 7cf3dbe420
Generic: Repo Health / Release configuration (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
feat: implement v1.1 system control tools (9 new tools)
- tools/process_kill.ts: windows_process_kill (#3)
- tools/service.ts: windows_service_list, windows_service_control (#4, #5)
- tools/audio_apps.ts: windows_audio_app_volumes (#8)
- tools/power.ts: windows_power_get, windows_power_action (#12, #13)
- tools/network.ts: windows_network_info (#22)
- tools/drives.ts: windows_drives, windows_file_search (#24, #25)

Total: 23 tools registered (v1.0 + v1.1 complete)

Authored-by: Moko Consulting
2026-05-25 21:17:45 -05:00

58 lines
1.6 KiB
TypeScript

/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Tool: windows_process_kill (#3)
*/
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { runPowerShell } from '../shell.js';
export function registerProcessKillTools(server: McpServer): void {
server.tool(
'windows_process_kill',
'Terminate running processes by PID or name.',
{
pid: z.number().optional().describe('Process ID to kill'),
name: z.string().optional().describe('Process name to kill (all matching)'),
force: z.boolean().default(false).describe('Force termination'),
},
async ({ pid, name, force }) => {
if (!pid && !name) {
return { content: [{ type: 'text', text: 'Provide either pid or name.' }], isError: true };
}
const forceFlag = force ? ' -Force' : '';
let ps: string;
if (pid) {
ps = `
$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue
if ($p) {
$n = $p.ProcessName
Stop-Process -Id ${pid}${forceFlag} -ErrorAction Stop
"Killed PID ${pid} ($n)"
} else {
"No process with PID ${pid}"
}`;
} else {
ps = `
$procs = Get-Process -Name '${name!.replace(/'/g, "''")}' -ErrorAction SilentlyContinue
if ($procs) {
$count = @($procs).Count
$procs | Stop-Process${forceFlag} -ErrorAction Stop
"Killed $count process(es) named '${name}'"
} else {
"No processes named '${name}'"
}`;
}
const result = await runPowerShell(ps);
return {
content: [{ type: 'text', text: result.stdout || result.stderr }],
isError: result.exitCode !== 0,
};
},
);
}