Skip to main content
Glama

get_diagnostics

Identify type errors and warnings in Python code files to improve code quality and prevent runtime issues.

Instructions

Get type errors and warnings for a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • MCP tool handler for 'get_diagnostics' which calls the underlying LSP client.
    @mcp.tool()
    async def get_diagnostics(file_path: str) -> str:
        """Get type errors and warnings for a file."""
        client = _get_client()
    
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            await client.open_document(path)
    
            import asyncio
            await asyncio.sleep(0.5)
    
            diagnostics = client.get_diagnostics(path)
    
            if not diagnostics:
                return _ok({"file": path.name, "count": 0, "diagnostics": []})
    
            diag_list = []
            for diag in diagnostics:
                severity = SEVERITY_MAP.get(diag.severity or 1, "error")
                diag_list.append({
                    "line": diag.range.start.line + 1,
                    "column": diag.range.start.character + 1,
                    "severity": severity,
  • The underlying LSP client method that retrieves cached diagnostics for a given file path.
    def get_diagnostics(self, file_path: str | Path) -> list[Diagnostic]:
        """Get cached diagnostics for a file."""
        file_path = Path(file_path).resolve()
        uri = file_path.as_uri()
        return self._diagnostics.get(uri, [])

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/qinsehm1128/mcp-ty'

If you have feedback or need assistance with the MCP directory API, please join our Discord server