Skip to main content
Glama

swift_package_stop

Terminate a running Swift Package executable by specifying its process ID (PID) using this tool. Integrates with XcodeBuildMCP for efficient process management.

Instructions

Stops a running Swift Package executable started with swift_package_run

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pidYesProcess ID (PID) of the running executable

Implementation Reference

  • Defines the Zod schema for input parameters (pid) of the swift_package_stop tool.
    const swiftPackageStopSchema = z.object({
      pid: z.number().describe('Process ID (PID) of the running executable'),
    });
  • Core handler function that stops the Swift Package process by PID: retrieves process info, sends SIGTERM/SIGKILL, removes from active list, and returns response.
    export async function swift_package_stopLogic(
      params: SwiftPackageStopParams,
      processManager: ProcessManager = getDefaultProcessManager(),
      timeout: number = 5000,
    ): Promise<ToolResponse> {
      const processInfo = processManager.getProcess(params.pid);
      if (!processInfo) {
        return createTextResponse(
          `⚠️ No running process found with PID ${params.pid}. Use swift_package_run to check active processes.`,
          true,
        );
      }
    
      try {
        processInfo.process.kill('SIGTERM');
    
        // Give it time to terminate gracefully (configurable for testing)
        await new Promise((resolve) => {
          let terminated = false;
    
          processInfo.process.on('exit', () => {
            terminated = true;
            resolve(true);
          });
    
          setTimeout(() => {
            if (!terminated) {
              processInfo.process.kill('SIGKILL');
            }
            resolve(true);
          }, timeout);
        });
    
        processManager.removeProcess(params.pid);
    
        return {
          content: [
            {
              type: 'text',
              text: `✅ Stopped executable (was running since ${processInfo.startedAt.toISOString()})`,
            },
            {
              type: 'text',
              text: `💡 Process terminated. You can now run swift_package_run again if needed.`,
            },
          ],
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return createErrorResponse('Failed to stop process', message);
      }
    }
  • Default export registering the tool with name, description, schema, and a thin handler that validates inputs and delegates to the core logic.
    export default {
      name: 'swift_package_stop',
      description: 'Stops a running Swift Package executable started with swift_package_run',
      schema: swiftPackageStopSchema.shape, // MCP SDK compatibility
      async handler(args: Record<string, unknown>): Promise<ToolResponse> {
        // Validate parameters using Zod
        const parseResult = swiftPackageStopSchema.safeParse(args);
        if (!parseResult.success) {
          return createErrorResponse(
            'Parameter validation failed',
            parseResult.error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', '),
          );
        }
    
        return swift_package_stopLogic(parseResult.data);
      },
    };
Install Server

Other Tools

Related Tools

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/cameroncooke/XcodeBuildMCP'

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