Skip to main content
Glama

xcode_open_project

Open Xcode projects or workspaces from the command line to access development environments and initiate build processes.

Instructions

Open an Xcode project or workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xcodeprojYesAbsolute path to the .xcodeproj file (or .xcworkspace if available) - e.g., /path/to/project.xcodeproj

Implementation Reference

  • Core handler implementation: validates project path, prefers .xcworkspace over .xcodeproj, ensures Xcode is running, executes JXA script to open project in Xcode.
    public static async openProject(projectPath: string): Promise<McpResult> {
      const validationError = PathValidator.validateProjectPath(projectPath);
      if (validationError) return validationError;
      
      // Check for workspace preference: if we're opening a .xcodeproj file,
      // check if there's a corresponding .xcworkspace file in the same directory
      let actualPath = projectPath;
      if (projectPath.endsWith('.xcodeproj')) {
        const { existsSync } = await import('fs');
        const workspacePath = projectPath.replace(/\.xcodeproj$/, '.xcworkspace');
        if (existsSync(workspacePath)) {
          actualPath = workspacePath;
        }
      }
      
      // Ensure Xcode is running before trying to open project
      const xcodeError = await this.ensureXcodeIsRunning();
      if (xcodeError) return xcodeError;
      
      const script = `
        const app = Application('Xcode');
        app.open(${JSON.stringify(actualPath)});
        'Project opened successfully';
      `;
      
      try {
        const result = await JXAExecutor.execute(script);
        
        // If we automatically chose a workspace over a project, indicate this in the response
        if (actualPath !== projectPath && actualPath.endsWith('.xcworkspace')) {
          return { content: [{ type: 'text', text: `Opened workspace instead of project: ${result}` }] };
        }
        
        return { content: [{ type: 'text', text: result }] };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return { content: [{ type: 'text', text: `Failed to open project: ${errorMessage}` }] };
      }
    }
  • MCP CallToolRequestSchema dispatch handler: validates parameters, calls ProjectTools.openProject, updates currentProjectPath on success.
    case 'xcode_open_project':
      if (!args.xcodeproj) {
        throw new McpError(
          ErrorCode.InvalidParams,
          this.preferredXcodeproj 
            ? `Missing required parameter: xcodeproj (no preferred value was applied)\n\nšŸ’” Expected: absolute path to .xcodeproj or .xcworkspace file`
            : `Missing required parameter: xcodeproj\n\nšŸ’” Expected: absolute path to .xcodeproj or .xcworkspace file`
        );
      }
      const result = await ProjectTools.openProject(args.xcodeproj as string);
      if (result && 'content' in result && result.content?.[0] && 'text' in result.content[0]) {
        const textContent = result.content[0];
        if (textContent.type === 'text' && typeof textContent.text === 'string') {
          if (!textContent.text.includes('Error') && !textContent.text.includes('does not exist')) {
            this.currentProjectPath = args.xcodeproj as string;
          }
        }
      }
      return result;
  • Tool schema definition: inputSchema for xcodeproj parameter, description, and conditional required fields based on preferences.
    {
      name: 'xcode_open_project',
      description: 'Open an Xcode project or workspace',
      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'],
      },
    },
  • Registers tool list handler using getToolDefinitions which includes xcode_open_project schema.
    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
        })),
      };
    });
  • Helper method called by openProject to ensure Xcode is running before opening the project, launches if necessary.
    public static async ensureXcodeIsRunning(): Promise<McpResult | null> {
      // First check if Xcode is already running
      const checkScript = `
        (function() {
          try {
            const app = Application('Xcode');
            if (app.running()) {
              return 'Xcode is already running';
            } else {
              return 'Xcode is not running';
            }
          } catch (error) {
            return 'Xcode is not running: ' + error.message;
          }
        })()
      `;
      
      try {
        const checkResult = await JXAExecutor.execute(checkScript);
        if (checkResult.includes('already running')) {
          return null; // All good, Xcode is running
        }
      } catch (error) {
        // Continue to launch Xcode
      }
      
      // Get the Xcode path from xcode-select
      let xcodePath: string;
      try {
        const { spawn } = await import('child_process');
        const xcodeSelectResult = await new Promise<string>((resolve, reject) => {
          const process = spawn('xcode-select', ['-p']);
          let stdout = '';
          let stderr = '';
          
          process.stdout.on('data', (data) => {
            stdout += data.toString();
          });
          
          process.stderr.on('data', (data) => {
            stderr += data.toString();
          });
          
          process.on('close', (code) => {
            if (code === 0) {
              resolve(stdout.trim());
            } else {
              reject(new Error(`xcode-select failed with code ${code}: ${stderr}`));
            }
          });
        });
        
        if (!xcodeSelectResult || xcodeSelectResult.trim() === '') {
          return {
            content: [{
              type: 'text',
              text: 'āŒ No Xcode installation found\n\nšŸ’” To fix this:\n• Install Xcode from the Mac App Store\n• Run: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer'
            }]
          };
        }
        
        // Convert from Developer path to app path
        xcodePath = xcodeSelectResult.replace('/Contents/Developer', '');
        
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `āŒ Failed to determine Xcode path: ${error instanceof Error ? error.message : String(error)}\n\nšŸ’” Ensure Xcode is properly installed and xcode-select is configured`
          }]
        };
      }
      
      // Launch Xcode
      const launchScript = `
        (function() {
          try {
            const app = Application(${JSON.stringify(xcodePath)});
            app.launch();
            
            // Wait for Xcode to start
            let attempts = 0;
            while (!app.running() && attempts < 30) {
              delay(1);
              attempts++;
            }
            
            if (app.running()) {
              return 'Xcode launched successfully from ' + ${JSON.stringify(xcodePath)};
            } else {
              return 'Failed to launch Xcode - timed out after 30 seconds';
            }
          } catch (error) {
            return 'Failed to launch Xcode: ' + error.message;
          }
        })()
      `;
      
      try {
        const launchResult = await JXAExecutor.execute(launchScript);
        if (launchResult.includes('launched successfully')) {
          return null; // Success
        } else {
          return {
            content: [{
              type: 'text',
              text: `āŒ ${launchResult}\n\nšŸ’” Try:\n• Manually launching Xcode once\n• Checking Xcode installation\n• Ensuring sufficient system resources`
            }]
          };
        }
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `āŒ Failed to launch Xcode: ${error instanceof Error ? error.message : String(error)}`
          }]
        };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Open' implies an action that might launch an application or load a project, the description doesn't specify what 'open' means operationally (e.g., does it launch Xcode GUI, load in background, require specific permissions, or have side effects?). For a tool with no annotation coverage, this is a significant gap in explaining behavior beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the tool's purpose without unnecessary words. It's front-loaded with the core action ('Open') and resource, making it immediately scannable. Every word earns its place, with no redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete for a tool that performs an action like 'open'. It doesn't explain what happens after opening (e.g., success indicators, error conditions, or system state changes), nor does it address potential complexities like file permissions or Xcode availability. For a tool with no structured behavioral hints, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'xcodeproj' well-documented in the schema as an absolute path to .xcodeproj or .xcworkspace files. The description adds no additional parameter semantics beyond what's already in the schema (it only repeats 'Xcode project or workspace'). Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Open') and resource ('Xcode project or workspace'), making the tool's function immediately understandable. It distinguishes between .xcodeproj and .xcworkspace file types, which is helpful. However, it doesn't explicitly differentiate from sibling tools like 'xcode_open_file' or 'xcode_get_projects', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools available (e.g., 'xcode_open_file', 'xcode_get_projects', 'xcode_refresh_project'), there's no indication of prerequisites, when this tool is appropriate, or what distinguishes it from similar operations. This leaves the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/lapfelix/XcodeMCP'

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