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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Open a file in Xcode' implies a read-only navigation action, but it doesn't specify whether this requires Xcode to be active, what happens if the file doesn't exist, or if it changes application state. For a tool with zero annotation coverage, this is insufficient behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable and appropriately sized for a simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool in this context. It doesn't explain what 'opening' entails (e.g., launches Xcode, navigates within an existing instance), potential errors, or return values. With 2 parameters and many sibling tools, more context is needed for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear parameter documentation in the input schema. The description adds no additional parameter information beyond what's already in the schema (e.g., file_path as absolute path, line_number as optional navigation). This meets the baseline of 3 when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Open a file in Xcode' clearly states the action (open) and target (a file in Xcode), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'xcode_open_project' or 'xcode_get_projects', which also involve opening/navigating Xcode resources, so it misses full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention scenarios like opening source files versus projects, or prerequisites such as having Xcode running. With many sibling tools for Xcode operations, this lack of context leaves the agent guessing about appropriate usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/lapfelix/XcodeMCP'

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