Skip to main content
Glama
jonmmease

jons-mcp-java

by jonmmease

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
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • 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}
  • 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
  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jonmmease/jons-mcp-java'

If you have feedback or need assistance with the MCP directory API, please join our Discord server