Skip to main content
Glama
diagnostics.ts2.04 kB
import { Diagnostic, DiagnosticSeverity, LSPDiagnostic, LSPDiagnosticSeverity, } from './types.js'; /** * In-memory diagnostic cache */ export class DiagnosticCache { private cache = new Map<string, Diagnostic[]>(); /** * Store diagnostics for a file path */ set(filePath: string, diagnostics: Diagnostic[]): void { this.cache.set(filePath, diagnostics); } /** * Get diagnostics for a file path */ get(filePath: string): Diagnostic[] { return this.cache.get(filePath) ?? []; } /** * Clear diagnostics for a file path */ clear(filePath: string): void { this.cache.delete(filePath); } /** * Clear all diagnostics */ clearAll(): void { this.cache.clear(); } /** * Get all diagnostics as a map */ getAll(): Record<string, Diagnostic[]> { const result: Record<string, Diagnostic[]> = {}; for (const [path, diagnostics] of this.cache.entries()) { result[path] = diagnostics; } return result; } } /** * Convert LSP severity to MCP severity */ function convertSeverity(lspSeverity?: LSPDiagnosticSeverity): DiagnosticSeverity { switch (lspSeverity) { case LSPDiagnosticSeverity.Error: return 'error'; case LSPDiagnosticSeverity.Warning: return 'warning'; case LSPDiagnosticSeverity.Information: case LSPDiagnosticSeverity.Hint: return 'info'; default: return 'error'; // Default to error if severity unknown } } /** * Transform LSP diagnostic to MCP diagnostic format */ export function transformDiagnostic(lspDiag: LSPDiagnostic): Diagnostic { return { line: lspDiag.range.start.line + 1, // LSP is 0-indexed, convert to 1-indexed column: lspDiag.range.start.character + 1, severity: convertSeverity(lspDiag.severity), message: lspDiag.message, code: lspDiag.code?.toString(), }; } /** * Transform array of LSP diagnostics */ export function transformDiagnostics(lspDiags: LSPDiagnostic[]): Diagnostic[] { return lspDiags.map(transformDiagnostic); }

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/ryanmazzolini/minimal-godot-mcp'

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