Skip to main content
Glama

list_projects

Find and display Godot projects in a specified directory to help users locate and manage their game development files.

Instructions

List Godot projects in a directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesDirectory to search for Godot projects
recursiveNoWhether to search recursively (default: false)

Implementation Reference

  • src/index.ts:729-744 (registration)
    Tool registration including name, description, and input schema for list_projects
    name: 'list_projects',
    description: 'List Godot projects in a directory',
    inputSchema: {
      type: 'object',
      properties: {
        directory: {
          type: 'string',
          description: 'Directory to search for Godot projects',
        },
        recursive: {
          type: 'boolean',
          description: 'Whether to search recursively (default: false)',
        },
      },
      required: ['directory'],
    },
  • Handler function for list_projects tool that normalizes args, validates directory, finds projects using findGodotProjects, and returns JSON list
    private async handleListProjects(args: any) {
      // Normalize parameters to camelCase
      args = this.normalizeParameters(args);
      
      if (!args.directory) {
        return this.createErrorResponse(
          'Directory is required',
          ['Provide a valid directory path to search for Godot projects']
        );
      }
    
      if (!this.validatePath(args.directory)) {
        return this.createErrorResponse(
          'Invalid directory path',
          ['Provide a valid path without ".." or other potentially unsafe characters']
        );
      }
    
      try {
        this.logDebug(`Listing Godot projects in directory: ${args.directory}`);
        if (!existsSync(args.directory)) {
          return this.createErrorResponse(
            `Directory does not exist: ${args.directory}`,
            ['Provide a valid directory path that exists on the system']
          );
        }
    
        const recursive = args.recursive === true;
        const projects = this.findGodotProjects(args.directory, recursive);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(projects, null, 2),
            },
          ],
        };
      } catch (error: any) {
        return this.createErrorResponse(
          `Failed to list projects: ${error?.message || 'Unknown error'}`,
          [
            'Ensure the directory exists and is accessible',
            'Check if you have permission to read the directory',
          ]
        );
      }
    }
  • src/index.ts:944-945 (registration)
    Registration of the handler in the CallToolRequestSchema switch statement
    case 'list_projects':
      return await this.handleListProjects(request.params.arguments);
  • Helper function that implements the core logic to find Godot projects by searching for project.godot files in directories, recursively if specified
    private findGodotProjects(directory: string, recursive: boolean): Array<{ path: string; name: string }> {
      const projects: Array<{ path: string; name: string }> = [];
    
      try {
        // Check if the directory itself is a Godot project
        const projectFile = join(directory, 'project.godot');
        if (existsSync(projectFile)) {
          projects.push({
            path: directory,
            name: basename(directory),
          });
        }
    
        // If not recursive, only check immediate subdirectories
        if (!recursive) {
          const entries = readdirSync(directory, { withFileTypes: true });
          for (const entry of entries) {
            if (entry.isDirectory()) {
              const subdir = join(directory, entry.name);
              const projectFile = join(subdir, 'project.godot');
              if (existsSync(projectFile)) {
                projects.push({
                  path: subdir,
                  name: entry.name,
                });
              }
            }
          }
        } else {
          // Recursive search
          const entries = readdirSync(directory, { withFileTypes: true });
          for (const entry of entries) {
            if (entry.isDirectory()) {
              const subdir = join(directory, entry.name);
              // Skip hidden directories
              if (entry.name.startsWith('.')) {
                continue;
              }
              // Check if this directory is a Godot project
              const projectFile = join(subdir, 'project.godot');
              if (existsSync(projectFile)) {
                projects.push({
                  path: subdir,
                  name: entry.name,
                });
              } else {
                // Recursively search this directory
                const subProjects = this.findGodotProjects(subdir, true);
                projects.push(...subProjects);
              }
            }
          }
        }
      } catch (error) {
        this.logDebug(`Error searching directory ${directory}: ${error}`);
      }
    
      return projects;
    }

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/Zycroft/godot-mcp'

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