read_enclosing
Locate the function, method, or class that contains a given line number in a file. Supports nesting depth to retrieve parent definitions for better code navigation.
Instructions
Find the enclosing function or class for a specific line number.
Given a file and line number, returns the complete enclosing definition (function, method, class, struct, etc.) containing that line. Use depth=2 to get the parent definition (e.g., the class containing a method). Falls back to a centered context window for unsupported languages or top-level code.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"absolute_file_path": "<absolute_file_path>",
"line": "<line>"
},
"name": "read_enclosing"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| absolute_file_path | Yes | Absolute path to target file | |
| line | Yes | Line number to find the enclosing function/class for | |
| depth | No | Nesting depth: 1 = innermost definition, 2 = parent (e.g., class containing a method) | |
| context_lines | No | Lines of context for fallback window when no enclosing definition is found |