document_symbols
Extract all symbols from a Java file to enable code navigation and analysis. This tool identifies classes, methods, and variables within Java source code for development workflows.
Instructions
Get all symbols defined in a Java file.
Args: file_path: Absolute path to the Java file
Returns: Dictionary with 'symbols' array or 'status'/'message' if initializing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/jons_mcp_java/tools/symbols.py:13-49 (handler)The primary handler function implementing the 'document_symbols' tool logic. It uses the JDT.LS client manager to get the appropriate LSP client, sends a documentSymbol request, formats the response, and returns the symbols.@mcp.tool() async def document_symbols( file_path: str, ) -> dict: """ Get all symbols defined in a Java file. Args: file_path: Absolute path to the Java file Returns: Dictionary with 'symbols' array or 'status'/'message' if initializing """ manager = get_manager() if manager is None: return {"status": "error", "message": "Server not initialized"} client, status = await manager.get_client_for_file_with_status(Path(file_path)) if client is None: return {"status": "initializing", "message": status} await client.ensure_file_open(file_path) response = await client.request( LSP_TEXT_DOCUMENT_DOCUMENT_SYMBOL, { "textDocument": {"uri": path_to_uri(file_path)}, } ) if response is None: return {"symbols": []} # Response is either DocumentSymbol[] or SymbolInformation[] symbols = [format_symbol(sym) for sym in response] return {"symbols": symbols}
- src/jons_mcp_java/server.py:65-65 (registration)Import statement in the main server file that loads the symbols module, thereby registering the 'document_symbols' tool via FastMCP's decorator system (@mcp.tool()).from jons_mcp_java.tools import navigation, symbols, diagnostics, info # noqa: E402, F401
- src/jons_mcp_java/tools/__init__.py:18-18 (registration)The 'document_symbols' tool is listed in the __all__ export list of the tools package, facilitating its import and registration."document_symbols",
- Imports helper functions used in the document_symbols handler: format_symbol to process LSP symbols and path_to_uri for URI conversion.from jons_mcp_java.utils import format_symbol, path_to_uri