Skip to main content
Glama
falahgs

3D Cartoon Generator & File System MCP Server

by falahgs

search_files

Search for files in a given directory using a glob pattern, with optional exclusion patterns to refine results.

Instructions

Search for files matching a pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesBase directory to search from
patternYesSearch pattern (glob format)
excludePatternsNoPatterns to exclude from search (glob format)

Implementation Reference

  • The main handler function 'searchFiles' that recursively searches directories for files matching a glob pattern, with support for exclude patterns. Uses fsPromises.readdir, minimatch for pattern matching, and validatePath for security.
    async function searchFiles(rootPath: string, pattern: string, excludePatterns: string[] = []): Promise<string[]> {
      const results: string[] = [];
    
      async function search(currentPath: string) {
        const entries = await fsPromises.readdir(currentPath, { withFileTypes: true });
    
        for (const entry of entries) {
          const fullPath = path.join(currentPath, entry.name);
    
          try {
            // Validate each path before processing
            await validatePath(fullPath);
    
            // Check if path matches any exclude pattern
            const relativePath = path.relative(rootPath, fullPath);
            const shouldExclude = excludePatterns.some(pattern => {
              const globPattern = pattern.includes('*') ? pattern : `**/${pattern}/**`;
              return minimatch(relativePath, globPattern, { dot: true });
            });
    
            if (shouldExclude) {
              continue;
            }
    
            // Check if the path matches the search pattern
            if (minimatch(entry.name, pattern, { nocase: true })) {
              results.push(fullPath);
            }
    
            if (entry.isDirectory()) {
              await search(fullPath);
            }
          } catch (error) {
            // Skip invalid paths during search
            continue;
          }
        }
      }
    
      await search(rootPath);
      return results;
    }
  • The switch-case handler in the CallToolRequestSchema that dispatches 'search_files' tool calls. Validates path, extracts excludePatterns, calls searchFiles, and returns results.
    case "search_files": {
      const validPath = await validatePath(args.path);
      const excludePatterns = args.excludePatterns || [];
      const results = await searchFiles(validPath, args.pattern, excludePatterns);
      return {
        toolResult: {
          success: true,
          content: [{ 
            type: "text", 
            text: results.length > 0 ? results.join("\n") : "No matching files found"
          }],
          message: `Found ${results.length} matching files`
        }
      };
    }
  • Input schema definition for the 'search_files' tool registered with ListToolsRequestSchema. Defines path (string, required), pattern (string, required), and excludePatterns (string array, optional).
    {
      name: "search_files",
      description: "Search for files matching a pattern",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "Base directory to search from"
          },
          pattern: {
            type: "string",
            description: "Search pattern (glob format)"
          },
          excludePatterns: {
            type: "array",
            items: {
              type: "string"
            },
            description: "Patterns to exclude from search (glob format)"
          }
        },
        required: ["path", "pattern"]
      }
    }
  • src/index.ts:277-387 (registration)
    Tool registration via server.setRequestHandler(ListToolsRequestSchema, ...). The 'search_files' tool is registered as one of several tools in the tools array (line 361).
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          // Image generation tool
          {
            name: "generate_3d_cartoon",
            description: "Generates a 3D style cartoon image for kids based on the given prompt",
            inputSchema: {
              type: "object",
              properties: {
                prompt: {
                  type: "string",
                  description: "The prompt describing the 3D cartoon image to generate"
                },
                fileName: {
                  type: "string",
                  description: "The name of the output file (without extension)"
                }
              },
              required: ["prompt", "fileName"]
            }
          },
          // File system tools
          {
            name: "read_file",
            description: "Read the contents of a file",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Path to the file to read"
                }
              },
              required: ["path"]
            }
          },
          {
            name: "write_file",
            description: "Write content to a file",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Path to the file to write"
                },
                content: {
                  type: "string",
                  description: "Content to write to the file"
                }
              },
              required: ["path", "content"]
            }
          },
          {
            name: "list_directory",
            description: "List the contents of a directory",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Path to the directory to list"
                }
              },
              required: ["path"]
            }
          },
          {
            name: "create_directory",
            description: "Create a new directory",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Path to the directory to create"
                }
              },
              required: ["path"]
            }
          },
          {
            name: "search_files",
            description: "Search for files matching a pattern",
            inputSchema: {
              type: "object",
              properties: {
                path: {
                  type: "string",
                  description: "Base directory to search from"
                },
                pattern: {
                  type: "string",
                  description: "Search pattern (glob format)"
                },
                excludePatterns: {
                  type: "array",
                  items: {
                    type: "string"
                  },
                  description: "Patterns to exclude from search (glob format)"
                }
              },
              required: ["path", "pattern"]
            }
          }
        ]
      };
    });
Behavior2/5

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

No annotations provided, so description must disclose behavior. It only states 'matching a pattern' without specifying recursion, case sensitivity, or result format. Behavior is under-specified.

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

Conciseness4/5

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

Single sentence with no wasted words. However, it lacks structure (e.g., separate sections for behavior vs parameters). Concise but could be better organized.

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 3 parameters, no output schema, and no annotations, the description is too brief. Does not mention output format, recursion, or edge cases. Compels the agent to guess.

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 coverage is 100%, so baseline is 3. The description does not add extra meaning beyond what the schema already provides for each parameter. No additional context or examples.

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 clearly states the verb 'search' and resource 'files', and distinguishes from siblings like list_directory which lists without pattern matching. However, it does not specify recursive behavior or scope.

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?

No guidance on when to use this tool versus alternatives like list_directory (which lists files without pattern) or read_file. The context signals show siblings but description offers no differentiation.

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/falahgs/mcp-3d-style-cartoon-gen-server'

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