list_file_symbols
Extract all symbols defined in a Python file to analyze code structure and identify functions, classes, and variables for navigation and refactoring.
Instructions
List all symbols defined in a file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/mcp_ty/server.py:210-243 (handler)The list_file_symbols function implements the logic for listing symbols in a file, including symbol parsing and error handling.
async def list_file_symbols(file_path: str) -> str: """List all symbols defined in a file.""" client = _get_client() path = Path(file_path).resolve() if not path.exists(): return _error(f"File not found: {file_path}") try: await client.open_document(path) symbols = await client.search_document_symbols(path) if not symbols: return _not_found(f"No symbols in {path.name}") def parse_symbol(sym: dict) -> dict: name = sym.get("name", "?") kind = SYMBOL_KINDS.get(sym.get("kind", 0), "Symbol") if "range" in sym: range_info = sym.get("range", {}).get("start", {}) else: range_info = sym.get("location", {}).get("range", {}).get("start", {}) line = range_info.get("line", 0) + 1 children = [parse_symbol(c) for c in sym.get("children", [])] result = {"name": name, "kind": kind, "line": line} if children: result["children"] = children return result parsed = [parse_symbol(sym) for sym in symbols] return _ok({"file": path.name, "path": str(path), "count": len(symbols), "symbols": parsed}) - src/mcp_ty/server.py:209-209 (registration)The list_file_symbols tool is registered using the @mcp.tool() decorator.
@mcp.tool()