Skip to main content
Glama

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
NameRequiredDescriptionDefault
agentIdYesSession ID of the agent to kill

Implementation Reference

  • 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).`,
            }),
          },
        ],
      };
    }
  • Input schema for kill_agent tool.
    {
      agentId: z.string().describe('Session ID of the agent to kill'),
    },
  • 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).`,
                }),
              },
            ],
          };
        }
      );
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikusnuz/agent-link-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server