Skip to main content
Glama

swift_package_stop

Stop a running Swift Package executable by providing its process ID (PID) to ensure proper termination on the sl-test server.

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

  • The core handler function for 'swift_package_stop' that terminates the process by PID using SIGTERM followed by SIGKILL if necessary, and cleans up the activeProcesses map.
    async (params: { pid: number }): Promise<ToolResponse> => { const processInfo = activeProcesses.get(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 5 seconds to terminate gracefully await new Promise((resolve) => { let terminated = false; processInfo.process.on('exit', () => { terminated = true; resolve(true); }); setTimeout(() => { if (!terminated) { processInfo.process.kill('SIGKILL'); } resolve(true); }, 5000); }); activeProcesses.delete(params.pid); return { content: [ { type: 'text' as const, text: `✅ Stopped executable (was running since ${processInfo.startedAt.toISOString()})`, }, { type: 'text' as const, 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, 'SystemError'); } },
  • Zod input schema defining the required 'pid' parameter as a number.
    { pid: z.number().describe('Process ID (PID) of the running executable'), },
  • Local registration function registerStopSwiftPackageTool that sets up the tool 'swift_package_stop' with schema and handler using registerTool.
    export function registerStopSwiftPackageTool(server: McpServer): void { registerTool( server, 'swift_package_stop', 'Stops a running Swift Package executable started with swift_package_run', { pid: z.number().describe('Process ID (PID) of the running executable'), }, async (params: { pid: number }): Promise<ToolResponse> => { const processInfo = activeProcesses.get(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 5 seconds to terminate gracefully await new Promise((resolve) => { let terminated = false; processInfo.process.on('exit', () => { terminated = true; resolve(true); }); setTimeout(() => { if (!terminated) { processInfo.process.kill('SIGKILL'); } resolve(true); }, 5000); }); activeProcesses.delete(params.pid); return { content: [ { type: 'text' as const, text: `✅ Stopped executable (was running since ${processInfo.startedAt.toISOString()})`, }, { type: 'text' as const, 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, 'SystemError'); } }, ); }
  • Top-level registration entry that conditionally calls registerStopSwiftPackageTool based on environment variable.
    register: registerStopSwiftPackageTool, groups: [ToolGroup.SWIFT_PACKAGE_WORKFLOW], envVar: 'XCODEBUILDMCP_TOOL_SWIFT_PACKAGE_STOP', isWriteTool: true, },
  • Global Map tracking active Swift package processes by PID, used by run, list, and stop tools.
    // Store active processes so we can manage them - keyed by PID for uniqueness const activeProcesses = new Map< number, { process: ChildProcess; startedAt: Date; packagePath: string; executableName?: string } >();

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

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