xcode_close_project
Close active Xcode projects or workspaces to free system resources and prepare for new tasks. Automatically stops any running actions first for clean project management.
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 | Absolute path to the .xcodeproj file (or .xcworkspace if available) - e.g., /path/to/project.xcodeproj |
Implementation Reference
- src/tools/ProjectTools.ts:281-308 (handler)Core handler function implementing the tool logic: validates path, executes JXA script to close the Xcode workspace/project, handles errors gracefully.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/XcodeServer.ts:381-397 (handler)MCP server dispatch handler: handles callTool requests for 'xcode_close_project', validates parameters, calls ProjectTools.closeProject, manages current project state.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/shared/toolDefinitions.ts:33-47 (schema)Tool schema definition including name, description, and input schema used by the MCP server for listTools and validation.{ 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:301-319 (registration)Server registration of all tools including 'xcode_close_project' via getToolDefinitions for the MCP listTools endpoint.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 })), }; });