Skip to main content
Glama

definition

Navigate to symbol definitions in Java code by specifying file path and position to find implementation locations.

Instructions

Navigate to the definition of a symbol at the given position.

Args: file_path: Absolute path to the Java file line: 0-indexed line number character: 0-indexed character position

Returns: Dictionary with 'locations' array or 'status'/'message' if initializing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
characterYes

Implementation Reference

  • Core implementation of the 'definition' MCP tool. Sends LSP 'textDocument/definition' request to the JDT.LS client for the given position and formats the response locations.
    @mcp.tool() async def definition( file_path: str, line: int, character: int, ) -> dict: """ Navigate to the definition of a symbol at the given position. Args: file_path: Absolute path to the Java file line: 0-indexed line number character: 0-indexed character position Returns: Dictionary with 'locations' array or 'status'/'message' if initializing """ manager = get_manager() if manager is None: return {"status": "error", "message": "Server not initialized"} # Get client with status feedback client, status = await manager.get_client_for_file_with_status(Path(file_path)) if client is None: return {"status": "initializing", "message": status} # Ensure file is open await client.ensure_file_open(file_path) # Make LSP request response = await client.request( LSP_TEXT_DOCUMENT_DEFINITION, { "textDocument": {"uri": path_to_uri(file_path)}, "position": {"line": line, "character": character} } ) return format_locations(response)
  • Explicit import of tools modules (including navigation.py containing 'definition') at server startup to register all @mcp.tool() functions with the FastMCP server.
    # Import tools to register them from jons_mcp_java.tools import navigation, symbols, diagnostics, info # noqa: E402, F401
  • LSP method constant used by the 'definition' handler to identify the definition request.
    LSP_TEXT_DOCUMENT_DEFINITION = "textDocument/definition" LSP_TEXT_DOCUMENT_TYPE_DEFINITION = "textDocument/typeDefinition"
  • Utility function to normalize and format LSP location responses (single or array of Location/LocationLink) into a consistent {'locations': [...]} dict, used by the handler.
    def format_locations(response: dict | list | None) -> dict: """ Normalize LSP Location response to a consistent format. LSP methods like definition can return: - null/None - Single Location object - Array of Location objects - Array of LocationLink objects This normalizes to: {"locations": [...]} """ if response is None: return {"locations": []} if isinstance(response, dict): # Single Location or LocationLink return {"locations": [_normalize_location(response)]} if isinstance(response, list): return {"locations": [_normalize_location(loc) for loc in response]} return {"locations": []}

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