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
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/mcp_ty/server.py:435-461 (handler)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, - src/mcp_ty/lsp_client.py:624-628 (helper)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, [])