Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

find_pattern

Locate specific JavaScript/TypeScript code patterns using intuitive syntax for targeted searches in code analysis.

Instructions

Find first node matching the specified pattern using tree-hugger-js intuitive syntax. Use for targeted searches when you need one specific match.

Examples: • Find main function: find_pattern('function[name="main"]') • Find React component: find_pattern('function[name="UserProfile"]') • Find async functions: find_pattern('function[async]') • Find specific class: find_pattern('class[name="UserManager"]') • Find error handling: find_pattern('call[text*="catch"]') • Find JSX with props: find_pattern('jsx:has(jsx-attribute[name="className"])') • Debug specific calls: find_pattern('call[text*="console.log"]')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesPattern using intuitive syntax: 'function', 'class[name="MyClass"]', 'function[async]', 'call[text*="fetch"]'

Implementation Reference

  • The handler function that executes the 'find_pattern' tool. It checks if AST is loaded, uses tree.find(pattern) to locate the first matching node, extracts metadata, and returns formatted node information or error.
    private async findPattern(args: { pattern: string }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const result = this.currentAST.tree.find(args.pattern);
        
        if (!result) {
          return {
            content: [{
              type: "text",
              text: `No match found for pattern: ${args.pattern}`,
            }],
          };
        }
    
        const nodeInfo = {
          type: result.type,
          text: result.text.length > 200 ? result.text.slice(0, 200) + '...' : result.text,
          line: result.line,
          column: result.column,
          name: result.name,
          startPosition: result.startPosition,
          endPosition: result.endPosition,
          childrenCount: result.children.length,
        };
    
        return {
          content: [{
            type: "text", 
            text: `Found match for pattern "${args.pattern}":\n${JSON.stringify(nodeInfo, null, 2)}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error finding pattern: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • Input schema definition for the 'find_pattern' tool, specifying a required 'pattern' string parameter.
    inputSchema: {
      type: "object",
      properties: {
        pattern: {
          type: "string",
          description: "Pattern using intuitive syntax: 'function', 'class[name=\"MyClass\"]', 'function[async]', 'call[text*=\"fetch\"]'"
        }
      },
      required: ["pattern"],
    },
  • src/index.ts:416-417 (registration)
    Registration in the CallToolRequestSchema switch statement that dispatches to the findPattern handler.
    case "find_pattern":
      return await this.findPattern(args as { pattern: string });
  • src/index.ts:202-215 (registration)
    Tool registration in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: "find_pattern",
      description: "Find first node matching the specified pattern using tree-hugger-js intuitive syntax. Use for targeted searches when you need one specific match.\n\nExamples:\n• Find main function: find_pattern('function[name=\"main\"]')\n• Find React component: find_pattern('function[name=\"UserProfile\"]')\n• Find async functions: find_pattern('function[async]')\n• Find specific class: find_pattern('class[name=\"UserManager\"]')\n• Find error handling: find_pattern('call[text*=\"catch\"]')\n• Find JSX with props: find_pattern('jsx:has(jsx-attribute[name=\"className\"])')\n• Debug specific calls: find_pattern('call[text*=\"console.log\"]')",
      inputSchema: {
        type: "object",
        properties: {
          pattern: {
            type: "string",
            description: "Pattern using intuitive syntax: 'function', 'class[name=\"MyClass\"]', 'function[async]', 'call[text*=\"fetch\"]'"
          }
        },
        required: ["pattern"],
      },
    },
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It explains the tool returns the 'first' match (important behavioral trait) and uses 'tree-hugger-js intuitive syntax,' but lacks details on error handling, performance, or output format. For a search tool with no annotations, this is adequate but leaves gaps in 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.

Conciseness4/5

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

The description is well-structured: it starts with the core purpose, provides usage guidance, and follows with relevant examples. Every sentence adds value, though the example list is lengthy; it could be more concise by summarizing syntax patterns instead of listing many specific cases.

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 no annotations and no output schema, the description covers purpose and usage well but lacks details on return values, error conditions, or limitations. For a pattern-matching tool with one parameter, it's minimally viable but incomplete for full agent understanding.

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

Parameters4/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds value by providing 7 concrete examples (e.g., 'Find main function: find_pattern('function[name="main"]')') that illustrate pattern syntax and use cases, enhancing understanding beyond the schema's generic description.

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: 'Find first node matching the specified pattern using tree-hugger-js intuitive syntax.' It specifies the verb ('find'), resource ('first node'), and method ('using tree-hugger-js intuitive syntax'), distinguishing it from siblings like find_all_pattern (which finds all matches) and other analysis tools.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool: 'Use for targeted searches when you need one specific match.' It distinguishes it from find_all_pattern (implied alternative for multiple matches) and other siblings like get_functions or get_classes (which retrieve broader categories without pattern matching).

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