xcode_open_file
Open files in Xcode directly from your workflow, optionally navigating to specific line numbers for efficient code editing and review.
Instructions
Open a file in Xcode
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Absolute path to the file to open | |
| line_number | No | Optional line number to navigate to |
Implementation Reference
- src/tools/InfoTools.ts:57-79 (handler)Core handler function that validates the file path and uses JXA scripting to open the specified file in Xcode. Optionally navigates to a given line number using app.hack().public static async openFile(filePath: string, lineNumber?: number): Promise<McpResult> { const validationError = PathValidator.validateFilePath(filePath); if (validationError) return validationError; const script = ` (function() { const app = Application('Xcode'); app.open(${JSON.stringify(filePath)}); ${lineNumber ? ` const docs = app.sourceDocuments(); const doc = docs.find(d => d.path().includes(${JSON.stringify(filePath.split('/').pop())})); if (doc) { app.hack({document: doc, start: ${lineNumber}, stop: ${lineNumber}}); }` : ''} return 'File opened successfully'; })() `; const result = await JXAExecutor.execute(script); return { content: [{ type: 'text', text: result }] }; }
- src/XcodeServer.ts:521-525 (handler)Dispatch handler in the main tool switch statement that validates input parameters and calls InfoTools.openFile.case 'xcode_open_file': if (!args.file_path) { throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: file_path`); } return await InfoTools.openFile(args.file_path as string, args.line_number as number);
- Tool schema definition specifying input parameters: file_path (required, absolute path) and line_number (optional). Used by ListTools endpoint.{ name: 'xcode_open_file', description: 'Open a file in Xcode', inputSchema: { type: 'object', properties: { file_path: { type: 'string', description: 'Absolute path to the file to open', }, line_number: { type: 'number', description: 'Optional line number to navigate to', }, }, required: ['file_path'], },
- src/XcodeServer.ts:301-311 (registration)Registration in ListToolsRequestSchema handler: loads tool definitions from shared/toolDefinitions.ts (which includes xcode_open_file) and exposes name, description, inputSchema.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);