Analyze Function
Deep dive analysis of a specific function including callers, callees, complexity, and data flow
Analyze Function
Perform a deep analysis of a specific function to understand its role, complexity, and impact.
Prerequisites
This command requires the --call-graph flag to be enabled when starting narsil-mcp. Check get_index_status to verify.
Workflow
The user should provide a function name. Parse $ARGUMENTS to extract:
- Repository name (if provided)
- Function name (required)
-
Find the function: Use
workspace_symbol_searchto locate the function if the exact location is unknown -
Get the source: Use
get_symbol_definitionto read the function code -
Analyze callers: Use
get_callerswithtransitive=trueandmax_depth=3to see what calls this function -
Analyze callees: Use
get_calleeswithtransitive=trueto see what this function calls -
Check complexity: Use
get_complexityto get cyclomatic and cognitive complexity metrics -
Data flow (if path is known): Use
get_data_flowto understand variable definitions and uses -
Control flow (if path is known): Use
get_control_flowto see branches and loops -
Summarize:
- Function purpose (based on code and naming)
- Complexity assessment (simple/moderate/complex)
- Dependency analysis (what it depends on, what depends on it)
- Risk assessment for modifications
- Suggestions for refactoring if complexity is high
Arguments
Function to analyze: $ARGUMENTS
Example usage:
/narsil:analyze-function handle_request/narsil:analyze-function myrepo process_payment