Skip to main content
Glama

xcode_open_file

Open a specific file in Xcode from a given path, optionally navigating to a designated line number, facilitating quick access and code review.

Instructions

Open a file in Xcode

Input Schema

NameRequiredDescriptionDefault
file_pathYesPath to the file to open - supports both absolute (/path/to/file.swift) and relative (src/file.swift) paths
line_numberNoOptional line number to navigate to

Input Schema (JSON Schema)

{ "properties": { "file_path": { "description": "Path to the file to open - supports both absolute (/path/to/file.swift) and relative (src/file.swift) paths", "type": "string" }, "line_number": { "description": "Optional line number to navigate to", "type": "number" } }, "required": [ "file_path" ], "type": "object" }

Implementation Reference

  • The core handler function that opens the specified file in Xcode using AppleScript/JXA. Optionally navigates to a specific line number if provided. Validates the file path first.
    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 }] }; }
  • Registration of the 'xcode_open_file' tool handler in the MCP server switch statement. Delegates to InfoTools.openFile after parameter validation.
    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); case 'xcresult_browse':
  • Tool schema definition including input schema with file_path (required) and optional line_number.
    { 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'], }, },
  • Tool list registration that provides all tool definitions including 'xcode_open_file' schema via getToolDefinitions.
    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 })), }; });

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