get_functions
Retrieve all functions in JavaScript/TypeScript code with metadata like name, type, location, and async status. Use for code reviews, API analysis, test coverage, refactoring prep, or performance audits.
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 |
|---|---|---|---|
| asyncOnly | No | Only return async functions (default: false). Use for async/await pattern analysis. | |
| includeAnonymous | No | Include anonymous functions (default: true). Set false to focus on named functions only. |
Input Schema (JSON Schema)
Implementation Reference
- src/index.ts:609-654 (handler)The primary handler implementing the get_functions tool. It retrieves function details from the parsed AST, applies filters for anonymous and async functions based on input arguments, stores the result in lastAnalysis, and returns a formatted list of functions with metadata.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:234-250 (schema)The JSON schema definition for the get_functions tool, specifying the input parameters includeAnonymous (boolean) and asyncOnly (boolean). Includes detailed description with usage examples.{ 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." } }, }, },
- src/index.ts:422-423 (registration)The registration/dispatch case in the main tool request handler switch statement that maps incoming 'get_functions' calls to the getFunctions handler method.case "get_functions": return await this.getFunctions(args as { includeAnonymous?: boolean; asyncOnly?: boolean });