Skip to main content
Glama
jonmmease

jons-mcp-java

by jonmmease

definition

Navigate to symbol definitions in Java code by specifying file path and position to locate implementation details and references.

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main implementation of the 'definition' tool. This async function uses the @mcp.tool() decorator, sends an LSP 'textDocument/definition' request to the appropriate JDT.LS client, 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)
  • Import statement that loads the navigation module, triggering registration of the 'definition' tool via its @mcp.tool() decorator.
    from jons_mcp_java.tools import navigation, symbols, diagnostics, info  # noqa: E402, F401
  • Constant defining the LSP method name used in the definition tool request.
    LSP_TEXT_DOCUMENT_DEFINITION = "textDocument/definition"
  • Utility function used by the definition tool to normalize and format LSP location responses into a standard dictionary format.
    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": []}
  • Utility function used to convert file paths to LSP-compatible file:// URIs for requests.
    def path_to_uri(path: str | Path) -> str:
        """Convert a file path to a file:// URI."""
        if isinstance(path, str):
            path = Path(path)
    
        # Resolve to absolute path
        path = path.resolve()
    
        # Convert to URI format
        # On Unix, paths start with / so we get file:///
        path_str = str(path)
        if not path_str.startswith("/"):
            path_str = "/" + path_str
    
        # Quote special characters but preserve /
        encoded = quote(path_str, safe="/")
        return f"file://{encoded}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the return structure but doesn't disclose behavioral traits like error conditions, performance characteristics, or what happens if the symbol isn't found. The description adds some value but leaves significant gaps for a mutation-like navigation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement followed by Args and Returns sections. It's appropriately sized, though the Returns section could be slightly more concise. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (navigation with position parameters), no annotations, and the presence of an output schema, the description is reasonably complete. It explains parameters well and outlines return structure, though more behavioral context would help. The output schema reduces the need to fully document returns.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by clearly explaining all 3 parameters in the Args section: 'file_path' as absolute path, 'line' as 0-indexed line number, and 'character' as 0-indexed character position. This adds crucial meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Navigate to the definition of a symbol') and resource ('a symbol at the given position'), distinguishing it from siblings like 'hover' (which provides info) or 'references' (which finds usages). It precisely communicates what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when navigating to a symbol's definition in Java code, but doesn't explicitly state when to use this vs. alternatives like 'type_definition' or 'implementation'. It provides context but lacks explicit guidance on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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