Skip to main content
Glama
ebowwa

Xcode MCP Server

by ebowwa

xcode_read_file

Read file contents within Xcode projects to access code, configuration, or resource files for development tasks.

Instructions

Read contents of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the file to read

Implementation Reference

  • The core handler function that executes the file reading logic using Node.js fs.readFile. This is the exact implementation that reads the file contents for the xcode_read_file tool.
    async readFile(filePath: string): Promise<string> {
      return await fs.readFile(filePath, 'utf-8');
    }
  • Handler in executeInternalCommand that processes the 'read_file' internal command by calling fileManager.readFile with the provided file_path argument.
    case 'read_file':
      output = await this.fileManager.readFile(args.file_path);
      break;
  • src/index.ts:91-171 (registration)
    MCP CallTool request handler that registers and executes all xcode_* tools, including xcode_read_file, by stripping the prefix and delegating to commandExecutor.executeCommand.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      try {
        // Handle web monitor tools
        if (name === 'start_web_monitor') {
          const result = await this.webMonitorManager.start();
          return {
            content: [
              {
                type: 'text',
                text: `${result.message}\n\nWeb interface available at: ${result.url}`
              }
            ]
          };
        }
        
        if (name === 'stop_web_monitor') {
          const result = this.webMonitorManager.stop();
          return {
            content: [
              {
                type: 'text',
                text: result.message
              }
            ]
          };
        }
        
        if (name === 'web_monitor_status') {
          const status = this.webMonitorManager.getStatus();
          let text = status.running 
            ? `Web monitor is running at ${status.url} (port ${status.port})`
            : 'Web monitor is not running';
          return {
            content: [
              {
                type: 'text',
                text: text
              }
            ]
          };
        }
        
        // Handle Xcode commands
        // Remove 'xcode_' prefix if present
        const commandName = name.startsWith('xcode_') ? name.slice(6) : name;
        const result = await this.commandExecutor.executeCommand(commandName, args);
        
        let responseText = result.output;
        if (result.error) {
          responseText += `\n\nWarnings/Errors:\n${result.error}`;
        }
        if (!result.success) {
          responseText = `Command failed: ${result.error}\n\nCommand executed: ${result.command}`;
        }
        
        return {
          content: [
            {
              type: 'text',
              text: responseText,
            },
          ],
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${errorMessage}`,
            },
          ],
        };
      }
    });
  • Generates the MCP tool definitions including name 'xcode_read_file', description, and inputSchema based on the 'read_file' command parameters from commands.json.
    generateMCPToolDefinitions(): Array<{
      name: string;
      description: string;
      inputSchema: any;
    }> {
      return Object.entries(this.commands).map(([name, command]) => ({
        name: `xcode_${name}`,
        description: command.description,
        inputSchema: {
          type: 'object',
          properties: command.parameters ? Object.fromEntries(
            Object.entries(command.parameters).map(([paramName, paramDef]) => [
              paramName,
              {
                type: paramDef.type,
                description: paramDef.description,
                ...(paramDef.default !== undefined && { default: paramDef.default })
              }
            ])
          ) : {},
          required: command.parameters ? Object.entries(command.parameters)
            .filter(([_, paramDef]) => paramDef.required)
            .map(([paramName]) => paramName) : []
        }
      }));
    }
  • src/index.ts:52-90 (registration)
    Registers the xcode_read_file tool in the MCP ListTools response by including it in the dynamic tools list from generateMCPToolDefinitions.
    // Load commands and dynamically create tool list
    await this.commandExecutor.loadCommands();
    const tools = this.commandExecutor.generateMCPToolDefinitions();
    
    // Add web monitor management tools
    const webMonitorTools = [
      {
        name: 'start_web_monitor',
        description: 'Start the web interface for visual command execution and monitoring',
        inputSchema: {
          type: 'object',
          properties: {},
          required: []
        }
      },
      {
        name: 'stop_web_monitor',
        description: 'Stop the web interface if it is running',
        inputSchema: {
          type: 'object',
          properties: {},
          required: []
        }
      },
      {
        name: 'web_monitor_status',
        description: 'Get the current status of the web monitor',
        inputSchema: {
          type: 'object',
          properties: {},
          required: []
        }
      }
    ];
    
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [...tools, ...webMonitorTools],
    }));

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

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