kill_agent
Terminate an active agent session and clean up its resources to manage system resources and end collaboration processes.
Instructions
Terminate an active agent session and clean up its resources.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agentId | Yes | Session ID of the agent to kill |
Implementation Reference
- src/tools/kill-agent.ts:13-51 (handler)The handler logic for killing an agent session.
async (params) => { const { agentId } = params; const session = sessionManager.getSession(agentId); if (!session) { return { content: [ { type: 'text' as const, text: JSON.stringify({ error: `Session "${agentId}" not found.`, agentId, killed: false, }), }, ], isError: true, }; } const killed = sessionManager.killSession(agentId); sessionManager.removeSession(agentId); return { content: [ { type: 'text' as const, text: JSON.stringify({ agentId, killed, message: killed ? `Agent "${agentId}" has been terminated.` : `Agent "${agentId}" session removed (process was not running or already exited).`, }), }, ], }; } - src/tools/kill-agent.ts:9-11 (schema)Input schema for kill_agent tool.
{ agentId: z.string().describe('Session ID of the agent to kill'), }, - src/tools/kill-agent.ts:5-53 (registration)Registration function for the kill_agent tool.
export function registerKillAgent(server: McpServer, sessionManager: SessionManager): void { server.tool( 'kill_agent', 'Terminate an active agent session and clean up its resources.', { agentId: z.string().describe('Session ID of the agent to kill'), }, { readOnlyHint: false, destructiveHint: true }, async (params) => { const { agentId } = params; const session = sessionManager.getSession(agentId); if (!session) { return { content: [ { type: 'text' as const, text: JSON.stringify({ error: `Session "${agentId}" not found.`, agentId, killed: false, }), }, ], isError: true, }; } const killed = sessionManager.killSession(agentId); sessionManager.removeSession(agentId); return { content: [ { type: 'text' as const, text: JSON.stringify({ agentId, killed, message: killed ? `Agent "${agentId}" has been terminated.` : `Agent "${agentId}" session removed (process was not running or already exited).`, }), }, ], }; } ); }