Skip to main content
Glama
devyhan
by devyhan

xcode-build

Automate Xcode project builds by specifying project paths, schemes, configurations, and destinations. Manage build outputs and optional clean steps for efficient iOS app development.

Input Schema

NameRequiredDescriptionDefault
cleanNo빌드 전 clean 실행 여부
configurationNo빌드 구성 (예: Debug, Release)
destinationNo빌드 대상 (예: 'platform=iOS Simulator,name=iPhone 14')
extraArgsNo추가 xcodebuild 인자들
outputDirNo빌드 결과물 저장 경로 (SYMROOT)
projectPathYesXcode 프로젝트 또는 워크스페이스 경로
schemeYes빌드할 스킴

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "clean": { "description": "빌드 전 clean 실행 여부", "type": "boolean" }, "configuration": { "description": "빌드 구성 (예: Debug, Release)", "type": "string" }, "destination": { "description": "빌드 대상 (예: 'platform=iOS Simulator,name=iPhone 14')", "type": "string" }, "extraArgs": { "description": "추가 xcodebuild 인자들", "items": { "type": "string" }, "type": "array" }, "outputDir": { "description": "빌드 결과물 저장 경로 (SYMROOT)", "type": "string" }, "projectPath": { "description": "Xcode 프로젝트 또는 워크스페이스 경로", "type": "string" }, "scheme": { "description": "빌드할 스킴", "type": "string" } }, "required": [ "projectPath", "scheme" ], "type": "object" }

Implementation Reference

  • Handler function that implements the core logic for the 'xcode-build' tool by constructing and executing an xcodebuild command based on provided parameters.
    async ({ projectPath, scheme, configuration, destination, extraArgs = [], outputDir, clean = false }) => { try { console.error(`Xcode 프로젝트 빌드: ${projectPath}, Scheme: ${scheme}`); let command = `xcodebuild`; // 워크스페이스인지 프로젝트인지 확인 if (projectPath.endsWith(".xcworkspace")) { command += ` -workspace "${projectPath}"`; } else { command += ` -project "${projectPath}"`; } command += ` -scheme "${scheme}"`; if (clean) { command += ` clean`; } command += ` build`; // 명시적으로 build 액션 지정 if (configuration) { command += ` -configuration "${configuration}"`; } if (destination) { command += ` -destination "${destination}"`; } if (outputDir) { command += ` SYMROOT="${outputDir}"`; } // 추가 인자 추가 if (extraArgs.length > 0) { command += " " + extraArgs.join(" "); } console.error(`실행할 빌드 명령어: ${command}`); // 빌드 명령어 실행 try { const { stdout, stderr } = await executeCommand(command); let resultText = "빌드 결과:\n"; if (stdout) resultText += `${stdout}\n`; if (stderr) resultText += `STDERR:\n${stderr}\n`; return { content: [{ type: "text", text: resultText }] }; } catch (error: any) { throw error; } } catch (error: any) { console.error(`Xcode 빌드 오류: ${error.message}`); return { content: [{ type: "text", text: `Xcode 빌드 중 오류가 발생했습니다:\n${error.message}\n${error.stderr || ''}` }], isError: true }; } }
  • Input schema using Zod for validating parameters of the 'xcode-build' tool.
    { projectPath: z.string().describe("Xcode 프로젝트 또는 워크스페이스 경로"), scheme: z.string().describe("빌드할 스킴"), configuration: z.string().optional().describe("빌드 구성 (예: Debug, Release)"), destination: z.string().optional().describe("빌드 대상 (예: 'platform=iOS Simulator,name=iPhone 14')"), extraArgs: z.array(z.string()).optional().describe("추가 xcodebuild 인자들"), outputDir: z.string().optional().describe("빌드 결과물 저장 경로 (SYMROOT)"), clean: z.boolean().optional().describe("빌드 전 clean 실행 여부") },
  • src/index.ts:81-158 (registration)
    Registration of the 'xcode-build' tool using server.tool() with name, schema, and handler.
    server.tool( "xcode-build", { projectPath: z.string().describe("Xcode 프로젝트 또는 워크스페이스 경로"), scheme: z.string().describe("빌드할 스킴"), configuration: z.string().optional().describe("빌드 구성 (예: Debug, Release)"), destination: z.string().optional().describe("빌드 대상 (예: 'platform=iOS Simulator,name=iPhone 14')"), extraArgs: z.array(z.string()).optional().describe("추가 xcodebuild 인자들"), outputDir: z.string().optional().describe("빌드 결과물 저장 경로 (SYMROOT)"), clean: z.boolean().optional().describe("빌드 전 clean 실행 여부") }, async ({ projectPath, scheme, configuration, destination, extraArgs = [], outputDir, clean = false }) => { try { console.error(`Xcode 프로젝트 빌드: ${projectPath}, Scheme: ${scheme}`); let command = `xcodebuild`; // 워크스페이스인지 프로젝트인지 확인 if (projectPath.endsWith(".xcworkspace")) { command += ` -workspace "${projectPath}"`; } else { command += ` -project "${projectPath}"`; } command += ` -scheme "${scheme}"`; if (clean) { command += ` clean`; } command += ` build`; // 명시적으로 build 액션 지정 if (configuration) { command += ` -configuration "${configuration}"`; } if (destination) { command += ` -destination "${destination}"`; } if (outputDir) { command += ` SYMROOT="${outputDir}"`; } // 추가 인자 추가 if (extraArgs.length > 0) { command += " " + extraArgs.join(" "); } console.error(`실행할 빌드 명령어: ${command}`); // 빌드 명령어 실행 try { const { stdout, stderr } = await executeCommand(command); let resultText = "빌드 결과:\n"; if (stdout) resultText += `${stdout}\n`; if (stderr) resultText += `STDERR:\n${stderr}\n`; return { content: [{ type: "text", text: resultText }] }; } catch (error: any) { throw error; } } catch (error: any) { console.error(`Xcode 빌드 오류: ${error.message}`); return { content: [{ type: "text", text: `Xcode 빌드 중 오류가 발생했습니다:\n${error.message}\n${error.stderr || ''}` }], isError: true }; } } );
  • Helper function executeCommand imported and used in the xcode-build handler to safely execute the constructed shell command.
    export async function executeCommand(command: string, workingDir?: string, timeout: number = 60000) { try { console.error(`명령어 실행: ${command} in ${workingDir || 'current directory'}`); // 보안 상의 이유로 위험한 명령어 필터링 if (/rm\s+-rf\s+\//.test(command) || /mkfs/.test(command) || /dd\s+if/.test(command)) { throw new Error("보안상의 이유로 이 명령어를 실행할 수 없습니다."); } const options = { cwd: workingDir, timeout: timeout, // 버퍼 제한 제거 maxBuffer: Infinity }; const { stdout, stderr } = await execPromise(command, options); return { stdout, stderr }; } catch (error: any) { console.error(`명령어 실행 오류: ${error.message}`); throw error; } }

Other Tools

Related 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/devyhan/xcode-mcp'

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