Skip to main content
Glama

diagnostics

Identify and retrieve Java code errors and warnings for specific files or entire projects to support debugging and code quality improvement.

Instructions

Get diagnostics (errors, warnings) for a file or all files.

Args: file_path: Optional path to get diagnostics for a specific file. If not provided, returns diagnostics for all files.

Returns: Dictionary with 'diagnostics' array containing formatted diagnostic info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNo

Implementation Reference

  • Main handler for the 'diagnostics' MCP tool. Retrieves LSP diagnostics for a given file_path or all files using the JDTLS manager, formats them with _format_diagnostics, and returns a list of diagnostic dicts.
    @mcp.tool() async def diagnostics( file_path: str | None = None, ) -> dict: """ Get diagnostics (errors, warnings) for a file or all files. Args: file_path: Optional path to get diagnostics for a specific file. If not provided, returns diagnostics for all files. Returns: Dictionary with 'diagnostics' array containing formatted diagnostic info """ manager = get_manager() if manager is None: return {"status": "error", "message": "Server not initialized"} if file_path: # Get diagnostics for specific file raw_diagnostics = manager.get_diagnostics(Path(file_path)) formatted = _format_diagnostics(file_path, raw_diagnostics) return {"diagnostics": formatted} else: # Get all diagnostics all_raw = manager.get_all_diagnostics() all_formatted = [] for uri, diags in all_raw.items(): try: path = str(uri_to_path(uri)) except ValueError: path = uri all_formatted.extend(_format_diagnostics(path, diags)) return {"diagnostics": all_formatted}
  • Import statement in the main server file that loads the diagnostics module, executing its @mcp.tool() decorator to register the tool with the FastMCP server instance.
    # Import tools to register them from jons_mcp_java.tools import navigation, symbols, diagnostics, info # noqa: E402, F401
  • Helper function that formats raw LSP diagnostics into standardized dictionaries with file, line, severity, message, etc.
    def _format_diagnostics(file_path: str, diagnostics: list) -> list[dict]: """Format LSP diagnostics to a user-friendly format.""" result = [] for diag in diagnostics: range_obj = diag.get("range", {}) start = range_obj.get("start", {}) severity = diag.get("severity", 1) severity_name = { 1: "error", 2: "warning", 3: "information", 4: "hint", }.get(severity, "unknown") result.append({ "file": file_path, "line": start.get("line", 0), "character": start.get("character", 0), "severity": severity_name, "message": diag.get("message", ""), "source": diag.get("source", "jdtls"), "code": diag.get("code"), }) return result

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