Skip to main content
Glama

build_mac_ws

Build macOS applications from Xcode workspaces using xcodebuild with configurable schemes, architectures, and build settings.

Instructions

Builds a macOS app using xcodebuild from a workspace.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspacePathYesPath to the .xcworkspace file (Required)
schemeYesThe scheme to use (Required)
configurationNoBuild configuration (Debug, Release, etc.)
derivedDataPathNoPath where build products and other derived data will go
archNoArchitecture to build for (arm64 or x86_64). For macOS only.
extraArgsNoAdditional xcodebuild arguments
preferXcodebuildNoIf true, prefers xcodebuild over the experimental incremental build system, useful for when incremental build system fails.

Implementation Reference

  • Primary internal handler for the build_mac_ws tool. Executes the macOS-specific build logic by calling executeXcodeBuildCommand with platform: XcodePlatform.macOS.
    async function _handleMacOSBuildLogic(params: {
      workspacePath?: string;
      projectPath?: string;
      scheme: string;
      configuration: string;
      derivedDataPath?: string;
      arch?: string;
      extraArgs?: string[];
      preferXcodebuild?: boolean;
    }): Promise<ToolResponse> {
      log('info', `Starting macOS build for scheme ${params.scheme} (internal)`);
    
      return executeXcodeBuildCommand(
        {
          ...params,
        },
        {
          platform: XcodePlatform.macOS,
          arch: params.arch,
          logPrefix: 'macOS Build',
        },
        params.preferXcodebuild,
        'build',
      );
    }
  • Registers the 'build_mac_ws' MCP tool on the server using registerTool, defining name, description, input schema, and handler function.
    registerTool<WorkspaceParams>(
      server,
      'build_mac_ws',
      'Builds a macOS app using xcodebuild from a workspace.',
      {
        workspacePath: workspacePathSchema,
        scheme: schemeSchema,
        configuration: configurationSchema,
        derivedDataPath: derivedDataPathSchema,
        arch: archSchema,
        extraArgs: extraArgsSchema,
        preferXcodebuild: preferXcodebuildSchema,
      },
      async (params) =>
        _handleMacOSBuildLogic({
          ...params,
          configuration: params.configuration ?? 'Debug',
          preferXcodebuild: params.preferXcodebuild ?? false,
        }),
    );
  • Zod schema for the optional 'arch' parameter specific to macOS builds.
    const archSchema = z
      .enum(['arm64', 'x86_64'])
      .optional()
      .describe('Architecture to build for (arm64 or x86_64). For macOS only.');
  • Core helper function called by the handler to execute the actual xcodebuild command (or xcodemake/make for incremental builds), parse output, extract warnings/errors, and format the tool response.
    export async function executeXcodeBuildCommand(
      params: SharedBuildParams,
      platformOptions: PlatformBuildOptions,
      preferXcodebuild: boolean = false,
      buildAction: string = 'build',
    ): Promise<ToolResponse> {
      // Collect warnings, errors, and stderr messages from the build output
      const buildMessages: { type: 'text'; text: string }[] = [];
      function grepWarningsAndErrors(text: string): { type: 'warning' | 'error'; content: string }[] {
        return text
          .split('\n')
          .map((content) => {
            if (/warning:/i.test(content)) return { type: 'warning', content };
            if (/error:/i.test(content)) return { type: 'error', content };
            return null;
          })
          .filter(Boolean) as { type: 'warning' | 'error'; content: string }[];
      }
    
      log('info', `Starting ${platformOptions.logPrefix} ${buildAction} for scheme ${params.scheme}`);
    
      // Check if xcodemake is enabled and available
      const isXcodemakeEnabledFlag = isXcodemakeEnabled();
      let xcodemakeAvailableFlag = false;
    
      if (isXcodemakeEnabledFlag && buildAction === 'build') {
        xcodemakeAvailableFlag = await isXcodemakeAvailable();
    
        if (xcodemakeAvailableFlag && preferXcodebuild) {
          log(
            'info',
            'xcodemake is enabled but preferXcodebuild is set to true. Falling back to xcodebuild.',
          );
          buildMessages.push({
            type: 'text',
            text: '⚠️ incremental build support is enabled but preferXcodebuild is set to true. Falling back to xcodebuild.',
          });
        } else if (!xcodemakeAvailableFlag) {
          buildMessages.push({
            type: 'text',
            text: '⚠️ xcodemake is enabled but not available. Falling back to xcodebuild.',
          });
          log('info', 'xcodemake is enabled but not available. Falling back to xcodebuild.');
        } else {
          log('info', 'xcodemake is enabled and available, using it for incremental builds.');
          buildMessages.push({
            type: 'text',
            text: 'ℹ️ xcodemake is enabled and available, using it for incremental builds.',
          });
        }
      }
    
      try {
        const command = ['xcodebuild'];
    
        let projectDir = '';
        if (params.workspacePath) {
          projectDir = path.dirname(params.workspacePath);
          command.push('-workspace', params.workspacePath);
        } else if (params.projectPath) {
          projectDir = path.dirname(params.projectPath);
          command.push('-project', params.projectPath);
        }
    
        command.push('-scheme', params.scheme);
        command.push('-configuration', params.configuration);
        command.push('-skipMacroValidation');
    
        // Construct destination string based on platform
        let destinationString: string;
        const isSimulatorPlatform = [
          XcodePlatform.iOSSimulator,
          XcodePlatform.watchOSSimulator,
          XcodePlatform.tvOSSimulator,
          XcodePlatform.visionOSSimulator,
        ].includes(platformOptions.platform);
    
        if (isSimulatorPlatform) {
          if (platformOptions.simulatorId) {
            destinationString = constructDestinationString(
              platformOptions.platform,
              undefined,
              platformOptions.simulatorId,
            );
          } else if (platformOptions.simulatorName) {
            destinationString = constructDestinationString(
              platformOptions.platform,
              platformOptions.simulatorName,
              undefined,
              platformOptions.useLatestOS,
            );
          } else {
            return createTextResponse(
              `For ${platformOptions.platform} platform, either simulatorId or simulatorName must be provided`,
              true,
            );
          }
        } else if (platformOptions.platform === XcodePlatform.macOS) {
          destinationString = constructDestinationString(
            platformOptions.platform,
            undefined,
            undefined,
            false,
            platformOptions.arch,
          );
        } else if (platformOptions.platform === XcodePlatform.iOS) {
          destinationString = 'generic/platform=iOS';
        } else if (platformOptions.platform === XcodePlatform.watchOS) {
          destinationString = 'generic/platform=watchOS';
        } else if (platformOptions.platform === XcodePlatform.tvOS) {
          destinationString = 'generic/platform=tvOS';
        } else if (platformOptions.platform === XcodePlatform.visionOS) {
          destinationString = 'generic/platform=visionOS';
        } else {
          return createTextResponse(`Unsupported platform: ${platformOptions.platform}`, true);
        }
    
        command.push('-destination', destinationString);
    
        if (params.derivedDataPath) {
          command.push('-derivedDataPath', params.derivedDataPath);
        }
    
        if (params.extraArgs && params.extraArgs.length > 0) {
          command.push(...params.extraArgs);
        }
    
        command.push(buildAction);
    
        // Execute the command using xcodemake or xcodebuild
        let result;
        if (
          isXcodemakeEnabledFlag &&
          xcodemakeAvailableFlag &&
          buildAction === 'build' &&
          !preferXcodebuild
        ) {
          // Check if Makefile already exists
          const makefileExists = doesMakefileExist(projectDir);
          log('debug', 'Makefile exists: ' + makefileExists);
    
          // Check if Makefile log already exists
          const makeLogFileExists = doesMakeLogFileExist(projectDir, command);
          log('debug', 'Makefile log exists: ' + makeLogFileExists);
    
          if (makefileExists && makeLogFileExists) {
            // Use make for incremental builds
            buildMessages.push({
              type: 'text',
              text: 'ℹ️ Using make for incremental build',
            });
            result = await executeMakeCommand(projectDir, platformOptions.logPrefix);
          } else {
            // Generate Makefile using xcodemake
            buildMessages.push({
              type: 'text',
              text: 'ℹ️ Generating Makefile with xcodemake (first build may take longer)',
            });
            // Remove 'xcodebuild' from the command array before passing to executeXcodemakeCommand
            result = await executeXcodemakeCommand(
              projectDir,
              command.slice(1),
              platformOptions.logPrefix,
            );
          }
        } else {
          // Use standard xcodebuild
          result = await executeCommand(command, platformOptions.logPrefix);
        }
    
        // Grep warnings and errors from stdout (build output)
        const warningOrErrorLines = grepWarningsAndErrors(result.output);
        warningOrErrorLines.forEach(({ type, content }) => {
          buildMessages.push({
            type: 'text',
            text: type === 'warning' ? `⚠️ Warning: ${content}` : `❌ Error: ${content}`,
          });
        });
    
        // Include all stderr lines as errors
        if (result.error) {
          result.error.split('\n').forEach((content) => {
            if (content.trim()) {
              buildMessages.push({ type: 'text', text: `❌ [stderr] ${content}` });
            }
          });
        }
    
        if (!result.success) {
          log('error', `${platformOptions.logPrefix} ${buildAction} failed: ${result.error}`);
    
          // Create concise error response with warnings/errors included
          const errorResponse = createTextResponse(
            `❌ ${platformOptions.logPrefix} ${buildAction} failed for scheme ${params.scheme}.`,
            true,
          );
    
          if (buildMessages.length > 0 && errorResponse.content) {
            errorResponse.content.unshift(...buildMessages);
          }
    
          // If using xcodemake and build failed but no compiling errors, suggest using xcodebuild
          if (
            warningOrErrorLines.length == 0 &&
            isXcodemakeEnabledFlag &&
            xcodemakeAvailableFlag &&
            buildAction === 'build' &&
            !preferXcodebuild
          ) {
            errorResponse.content.push({
              type: 'text',
              text: `💡 Incremental build using xcodemake failed, suggest using preferXcodebuild option to try build again using slower xcodebuild command.`,
            });
          }
    
          return errorResponse;
        }
    
        log('info', `✅ ${platformOptions.logPrefix} ${buildAction} succeeded.`);
    
        // Create additional info based on platform and action
        let additionalInfo = '';
    
        // Add xcodemake info if relevant
        if (
          isXcodemakeEnabledFlag &&
          xcodemakeAvailableFlag &&
          buildAction === 'build' &&
          !preferXcodebuild
        ) {
          additionalInfo += `xcodemake: Using faster incremental builds with xcodemake. 
    Future builds will use the generated Makefile for improved performance.
    
    `;
        }
    
        // Only show next steps for 'build' action
        if (buildAction === 'build') {
          if (platformOptions.platform === XcodePlatform.macOS) {
            additionalInfo = `Next Steps:
    1. Get App Path: get_macos_app_path_${params.workspacePath ? 'workspace' : 'project'}
    2. Get Bundle ID: get_macos_bundle_id
    3. Launch App: launch_macos_app`;
          } else if (platformOptions.platform === XcodePlatform.iOS) {
            additionalInfo = `Next Steps:
    1. Get App Path: get_ios_device_app_path_${params.workspacePath ? 'workspace' : 'project'}
    2. Get Bundle ID: get_ios_bundle_id`;
          } else if (isSimulatorPlatform) {
            const idOrName = platformOptions.simulatorId ? 'id' : 'name';
            const simIdParam = platformOptions.simulatorId ? 'simulatorId' : 'simulatorName';
            const simIdValue = platformOptions.simulatorId || platformOptions.simulatorName;
    
            additionalInfo = `Next Steps:
    1. Get App Path: get_simulator_app_path_by_${idOrName}_${params.workspacePath ? 'workspace' : 'project'}({ ${simIdParam}: '${simIdValue}', scheme: '${params.scheme}' })
    2. Get Bundle ID: get_ios_bundle_id({ appPath: 'APP_PATH_FROM_STEP_1' })
    3. Choose one of the following options:
       - Option 1: Launch app normally:
         launch_app_in_simulator({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID' })
       - Option 2: Launch app with logs (captures both console and structured logs):
         launch_app_with_logs_in_simulator({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID' })
       - Option 3: Launch app normally, then capture structured logs only:
         launch_app_in_simulator({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID' })
         start_simulator_log_capture({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID' })
       - Option 4: Launch app normally, then capture all logs (will restart app):
         launch_app_in_simulator({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID' })
         start_simulator_log_capture({ simulatorUuid: 'SIMULATOR_UUID', bundleId: 'APP_BUNDLE_ID', captureConsole: true })
    
    When done capturing logs, use: stop_and_get_simulator_log({ logSessionId: 'SESSION_ID' })`;
          }
        }
    
        const successResponse: ToolResponse = {
          content: [
            ...buildMessages,
            {
              type: 'text',
              text: `✅ ${platformOptions.logPrefix} ${buildAction} succeeded for scheme ${params.scheme}.`,
            },
          ],
        };
    
        // Only add additional info if we have any
        if (additionalInfo) {
          successResponse.content.push({
            type: 'text',
            text: additionalInfo,
          });
        }
    
        return successResponse;
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        log('error', `Error during ${platformOptions.logPrefix} ${buildAction}: ${errorMessage}`);
        return createTextResponse(
          `Error during ${platformOptions.logPrefix} ${buildAction}: ${errorMessage}`,
          true,
        );
      }
    }
  • Top-level inclusion of the macOS workspace build tool registration in the central tool registration system.
      register: registerMacOSBuildWorkspaceTool,
      groups: [ToolGroup.MACOS_WORKFLOW],
      envVar: 'XCODEBUILDMCP_TOOL_MACOS_BUILD_WORKSPACE',
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the tool 'Builds a macOS app using xcodebuild' but doesn't describe what happens during execution (e.g., compilation process, output location, error handling), whether it requires specific environment setup, or what the expected outcome is. This leaves significant gaps for a build tool with potential complexity.

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 core purpose without unnecessary words. It's appropriately sized for a tool with good schema documentation and gets straight to the point with zero waste.

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?

For a build tool with 7 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool produces (e.g., where the built app ends up), what happens on success/failure, or any prerequisites (e.g., Xcode installation). The combination of missing behavioral context and lack of output information creates significant gaps.

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%, so the schema already documents all 7 parameters thoroughly. The description adds no additional parameter context beyond what's in the schema (e.g., no examples of typical 'extraArgs', no explanation of when 'preferXcodebuild' is needed beyond what the schema says). Baseline 3 is appropriate when 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 action ('Builds') and target ('macOS app using xcodebuild from a workspace'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'build_mac_proj' or 'build_run_mac_ws', which would require mentioning workspace vs project builds or build-only vs build-and-run distinctions.

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 multiple sibling tools for building macOS and iOS apps (e.g., 'build_mac_proj', 'build_run_mac_ws'), there's no indication of when a workspace-based build is preferred over project-based, or when to use build-only versus build-and-run variants.

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

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