Skip to main content
Glama

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
NameRequiredDescriptionDefault
file_pathYesAbsolute path to the file to open
line_numberNoOptional line number to navigate to

Implementation Reference

  • 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 }] }; }
  • 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'], },
  • 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);

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