get_functions
Extract JavaScript/TypeScript functions with metadata for code review, API analysis, test coverage, and refactoring preparation.
Instructions
Get all functions with metadata including name, type, location, and async status. Includes class methods, arrow functions, and declarations.
Examples: • Code review: get_functions() to see all functions in a file • Find async operations: get_functions({asyncOnly: true}) • API analysis: get_functions() then look for functions with 'fetch' or 'api' in names • Test coverage: get_functions() to identify functions needing tests • Refactoring prep: get_functions({includeAnonymous: false}) to focus on named functions • Performance audit: get_functions() to find large/complex functions by line count
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeAnonymous | No | Include anonymous functions (default: true). Set false to focus on named functions only. | |
| asyncOnly | No | Only return async functions (default: false). Use for async/await pattern analysis. |
Implementation Reference
- src/index.ts:609-654 (handler)The primary handler function for the 'get_functions' tool. It checks if AST is loaded, retrieves detailed function information using tree-hugger's getFunctionDetails(), applies filters for anonymous and async functions based on input args, truncates function text previews, stores results in lastAnalysis state, and returns a formatted JSON response listing all matching functions with metadata like name, type, location, and async status.private async getFunctions(args: { includeAnonymous?: boolean; asyncOnly?: boolean }) { if (!this.currentAST) { return { content: [{ type: "text", text: "No AST loaded. Please use parse_code first.", }], isError: true, }; } try { // Use enhanced library methods for detailed function analysis const functionData: FunctionInfo[] = this.currentAST.tree.getFunctionDetails() .filter(fn => { if (args.asyncOnly && !fn.async) return false; if (args.includeAnonymous === false && !fn.name) return false; return true; }) .map(fn => ({ ...fn, text: fn.text.length > 150 ? fn.text.slice(0, 150) + '...' : fn.text, })); this.lastAnalysis = { ...this.lastAnalysis, functions: functionData, timestamp: new Date(), } as AnalysisResult; return { content: [{ type: "text", text: `Found ${functionData.length} functions:\n${JSON.stringify(functionData, null, 2)}`, }], }; } catch (error) { return { content: [{ type: "text", text: `Error getting functions: ${error instanceof Error ? error.message : String(error)}`, }], isError: true, }; } }
- src/index.ts:422-423 (registration)The switch case in the MCP CallToolRequestHandler that detects 'get_functions' tool calls and dispatches to the private getFunctions implementation.case "get_functions": return await this.getFunctions(args as { includeAnonymous?: boolean; asyncOnly?: boolean });
- src/index.ts:234-250 (schema)Tool registration object defining the 'get_functions' name, detailed description with usage examples, and input schema specifying optional boolean parameters for filtering anonymous and async-only functions.{ name: "get_functions", description: "Get all functions with metadata including name, type, location, and async status. Includes class methods, arrow functions, and declarations.\n\nExamples:\n• Code review: get_functions() to see all functions in a file\n• Find async operations: get_functions({asyncOnly: true})\n• API analysis: get_functions() then look for functions with 'fetch' or 'api' in names\n• Test coverage: get_functions() to identify functions needing tests\n• Refactoring prep: get_functions({includeAnonymous: false}) to focus on named functions\n• Performance audit: get_functions() to find large/complex functions by line count", inputSchema: { type: "object", properties: { includeAnonymous: { type: "boolean", description: "Include anonymous functions (default: true). Set false to focus on named functions only." }, asyncOnly: { type: "boolean", description: "Only return async functions (default: false). Use for async/await pattern analysis." } }, }, },