Skip to content

Commit 9d1da53

Browse files
committed
Add architecture support to macOS build tools and improve project discovery
1 parent 033c1df commit 9d1da53

File tree

16 files changed

+294
-96
lines changed

16 files changed

+294
-96
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
/**
44
* XcodeBuildMCP - Main entry point
5-
* This file imports and configures the MCP server and tools
5+
*
6+
* This file serves as the entry point for the XcodeBuildMCP server, importing and registering
7+
* all tool modules with the MCP server. It follows the platform-specific approach for Xcode tools.
8+
*
9+
* Responsibilities:
10+
* - Creating and starting the MCP server
11+
* - Registering all platform-specific tool modules
12+
* - Configuring server options and logging
13+
* - Handling server lifecycle events
614
*/
715

816
// Import server components

src/server/server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Server Configuration - MCP Server setup and lifecycle management
3+
*
4+
* This module handles the creation, configuration, and lifecycle management of the
5+
* Model Context Protocol (MCP) server. It provides the foundation for all tool
6+
* registrations and server capabilities.
7+
*
8+
* Responsibilities:
9+
* - Creating and configuring the MCP server instance
10+
* - Setting up server capabilities and options
11+
* - Initializing progress reporting services
12+
* - Managing server lifecycle (start/stop)
13+
* - Handling transport configuration (stdio)
14+
*/
15+
116
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
217
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
318
import { log } from '../utils/logger.js';

src/tools/app_path.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
/**
22
* App Path Tools - Tools for retrieving app bundle paths
3+
*
4+
* This module provides tools for retrieving app bundle paths for various platforms
5+
* (macOS, iOS, watchOS, etc.) from both project files and workspaces.
6+
*
7+
* Responsibilities:
8+
* - Retrieving app bundle paths for simulator builds
9+
* - Retrieving app bundle paths for device builds
10+
* - Retrieving app bundle paths for macOS builds
11+
* - Supporting architecture-specific builds for macOS
12+
* - Handling platform-specific destination parameters
313
*/
414

515
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
616
import { log } from '../utils/logger.js';
717
import { validateRequiredParam, createTextResponse } from '../utils/validation.js';
818
import { ToolResponse, XcodePlatform } from '../types/common.js';
9-
import { executeXcodeCommand } from '../utils/xcode.js';
19+
import { executeXcodeCommand, constructDestinationString } from '../utils/xcode.js';
1020
import {
1121
registerTool,
1222
workspacePathSchema,
@@ -22,6 +32,13 @@ import {
2232
BaseAppPathSimulatorNameParams,
2333
BaseAppPathSimulatorIdParams,
2434
} from './common.js';
35+
import { z } from 'zod';
36+
37+
// Schema for architecture parameter
38+
const archSchema = z
39+
.enum(['arm64', 'x86_64'])
40+
.optional()
41+
.describe('Architecture to build for (arm64 or x86_64). For macOS only.');
2542

2643
// --- Private Helper Functions ---
2744

@@ -37,6 +54,7 @@ async function _handleGetAppPathLogic(params: {
3754
simulatorName?: string;
3855
simulatorId?: string;
3956
useLatestOS: boolean;
57+
arch?: string;
4058
}): Promise<ToolResponse> {
4159
log('info', `Getting app path for scheme ${params.scheme} on platform ${params.platform}`);
4260

@@ -77,7 +95,13 @@ async function _handleGetAppPathLogic(params: {
7795
);
7896
}
7997
} else if (params.platform === XcodePlatform.macOS) {
80-
destinationString = 'platform=macOS,arch=arm64,arch=x86_64';
98+
destinationString = constructDestinationString(
99+
params.platform,
100+
undefined,
101+
undefined,
102+
false,
103+
params.arch,
104+
);
81105
} else if (params.platform === XcodePlatform.iOS) {
82106
destinationString = 'generic/platform=iOS';
83107
} else if (params.platform === XcodePlatform.watchOS) {
@@ -160,7 +184,7 @@ async function _handleGetAppPathLogic(params: {
160184
* Registers the get_macos_app_path_workspace tool
161185
*/
162186
export function registerGetMacOSAppPathWorkspaceTool(server: McpServer): void {
163-
type Params = BaseWorkspaceParams & { configuration?: string };
187+
type Params = BaseWorkspaceParams & { configuration?: string; arch?: string };
164188
registerTool<Params>(
165189
server,
166190
'get_macos_app_path_workspace',
@@ -169,6 +193,7 @@ export function registerGetMacOSAppPathWorkspaceTool(server: McpServer): void {
169193
workspacePath: workspacePathSchema,
170194
scheme: schemeSchema,
171195
configuration: configurationSchema,
196+
arch: archSchema,
172197
},
173198
async (params: Params) => {
174199
const workspaceValidation = validateRequiredParam('workspacePath', params.workspacePath);
@@ -182,6 +207,7 @@ export function registerGetMacOSAppPathWorkspaceTool(server: McpServer): void {
182207
configuration: params.configuration ?? 'Debug',
183208
platform: XcodePlatform.macOS,
184209
useLatestOS: true,
210+
arch: params.arch, // Pass the architecture parameter
185211
});
186212
},
187213
);
@@ -191,7 +217,7 @@ export function registerGetMacOSAppPathWorkspaceTool(server: McpServer): void {
191217
* Registers the get_macos_app_path_project tool
192218
*/
193219
export function registerGetMacOSAppPathProjectTool(server: McpServer): void {
194-
type Params = BaseProjectParams & { configuration?: string };
220+
type Params = BaseProjectParams & { configuration?: string; arch?: string };
195221
registerTool<Params>(
196222
server,
197223
'get_macos_app_path_project',
@@ -200,6 +226,7 @@ export function registerGetMacOSAppPathProjectTool(server: McpServer): void {
200226
projectPath: projectPathSchema,
201227
scheme: schemeSchema,
202228
configuration: configurationSchema,
229+
arch: archSchema,
203230
},
204231
async (params: Params) => {
205232
const projectValidation = validateRequiredParam('projectPath', params.projectPath);
@@ -213,6 +240,7 @@ export function registerGetMacOSAppPathProjectTool(server: McpServer): void {
213240
configuration: params.configuration ?? 'Debug',
214241
platform: XcodePlatform.macOS,
215242
useLatestOS: true,
243+
arch: params.arch,
216244
});
217245
},
218246
);

src/tools/build_ios_device.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
22
* iOS Device Build Tools - Tools for building iOS applications for physical devices
3+
*
4+
* This module provides specialized tools for building iOS applications targeting physical
5+
* devices using xcodebuild. It supports both workspace and project-based builds.
6+
*
7+
* Responsibilities:
8+
* - Building iOS applications for physical devices from project files
9+
* - Building iOS applications for physical devices from workspaces
10+
* - Handling build configuration and derived data paths
11+
* - Providing platform-specific destination parameters
312
*/
413

514
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

src/tools/build_ios_simulator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* iOS Simulator Build Tools - Tools for building and running iOS applications in simulators
3+
*
4+
* This module provides specialized tools for building and running iOS applications in simulators
5+
* using xcodebuild. It supports both workspace and project-based builds with simulator targeting
6+
* by name or UUID.
7+
*
8+
* Responsibilities:
9+
* - Building iOS applications for simulators from project files and workspaces
10+
* - Running iOS applications in simulators after building
11+
* - Supporting simulator targeting by name or UUID
12+
* - Handling build configuration and derived data paths
313
*/
414

515
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

src/tools/build_macos.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* macOS Build Tools - Tools for building and running macOS applications
3+
*
4+
* This module provides specialized tools for building and running macOS applications
5+
* using xcodebuild. It supports both workspace and project-based builds with architecture
6+
* specification (arm64 or x86_64).
7+
*
8+
* Responsibilities:
9+
* - Building macOS applications from project files and workspaces
10+
* - Running macOS applications after building
11+
* - Supporting architecture-specific builds (arm64, x86_64)
12+
* - Handling build configuration and derived data paths
313
*/
414

515
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -10,6 +20,7 @@ import { XcodePlatform, executeXcodeCommand } from '../utils/xcode.js';
1020
import { createTextResponse } from '../utils/validation.js';
1121
import { ToolResponse } from '../types/common.js';
1222
import { executeXcodeBuild } from '../utils/build-utils.js';
23+
import { z } from 'zod';
1324
import {
1425
registerTool,
1526
workspacePathSchema,
@@ -20,6 +31,12 @@ import {
2031
extraArgsSchema,
2132
} from './common.js';
2233

34+
// Schema for architecture parameter
35+
const archSchema = z
36+
.enum(['arm64', 'x86_64'])
37+
.optional()
38+
.describe('Architecture to build for (arm64 or x86_64). For macOS only.');
39+
2340
// --- Private Helper Functions ---
2441

2542
/**
@@ -31,6 +48,7 @@ async function _handleMacOSBuildLogic(params: {
3148
scheme: string;
3249
configuration: string;
3350
derivedDataPath?: string;
51+
arch?: string;
3452
extraArgs?: string[];
3553
}): Promise<ToolResponse> {
3654
log('info', `Starting macOS build for scheme ${params.scheme} (internal)`);
@@ -41,6 +59,7 @@ async function _handleMacOSBuildLogic(params: {
4159
},
4260
{
4361
platform: XcodePlatform.macOS,
62+
arch: params.arch,
4463
logPrefix: 'macOS Build',
4564
},
4665
'build',
@@ -53,6 +72,7 @@ async function _getAppPathFromBuildSettings(params: {
5372
scheme: string;
5473
configuration: string;
5574
derivedDataPath?: string;
75+
arch?: string;
5676
extraArgs?: string[];
5777
}): Promise<{ success: boolean; appPath?: string; error?: string }> {
5878
try {
@@ -116,6 +136,7 @@ async function _handleMacOSBuildAndRunLogic(params: {
116136
scheme: string;
117137
configuration: string;
118138
derivedDataPath?: string;
139+
arch?: string;
119140
extraArgs?: string[];
120141
}): Promise<ToolResponse> {
121142
log('info', 'Handling macOS build & run logic...');
@@ -198,6 +219,7 @@ export function registerMacOSBuildTools(server: McpServer): void {
198219
scheme: string;
199220
configuration?: string;
200221
derivedDataPath?: string;
222+
arch?: string;
201223
extraArgs?: string[];
202224
};
203225

@@ -210,6 +232,7 @@ export function registerMacOSBuildTools(server: McpServer): void {
210232
scheme: schemeSchema,
211233
configuration: configurationSchema,
212234
derivedDataPath: derivedDataPathSchema,
235+
arch: archSchema,
213236
extraArgs: extraArgsSchema,
214237
},
215238
async (params) =>
@@ -224,6 +247,7 @@ export function registerMacOSBuildTools(server: McpServer): void {
224247
scheme: string;
225248
configuration?: string;
226249
derivedDataPath?: string;
250+
arch?: string;
227251
extraArgs?: string[];
228252
};
229253

@@ -236,6 +260,7 @@ export function registerMacOSBuildTools(server: McpServer): void {
236260
scheme: schemeSchema,
237261
configuration: configurationSchema,
238262
derivedDataPath: derivedDataPathSchema,
263+
arch: archSchema,
239264
extraArgs: extraArgsSchema,
240265
},
241266
async (params) =>
@@ -253,6 +278,7 @@ export function registerMacOSBuildAndRunTools(server: McpServer): void {
253278
scheme: string;
254279
configuration?: string;
255280
derivedDataPath?: string;
281+
arch?: string;
256282
extraArgs?: string[];
257283
};
258284

@@ -279,6 +305,7 @@ export function registerMacOSBuildAndRunTools(server: McpServer): void {
279305
scheme: string;
280306
configuration?: string;
281307
derivedDataPath?: string;
308+
arch?: string;
282309
extraArgs?: string[];
283310
};
284311

src/tools/build_settings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* Build Settings and Scheme Tools - Tools for viewing build settings and listing schemes
3+
*
4+
* This module provides tools for retrieving build settings and listing available schemes
5+
* from Xcode projects and workspaces. These tools are useful for debugging and exploring
6+
* project configuration.
7+
*
8+
* Responsibilities:
9+
* - Listing available schemes in Xcode projects and workspaces
10+
* - Retrieving detailed build settings for specific schemes
11+
* - Providing formatted output for build settings
12+
* - Supporting both project and workspace-based operations
313
*/
414

515
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

src/tools/bundleId.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* Bundle ID Tools - Extract bundle identifiers from app bundles
3+
*
4+
* This module provides tools for extracting bundle identifiers from iOS and macOS
5+
* application bundles (.app directories). Bundle IDs are required for launching
6+
* and installing applications.
7+
*
8+
* Responsibilities:
9+
* - Extracting bundle IDs from macOS app bundles
10+
* - Extracting bundle IDs from iOS app bundles
11+
* - Validating app bundle paths
12+
* - Providing formatted responses with next steps
313
*/
414

515
import { z } from 'zod';

src/tools/clean.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* Clean Tool - Uses xcodebuild's native clean action to clean build products
3+
*
4+
* This module provides tools for cleaning build products from Xcode projects and workspaces
5+
* using xcodebuild's native 'clean' action. Cleaning is important for ensuring fresh builds
6+
* and resolving certain build issues.
7+
*
8+
* Responsibilities:
9+
* - Cleaning build products from project files
10+
* - Cleaning build products from workspaces
11+
* - Supporting configuration-specific cleaning
12+
* - Handling derived data path specification
313
*/
414

515
import { z } from 'zod';

src/tools/common.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
/**
22
* Common types and utilities shared across build tool modules
3+
*
4+
* This module provides shared parameter schemas, types, and utility functions used by
5+
* multiple tool modules. Centralizing these definitions ensures consistency across
6+
* the codebase and simplifies maintenance.
7+
*
8+
* Responsibilities:
9+
* - Defining common parameter schemas with descriptive documentation
10+
* - Providing base parameter interfaces for workspace and project operations
11+
* - Implementing shared tool registration utilities
12+
* - Standardizing response formatting across tools
313
*/
414

515
import { z } from 'zod';

0 commit comments

Comments
 (0)