Bases: AXMTool
Find all functions/methods called by a given symbol.
Registered as ast_callees via axm.tools entry point.
This is the inverse of ast_callers: given a function name,
returns all call-sites within that function body.
Source code in packages/axm-ast/src/axm_ast/tools/callees.py
| Python |
|---|
| class CalleesTool(AXMTool):
"""Find all functions/methods called by a given symbol.
Registered as ``ast_callees`` via axm.tools entry point.
This is the inverse of ``ast_callers``: given a function name,
returns all call-sites *within* that function body.
"""
agent_hint: str = (
"Find all functions called by a symbol"
" — the inverse of ast_callers."
" Returns call-sites with module, line, call_expression."
)
@property
def name(self) -> str:
"""Return tool name for registry lookup."""
return "ast_callees"
@staticmethod
def render_text(callees: list[CalleeEntry], *, symbol: str) -> str:
"""Render callees as compact text for token-efficient MCP responses."""
header = f"ast_callees | {symbol} | {len(callees)} callees"
if not callees:
return header
lines = [header]
for c in callees:
module = c["module"].removeprefix("src.")
line = c["line"]
call_expression = c["call_expression"]
lines.append(f"{module}:{line} {call_expression}")
return "\n".join(lines)
@safe_execute
def execute(
self, *, path: str = ".", symbol: str | None = None, **kwargs: object
) -> ToolResult:
"""Find all callees of a symbol.
Args:
path: Path to package or workspace directory.
symbol: Symbol name to search for (required).
Returns:
ToolResult with callee list.
"""
if not symbol:
return ToolResult(success=False, error="symbol parameter is required")
project_path = Path(path).resolve()
if not project_path.is_dir():
return ToolResult(success=False, error=f"Not a directory: {project_path}")
try:
from axm_ast.core.flows import find_callees_workspace
from axm_ast.core.workspace import analyze_workspace
ws = analyze_workspace(project_path)
callees = find_callees_workspace(ws, symbol)
except ValueError:
from axm_ast.core.cache import get_package
from axm_ast.core.flows import find_callees
pkg = get_package(project_path)
callees = find_callees(pkg, symbol)
callee_data: list[CalleeEntry] = [
{
"module": c.module,
"line": c.line,
"call_expression": c.call_expression,
}
for c in callees
]
return ToolResult(
success=True,
data={"callees": callee_data, "count": len(callee_data)},
text=CalleesTool.render_text(callee_data, symbol=symbol),
)
|
Return tool name for registry lookup.
Find all callees of a symbol.
Parameters:
| Name |
Type |
Description |
Default |
path
|
str
|
Path to package or workspace directory.
|
'.'
|
symbol
|
str | None
|
Symbol name to search for (required).
|
None
|
Returns:
| Type |
Description |
ToolResult
|
ToolResult with callee list.
|
Source code in packages/axm-ast/src/axm_ast/tools/callees.py
| Python |
|---|
| @safe_execute
def execute(
self, *, path: str = ".", symbol: str | None = None, **kwargs: object
) -> ToolResult:
"""Find all callees of a symbol.
Args:
path: Path to package or workspace directory.
symbol: Symbol name to search for (required).
Returns:
ToolResult with callee list.
"""
if not symbol:
return ToolResult(success=False, error="symbol parameter is required")
project_path = Path(path).resolve()
if not project_path.is_dir():
return ToolResult(success=False, error=f"Not a directory: {project_path}")
try:
from axm_ast.core.flows import find_callees_workspace
from axm_ast.core.workspace import analyze_workspace
ws = analyze_workspace(project_path)
callees = find_callees_workspace(ws, symbol)
except ValueError:
from axm_ast.core.cache import get_package
from axm_ast.core.flows import find_callees
pkg = get_package(project_path)
callees = find_callees(pkg, symbol)
callee_data: list[CalleeEntry] = [
{
"module": c.module,
"line": c.line,
"call_expression": c.call_expression,
}
for c in callees
]
return ToolResult(
success=True,
data={"callees": callee_data, "count": len(callee_data)},
text=CalleesTool.render_text(callee_data, symbol=symbol),
)
|
render_text(callees, *, symbol)
staticmethod
Render callees as compact text for token-efficient MCP responses.
Source code in packages/axm-ast/src/axm_ast/tools/callees.py
| Python |
|---|
| @staticmethod
def render_text(callees: list[CalleeEntry], *, symbol: str) -> str:
"""Render callees as compact text for token-efficient MCP responses."""
header = f"ast_callees | {symbol} | {len(callees)} callees"
if not callees:
return header
lines = [header]
for c in callees:
module = c["module"].removeprefix("src.")
line = c["line"]
call_expression = c["call_expression"]
lines.append(f"{module}:{line} {call_expression}")
return "\n".join(lines)
|