Skip to main content
Glama
jonmmease

jons-mcp-java

by jonmmease

diagnostics

Identify and report Java code errors and warnings in specific files or across entire projects using Eclipse JDT.LS diagnostics.

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

  • The main handler for the 'diagnostics' MCP tool, decorated with @mcp.tool(). It retrieves diagnostics from the manager for a specific file or all files and formats them.
    @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 of the diagnostics tool (along with others) in the FastMCP server, which registers the tools due to the @mcp.tool() decorators.
    # Import tools to register them
    from jons_mcp_java.tools import navigation, symbols, diagnostics, info  # noqa: E402, F401
  • Helper function to format raw LSP diagnostics into a standardized dictionary format used by the tool.
    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