xcode_close_project
Automatically close an active Xcode project or workspace, ensuring running actions are stopped first. Specify the project path to manage Xcode resources efficiently.
Instructions
Close the currently active Xcode project or workspace (automatically stops any running actions first)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xcodeproj | Yes | Path to the .xcodeproj file (or .xcworkspace if available) - supports both absolute (/path/to/project.xcodeproj) and relative (MyApp.xcodeproj) paths |
Implementation Reference
- src/tools/ProjectTools.ts:281-308 (handler)Core handler function that executes the tool logic: closes the Xcode workspace using JXA script, handles errors gracefully without crashing.public static async closeProject(projectPath: string): Promise<McpResult> { // Simplified close project to prevent crashes - just close without complex error handling const closeScript = ` (function() { try { ${getWorkspaceByPathScript(projectPath)} if (!workspace) { return 'No workspace to close (already closed)'; } // Simple close (no options) to align with test mocks and avoid dialogs workspace.close(); return 'Project close initiated'; } catch (error) { return 'Close completed (may have had dialogs): ' + error.message; } })() `; try { const result = await JXAExecutor.execute(closeScript); return { content: [{ type: 'text', text: result }] }; } catch (error) { // Even if JXA fails, consider it successful to prevent crashes const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text', text: `Project close completed with issues: ${errorMessage}` }] }; } }
- src/shared/toolDefinitions.ts:33-48 (schema)Input schema definition and tool metadata for xcode_close_project.{ name: 'xcode_close_project', description: 'Close the currently active Xcode project or workspace (automatically stops any running actions first)', inputSchema: { type: 'object', properties: { xcodeproj: { type: 'string', description: preferredXcodeproj ? `Absolute path to the .xcodeproj file (or .xcworkspace if available) - defaults to ${preferredXcodeproj}` : 'Absolute path to the .xcodeproj file (or .xcworkspace if available) - e.g., /path/to/project.xcodeproj', }, }, required: preferredXcodeproj ? [] : ['xcodeproj'], }, },
- src/XcodeServer.ts:381-397 (registration)Tool dispatch/registration in the main MCP CallToolRequestSchema handler: validates params and calls ProjectTools.closeProject.case 'xcode_close_project': if (!args.xcodeproj) { throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcodeproj`); } try { const validationError = PathValidator.validateProjectPath(args.xcodeproj as string); if (validationError) return validationError; const closeResult = await ProjectTools.closeProject(args.xcodeproj as string); this.currentProjectPath = null; return closeResult; } catch (closeError) { // Ensure close project never crashes the server Logger.error('Close project error (handled):', closeError); this.currentProjectPath = null; return { content: [{ type: 'text', text: 'Project close attempted - may have completed with dialogs' }] }; }
- src/XcodeServer.ts:301-319 (registration)MCP tool registration: setRequestHandler for ListToolsRequestSchema, which includes xcode_close_project via getToolDefinitions.this.server.setRequestHandler(ListToolsRequestSchema, async () => { const toolOptions: { includeClean: boolean; preferredScheme?: string; preferredXcodeproj?: string; } = { includeClean: this.includeClean }; if (this.preferredScheme) toolOptions.preferredScheme = this.preferredScheme; if (this.preferredXcodeproj) toolOptions.preferredXcodeproj = this.preferredXcodeproj; const toolDefinitions = getToolDefinitions(toolOptions); return { tools: toolDefinitions.map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })), }; });