Skip to main content
Glama

xcode_set_active_scheme

Set the active scheme for an Xcode project to control which build configuration and targets are used for building, testing, or running the application.

Instructions

Set the active scheme for a specific project

Input Schema

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

Implementation Reference

  • Core implementation of xcode_set_active_scheme: validates path, opens project, normalizes scheme name, finds matching scheme via JXA, sets workspace.activeScheme, handles scheme not found with fuzzy matching suggestions.
    public static async setActiveScheme(
      projectPath: string, 
      schemeName: string, 
      openProject: OpenProjectCallback
    ): Promise<McpResult> {
      const validationError = PathValidator.validateProjectPath(projectPath);
      if (validationError) return validationError;
    
      await openProject(projectPath);
    
      // Normalize the scheme name for better matching
      const normalizedSchemeName = ParameterNormalizer.normalizeSchemeName(schemeName);
    
      const script = `
        (function() {
          ${getWorkspaceByPathScript(projectPath)}
          
          const schemes = workspace.schemes();
          const schemeNames = schemes.map(scheme => scheme.name());
          
          // Try exact match first
          let targetScheme = schemes.find(scheme => scheme.name() === ${JSON.stringify(normalizedSchemeName)});
          
          // If not found, try original name
          if (!targetScheme) {
            targetScheme = schemes.find(scheme => scheme.name() === ${JSON.stringify(schemeName)});
          }
          
          if (!targetScheme) {
            throw new Error('Scheme not found. Available: ' + JSON.stringify(schemeNames));
          }
          
          workspace.activeScheme = targetScheme;
          return 'Active scheme set to: ' + targetScheme.name();
        })()
      `;
      
      try {
        const result = await JXAExecutor.execute(script);
        return { content: [{ type: 'text', text: result }] };
      } catch (error) {
        const enhancedError = ErrorHelper.parseCommonErrors(error as Error);
        if (enhancedError) {
          return { content: [{ type: 'text', text: enhancedError }] };
        }
        
        const errorMessage = error instanceof Error ? error.message : String(error);
        if (errorMessage.includes('not found')) {
          try {
            // Extract available schemes from error message if present
            let availableSchemes: string[] = [];
            if (errorMessage.includes('Available:')) {
              const availablePart = errorMessage.split('Available: ')[1];
              // Find the JSON array part
              const jsonMatch = availablePart?.match(/\[.*?\]/);
              if (jsonMatch) {
                availableSchemes = JSON.parse(jsonMatch[0]);
              }
            }
              
            // Try to find a close match with fuzzy matching
            const bestMatch = ParameterNormalizer.findBestMatch(schemeName, availableSchemes);
            let guidance = ErrorHelper.getSchemeNotFoundGuidance(schemeName, availableSchemes);
            
            if (bestMatch && bestMatch !== schemeName) {
              guidance += `\n• Did you mean '${bestMatch}'?`;
            }
            
            return { content: [{ type: 'text', text: ErrorHelper.createErrorWithGuidance(`Scheme '${schemeName}' not found`, guidance) }] };
          } catch {
            return { content: [{ type: 'text', text: ErrorHelper.createErrorWithGuidance(`Scheme '${schemeName}' not found`, ErrorHelper.getSchemeNotFoundGuidance(schemeName)) }] };
          }
        }
        
        return { content: [{ type: 'text', text: `Failed to set active scheme: ${errorMessage}` }] };
      }
    }
  • MCP server dispatcher: handles tool call, validates parameters, delegates to ProjectTools.setActiveScheme
    case 'xcode_set_active_scheme':
      if (!args.xcodeproj) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: xcodeproj`);
      }
      if (!args.scheme_name) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: scheme_name`);
      }
      return await ProjectTools.setActiveScheme(
        args.xcodeproj as string, 
        args.scheme_name as string, 
        this.openProject.bind(this)
      );
  • Input schema definition: requires xcodeproj (unless preferred) and scheme_name, with descriptions
      name: 'xcode_set_active_scheme',
      description: 'Set the active scheme for a specific project',
      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',
          },
          scheme_name: {
            type: 'string',
            description: 'Name of the scheme to activate',
          },
        },
        required: preferredXcodeproj ? ['scheme_name'] : ['xcodeproj', 'scheme_name'],
      },
    },
  • Tool registration: dynamically registers all tools from getToolDefinitions including xcode_set_active_scheme schema in MCP listTools handler
    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
        })),
      };
  • Tool categorization: groups xcode_set_active_scheme with other Xcode tools for environment validation and limitations checking.
    const xcodeTools = [...buildTools, 'xcode_open_project', 'xcode_get_schemes', 'xcode_set_active_scheme', 
                       'xcode_get_run_destinations', 'xcode_get_workspace_info', 'xcode_get_projects'];
    const xcresultTools = ['xcresult_browse', 'xcresult_browser_get_console', 'xcresult_summary', 'xcresult_get_screenshot', 'xcresult_get_ui_hierarchy', 'xcresult_get_ui_element', 'xcresult_list_attachments', 'xcresult_export_attachment'];
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool sets the active scheme, implying a mutation, but does not cover critical aspects like whether this requires specific permissions, if changes persist across sessions, potential side effects (e.g., on builds), or error handling. This is inadequate for a mutation tool with zero annotation coverage.

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, clear sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and efficiently conveys the core action, making it easy to parse quickly.

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 complexity of a mutation tool with no annotations and no output schema, the description is incomplete. It lacks information on behavioral traits (e.g., side effects, error cases), usage context, and output expectations, which are essential for an agent to invoke this tool correctly in a development environment.

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 fully documents both parameters (xcodeproj and scheme_name). The description does not add any meaning beyond what the schema provides, such as explaining parameter interactions or constraints. Baseline 3 is appropriate when the schema handles all parameter documentation.

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 ('Set') and resource ('active scheme for a specific project'), making the purpose immediately understandable. However, it does not explicitly differentiate this tool from siblings like 'xcode_get_schemes' or 'xcode_refresh_project', which would require mentioning that this changes the active scheme rather than just retrieving or updating project settings.

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?

No guidance is provided on when to use this tool versus alternatives. For example, it does not specify prerequisites (e.g., needing an open project) or contrast with tools like 'xcode_get_schemes' (for listing schemes) or 'xcode_build' (which might implicitly use the active scheme). This leaves the agent without context for tool selection.

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