Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

find_all_pattern

Locate all code nodes matching a specified pattern for comprehensive analysis, auditing, or review tasks in JavaScript/TypeScript codebases.

Instructions

Find all nodes matching the specified pattern. Use for comprehensive analysis when you need all matches.

Examples: • Audit all functions: find_all_pattern('function') • Find all TODO comments: find_all_pattern('comment[text*="TODO"]') • Security audit: find_all_pattern('call[text*="eval"]') • Performance review: find_all_pattern('call[text*="console.log"]') to find debug logs • API usage: find_all_pattern('call[text*="fetch"]') to find all API calls • React hooks: find_all_pattern('call[text*="use"]') for hooks usage • Error patterns: find_all_pattern('string[text*="error"]') for error messages • Database queries: find_all_pattern('string[text*="SELECT"]') for SQL • Event handlers: find_all_pattern('function[text*="onClick"]')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesPattern to match: 'function', 'call[text*="console.log"]', 'string[text*="TODO"]'
limitNoMaximum number of matches to return (default: no limit). Use for large codebases.

Implementation Reference

  • The handler function that implements the core logic of the 'find_all_pattern' tool. It searches the current AST for all nodes matching the given pattern using tree-hugger-js's findAll method, applies an optional limit, formats the results, and returns them.
    private async findAllPattern(args: { pattern: string; limit?: number }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const results = this.currentAST.tree.findAll(args.pattern);
        const limitedResults = args.limit ? results.slice(0, args.limit) : results;
        
        const matches = limitedResults.map((node: NodeWrapper) => ({
          type: node.type,
          text: node.text.length > 100 ? node.text.slice(0, 100) + '...' : node.text,
          line: node.line,
          column: node.column,
          name: node.name,
        }));
    
        return {
          content: [{
            type: "text",
            text: `Found ${results.length} matches for pattern "${args.pattern}"${args.limit ? ` (showing first ${limitedResults.length})` : ''}:\n${JSON.stringify(matches, null, 2)}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error finding pattern: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • The input schema definition for the 'find_all_pattern' tool, specifying the required 'pattern' string and optional 'limit' number.
    inputSchema: {
      type: "object",
      properties: {
        pattern: {
          type: "string",
          description: "Pattern to match: 'function', 'call[text*=\"console.log\"]', 'string[text*=\"TODO\"]'"
        },
        limit: {
          type: "number",
          description: "Maximum number of matches to return (default: no limit). Use for large codebases."
        }
      },
      required: ["pattern"],
    },
  • src/index.ts:216-233 (registration)
    The tool registration in the ListToolsRequestSchema handler's tools array, including name, description, and input schema.
    {
      name: "find_all_pattern", 
      description: "Find all nodes matching the specified pattern. Use for comprehensive analysis when you need all matches.\n\nExamples:\n• Audit all functions: find_all_pattern('function')\n• Find all TODO comments: find_all_pattern('comment[text*=\"TODO\"]')\n• Security audit: find_all_pattern('call[text*=\"eval\"]')\n• Performance review: find_all_pattern('call[text*=\"console.log\"]') to find debug logs\n• API usage: find_all_pattern('call[text*=\"fetch\"]') to find all API calls\n• React hooks: find_all_pattern('call[text*=\"use\"]') for hooks usage\n• Error patterns: find_all_pattern('string[text*=\"error\"]') for error messages\n• Database queries: find_all_pattern('string[text*=\"SELECT\"]') for SQL\n• Event handlers: find_all_pattern('function[text*=\"onClick\"]')",
      inputSchema: {
        type: "object",
        properties: {
          pattern: {
            type: "string",
            description: "Pattern to match: 'function', 'call[text*=\"console.log\"]', 'string[text*=\"TODO\"]'"
          },
          limit: {
            type: "number",
            description: "Maximum number of matches to return (default: no limit). Use for large codebases."
          }
        },
        required: ["pattern"],
      },
    },
  • src/index.ts:419-420 (registration)
    The switch case in the CallToolRequestSchema handler that routes calls to the findAllPattern method.
    case "find_all_pattern":
      return await this.findAllPattern(args as { pattern: string; limit?: number });
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It implies the tool performs a read-only search operation, which is consistent with its purpose, but does not disclose potential limitations like performance impacts on large codebases, error handling, or return format details. The examples add some context but lack explicit behavioral traits.

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

Conciseness3/5

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

The description is front-loaded with a clear purpose statement, but the extensive list of examples (9 bullet points) adds redundancy and length without providing new semantic value. While helpful for illustration, it reduces conciseness by not earning its place efficiently beyond the initial guidance.

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

Completeness3/5

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

Given the tool's complexity (pattern matching in code analysis), no annotations, and no output schema, the description is moderately complete. It covers the purpose and usage with examples but lacks details on behavioral aspects like performance, error handling, or return structure, which are important for a tool with potential large-scale operations.

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?

The schema description coverage is 100%, so the input schema already documents both parameters ('pattern' and 'limit') thoroughly. The description does not add significant meaning beyond the schema, as it repeats pattern examples already in the schema description. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the tool's purpose with a specific verb ('Find all nodes') and resource ('matching the specified pattern'), and distinguishes it from siblings like 'find_pattern' by emphasizing 'comprehensive analysis when you need all matches'. This provides immediate clarity on what the tool does and its scope.

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

Usage Guidelines4/5

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

The description provides clear context for usage ('Use for comprehensive analysis when you need all matches') and includes practical examples that illustrate when to apply the tool. However, it does not explicitly state when not to use it or name alternatives among siblings, such as 'find_pattern' which might handle partial matches differently.

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/qckfx/tree-hugger-js-mcp'

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