Skip to main content
Glama

force_terminate

Destructive

Terminate a running terminal session by specifying its process ID to stop unresponsive or unwanted processes.

Instructions

                    Force terminate a running terminal session.
                    
                    This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYes

Implementation Reference

  • Dispatch handler for the 'force_terminate' tool call in MCP server request handler
    case "force_terminate":
        result = await handlers.handleForceTerminate(args);
        break;
  • src/server.ts:908-921 (registration)
    Tool registration in list_tools handler defining name, description, input schema, and annotations for 'force_terminate'
    {
        name: "force_terminate",
        description: `
                Force terminate a running terminal session.
                
                ${CMD_PREFIX_DESCRIPTION}`,
        inputSchema: zodToJsonSchema(ForceTerminateArgsSchema),
        annotations: {
            title: "Force Terminate Process",
            readOnlyHint: false,
            destructiveHint: true,
            openWorldHint: false,
        },
    },
  • MCP tool handler function that validates input with schema and delegates to forceTerminate implementation
    /**
     * Handle force_terminate command
     */
    export async function handleForceTerminate(args: unknown): Promise<ServerResult> {
        const parsed = ForceTerminateArgsSchema.parse(args);
        return forceTerminate(parsed);
    }
  • Zod schema defining input parameters for force_terminate tool (requires pid: number)
    export const ForceTerminateArgsSchema = z.object({
      pid: z.number(),
    });
  • Core forceTerminate function that handles argument parsing, virtual sessions, and delegates to terminalManager.forceTerminate
    export async function forceTerminate(args: unknown): Promise<ServerResult> {
      const parsed = ForceTerminateArgsSchema.safeParse(args);
      if (!parsed.success) {
        return {
          content: [{ type: "text", text: `Error: Invalid arguments for force_terminate: ${parsed.error}` }],
          isError: true,
        };
      }
    
      const pid = parsed.data.pid;
    
      // Handle virtual Node.js sessions (node:local)
      if (virtualNodeSessions.has(pid)) {
        virtualNodeSessions.delete(pid);
        return {
          content: [{
            type: "text",
            text: `Cleared virtual Node.js session ${pid}`
          }],
        };
      }
    
      const success = terminalManager.forceTerminate(pid);
      return {
        content: [{
          type: "text",
          text: success
            ? `Successfully initiated termination of session ${pid}`
            : `No active session found for PID ${pid}`
        }],
      };
    }
  • TerminalManager.forceTerminate method that sends SIGINT followed by SIGKILL if needed to terminate the process
    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) {
          // Convert error to string, handling both Error objects and other types
          const errorMessage = error instanceof Error ? error.message : String(error);
          capture('server_request_error', {error: errorMessage, message: `Failed to terminate process ${pid}:`});
          return false;
        }
    }

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/wonderwhy-er/ClaudeComputerCommander'

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