Skip to main content
Glama

Tree-Hugger-JS MCP Server

by qckfx

find_all_pattern

Identify and extract all nodes in JavaScript/TypeScript code matching a specified pattern for audits, debugging, or analysis. Use to locate API calls, error messages, React hooks, or SQL queries efficiently.

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

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

Input Schema (JSON Schema)

{ "properties": { "limit": { "description": "Maximum number of matches to return (default: no limit). Use for large codebases.", "type": "number" }, "pattern": { "description": "Pattern to match: 'function', 'call[text*=\"console.log\"]', 'string[text*=\"TODO\"]'", "type": "string" } }, "required": [ "pattern" ], "type": "object" }

Implementation Reference

  • The primary handler function that implements the core logic of the 'find_all_pattern' tool. It checks for a loaded AST, uses tree-hugger-js's findAll method to locate all matching nodes, applies optional limiting, formats the results, and returns them in the MCP response format.
    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, }; } }
  • src/index.ts:216-233 (registration)
    The tool registration entry in the ListToolsRequestSchema handler, defining the tool's name, detailed description with examples, 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"], }, },
  • The input schema defining the expected parameters: 'pattern' (required 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:419-420 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes calls to the findAllPattern method with type-cast arguments.
    case "find_all_pattern": return await this.findAllPattern(args as { pattern: string; limit?: number });

Other Tools

Related 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