hover
Retrieve Java documentation and type information for symbols at specific positions in files to understand code functionality during development.
Instructions
Get hover information (Javadoc, type info) for 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 'content' (markdown) or 'status'/'message' if initializing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| line | Yes | ||
| character | Yes |
Implementation Reference
- src/jons_mcp_java/tools/info.py:10-75 (handler)The core handler for the 'hover' MCP tool. It uses the JDT.LS client to send an LSP 'textDocument/hover' request for the given position in a Java file and processes the response contents into a markdown-formatted string.@mcp.tool() async def hover( file_path: str, line: int, character: int, ) -> dict: """ Get hover information (Javadoc, type info) for 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 'content' (markdown) 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_HOVER, { "textDocument": {"uri": path_to_uri(file_path)}, "position": {"line": line, "character": character} } ) if response is None: return {"content": None, "message": "No hover information available"} # Extract content from hover response contents = response.get("contents", {}) if isinstance(contents, str): return {"content": contents} if isinstance(contents, dict): # MarkupContent return {"content": contents.get("value", "")} if isinstance(contents, list): # Array of MarkedString or MarkupContent parts = [] for item in contents: if isinstance(item, str): parts.append(item) elif isinstance(item, dict): if "value" in item: parts.append(item["value"]) elif "language" in item: # MarkedString with language lang = item.get("language", "") value = item.get("value", "") parts.append(f"```{lang}\n{value}\n```") return {"content": "\n\n".join(parts)} return {"content": None}
- src/jons_mcp_java/server.py:65-65 (registration)Import of tool modules (including info.py containing hover) after FastMCP server creation, which registers all @mcp.tool()-decorated functions as MCP tools.from jons_mcp_java.tools import navigation, symbols, diagnostics, info # noqa: E402, F401
- src/jons_mcp_java/constants.py:17-17 (helper)LSP method constant used in the hover tool's LSP request.LSP_TEXT_DOCUMENT_HOVER = "textDocument/hover"
- src/jons_mcp_java/tools/__init__.py:11-11 (registration)Explicit import of the hover function to expose it via tools.__init__ for the server registration import.from jons_mcp_java.tools.info import hover
- src/jons_mcp_java/client.py:412-412 (helper)Client LSP capabilities declaration requesting hover support with markdown/plaintext content format from JDT.LS."hover": {"contentFormat": ["markdown", "plaintext"]},