zignet
Version:
MCP server for Zig â AI-powered code analysis, validation, and documentation with fine-tuned LLM
1 lines âĸ 29.4 kB
Source Map (JSON)
{"version":3,"file":"mcp-server.cjs","names":["modelDownloader","LlamaChatSession","globalLLM: ZigNetLLM | null","blocks: string[]","fixes: Fix[]","codeBlocks: string[]","descriptions: string[]","Server","ListToolsRequestSchema","SUPPORTED_ZIG_VERSIONS","DEFAULT_ZIG_VERSION","CallToolRequestSchema","formatAnalyzeResult","analyzeZig","formatCompileResult","compileZig","modelDownloader","StdioServerTransport"],"sources":["../src/llm/session.ts","../src/tools/docs.ts","../src/tools/suggest.ts","../src/mcp-server.ts"],"sourcesContent":["import {\n getLlama,\n LlamaModel,\n LlamaContext,\n LlamaChatSession,\n} from \"node-llama-cpp\";\nimport { modelDownloader } from \"./model-downloader.js\";\n\nexport interface LLMConfig {\n modelPath?: string;\n gpuDevice?: string;\n gpuLayers?: number;\n contextSize?: number;\n temperature?: number;\n topP?: number;\n}\n\nexport class ZigNetLLM {\n private model: LlamaModel | null = null;\n private context: LlamaContext | null = null;\n private session: LlamaChatSession | null = null;\n private config: Required<Omit<LLMConfig, \"gpuDevice\">> & {\n gpuDevice?: string;\n };\n\n constructor(config: LLMConfig = {}) {\n this.config = {\n modelPath: config.modelPath || \"\",\n gpuDevice: config.gpuDevice,\n gpuLayers: config.gpuLayers ?? 35, // RTX 3090 can handle all layers\n contextSize: config.contextSize ?? 4096,\n temperature: config.temperature ?? 0.7,\n topP: config.topP ?? 0.9,\n };\n }\n\n /**\n * Initialize the LLM model and session\n */\n async initialize(): Promise<void> {\n if (this.session) {\n console.log(\"âšī¸ LLM already initialized\");\n return;\n }\n\n console.log(\"đ Initializing ZigNet LLM...\");\n\n // Set GPU device if specified (applies CUDA_VISIBLE_DEVICES)\n if (this.config.gpuDevice !== undefined) {\n process.env.CUDA_VISIBLE_DEVICES = this.config.gpuDevice;\n console.log(`đ¯ GPU device selection: ${this.config.gpuDevice}`);\n }\n\n // Get model path (download if needed)\n const modelPath =\n this.config.modelPath ||\n (await modelDownloader.ensureModel((progress) => {\n if (progress.percent % 10 < 1) {\n // Log every 10%\n console.log(\n `đĨ Downloading model: ${progress.percent.toFixed(1)}%`,\n );\n }\n }));\n\n console.log(`đĻ Loading model: ${modelPath}`);\n console.log(`đŽ GPU layers: ${this.config.gpuLayers}`);\n\n // Initialize llama\n const llama = await getLlama();\n\n // Load model\n this.model = await llama.loadModel({\n modelPath,\n gpuLayers: this.config.gpuLayers,\n });\n\n // Create context\n this.context = await this.model.createContext({\n contextSize: this.config.contextSize,\n });\n\n // Create chat session with Zig-specific system prompt\n this.session = new LlamaChatSession({\n contextSequence: this.context.getSequence(),\n systemPrompt: `You are ZigNet, an AI assistant specialized in Zig programming language (v0.13-0.15).\n\nYour expertise includes:\n- Explaining Zig syntax, features, and idioms\n- Understanding comptime, generics, and error handling\n- Providing code examples and fixes\n- Referencing official Zig documentation\n\nAlways:\n- Generate idiomatic Zig code\n- Explain Zig-specific concepts clearly\n- Suggest best practices\n- Validate syntax mentally before responding\n\nWhen unsure, reference official Zig docs or suggest using 'zig ast-check'.`,\n });\n\n console.log(\"â
LLM initialized successfully!\");\n }\n\n /**\n * Query the LLM with a prompt\n */\n async query(prompt: string): Promise<string> {\n if (!this.session) {\n await this.initialize();\n }\n\n if (!this.session) {\n throw new Error(\"Failed to initialize LLM session\");\n }\n\n console.log(`đ¤ Querying LLM: ${prompt.substring(0, 50)}...`);\n\n const response = await this.session.prompt(prompt, {\n temperature: this.config.temperature,\n topP: this.config.topP,\n });\n\n return response;\n }\n\n /**\n * Dispose resources\n */\n dispose(): void {\n if (this.context) {\n void this.context.dispose();\n this.context = null;\n }\n if (this.model) {\n void this.model.dispose();\n this.model = null;\n }\n this.session = null;\n console.log(\"đī¸ LLM resources disposed\");\n }\n}\n\n/**\n * Singleton instance\n */\nlet globalLLM: ZigNetLLM | null = null;\n\n/**\n * Get or create the global LLM instance\n */\nexport async function getLLM(config?: LLMConfig): Promise<ZigNetLLM> {\n if (!globalLLM) {\n // If no config provided, load from environment\n if (!config) {\n const {\n MODEL_PATH,\n GPU_DEVICE,\n GPU_LAYERS,\n CONTEXT_SIZE,\n TEMPERATURE,\n TOP_P,\n } = await import(\"../config.js\");\n config = {\n modelPath: MODEL_PATH,\n gpuDevice: GPU_DEVICE,\n gpuLayers: GPU_LAYERS,\n contextSize: CONTEXT_SIZE,\n temperature: TEMPERATURE,\n topP: TOP_P,\n };\n }\n globalLLM = new ZigNetLLM(config);\n await globalLLM.initialize();\n }\n return globalLLM;\n}\n\n/**\n * Dispose the global LLM instance\n */\nexport function disposeLLM(): void {\n if (globalLLM) {\n globalLLM.dispose();\n globalLLM = null;\n }\n}\n","/**\n * get_zig_docs tool - Query Zig documentation using LLM\n */\n\nimport { getLLM } from \"../llm/session.js\";\n\nexport interface GetZigDocsArgs {\n topic: string;\n detail_level?: \"basic\" | \"intermediate\" | \"advanced\";\n}\n\nexport interface GetZigDocsResult {\n topic: string;\n documentation: string;\n examples?: string[];\n}\n\n/**\n * Get Zig documentation for a specific topic\n */\nexport async function getZigDocs(\n args: GetZigDocsArgs,\n): Promise<GetZigDocsResult> {\n const { topic, detail_level = \"intermediate\" } = args;\n\n console.log(`đ Getting Zig docs for: ${topic} (${detail_level})`);\n\n // Construct prompt based on detail level\n const detailInstructions = {\n basic: \"Provide a brief, beginner-friendly explanation.\",\n intermediate: \"Provide a detailed explanation with practical examples.\",\n advanced:\n \"Provide an in-depth explanation covering edge cases, best practices, and advanced patterns.\",\n };\n\n const prompt = `Explain the following Zig programming concept: \"${topic}\"\n\n${detailInstructions[detail_level]}\n\nFormat your response as:\n1. A clear definition/explanation\n2. One or more code examples\n3. Key points to remember\n\nBe specific to Zig versions 0.13-0.15.`;\n\n try {\n const llm = await getLLM();\n const response = await llm.query(prompt);\n\n // Parse response to extract examples if possible\n const examples = extractCodeBlocks(response);\n\n return {\n topic,\n documentation: response,\n examples: examples.length > 0 ? examples : undefined,\n };\n } catch (error) {\n throw new Error(\n `Failed to get Zig docs: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n\n/**\n * Extract code blocks from markdown text\n */\nfunction extractCodeBlocks(text: string): string[] {\n const codeBlockRegex = /```(?:zig)?\\n([\\s\\S]*?)```/g;\n const blocks: string[] = [];\n let match;\n\n while ((match = codeBlockRegex.exec(text)) !== null) {\n blocks.push(match[1].trim());\n }\n\n return blocks;\n}\n","/**\n * suggest_fix tool - Suggest intelligent fixes for Zig errors\n */\n\nimport { getLLM } from \"../llm/session.js\";\n\nexport interface SuggestFixArgs {\n error_message: string;\n code_context?: string;\n error_type?: \"syntax\" | \"type\" | \"semantic\" | \"runtime\";\n}\n\nexport interface SuggestFixResult {\n error_summary: string;\n suggested_fixes: Fix[];\n explanation: string;\n}\n\nexport interface Fix {\n description: string;\n code_before?: string;\n code_after: string;\n rationale: string;\n}\n\n/**\n * Suggest fixes for Zig compilation errors\n */\nexport async function suggestFix(\n args: SuggestFixArgs,\n): Promise<SuggestFixResult> {\n const { error_message, code_context, error_type = \"semantic\" } = args;\n\n console.log(`đĄ Suggesting fix for: ${error_message.substring(0, 50)}...`);\n\n // Construct prompt with error context\n const prompt = `You are analyzing a Zig compilation error. Help fix it.\n\nError Message:\n\\`\\`\\`\n${error_message}\n\\`\\`\\`\n\n${code_context ? `Code Context:\\n\\`\\`\\`zig\\n${code_context}\\n\\`\\`\\`\\n` : \"\"}\n\nError Type: ${error_type}\n\nProvide:\n1. A brief summary of what's wrong\n2. 1-3 concrete fix suggestions with code examples\n3. Explanation of why each fix works\n\nFormat your response clearly with code blocks for fixes.`;\n\n try {\n const llm = await getLLM();\n const response = await llm.query(prompt);\n\n // Parse the response (simplified - could be more sophisticated)\n const fixes = parseFixes(response);\n\n return {\n error_summary: extractErrorSummary(response),\n suggested_fixes: fixes,\n explanation: response,\n };\n } catch (error) {\n throw new Error(\n `Failed to suggest fix: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n\n/**\n * Extract error summary from LLM response\n */\nfunction extractErrorSummary(response: string): string {\n // Look for first paragraph or sentence\n const lines = response.split(\"\\n\").filter((line) => line.trim());\n return lines[0] || \"Error analysis\";\n}\n\n/**\n * Parse fix suggestions from LLM response\n */\nfunction parseFixes(response: string): Fix[] {\n const fixes: Fix[] = [];\n\n // Extract code blocks\n const codeBlockRegex = /```(?:zig)?\\n([\\s\\S]*?)```/g;\n const codeBlocks: string[] = [];\n let match;\n\n while ((match = codeBlockRegex.exec(response)) !== null) {\n codeBlocks.push(match[1].trim());\n }\n\n // Try to find fix descriptions\n const fixPattern = /(?:Fix|Option|Solution)\\s*\\d*[:.]\\s*([^\\n]+)/gi;\n const descriptions: string[] = [];\n\n while ((match = fixPattern.exec(response)) !== null) {\n descriptions.push(match[1].trim());\n }\n\n // Combine descriptions with code blocks\n for (let i = 0; i < Math.max(descriptions.length, codeBlocks.length); i++) {\n fixes.push({\n description: descriptions[i] || `Fix option ${i + 1}`,\n code_after: codeBlocks[i] || \"// See explanation above\",\n rationale: `Addresses the ${extractErrorSummary(response)}`,\n });\n }\n\n // If no structured fixes found, create a generic one\n if (fixes.length === 0) {\n fixes.push({\n description: \"Suggested fix\",\n code_after: codeBlocks[0] || \"// See detailed explanation\",\n rationale: \"Based on error analysis\",\n });\n }\n\n return fixes;\n}\n","/**\n * ZigNet MCP Server\n *\n * Model Context Protocol server for Zig code analysis and assistance.\n *\n * Tools:\n * - analyze_zig: Analyze Zig code for errors and validation\n * - compile_zig: Compile and format Zig code\n * - get_zig_docs: Retrieve Zig documentation\n * - suggest_fix: Get intelligent fix suggestions\n */\n\nimport { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';\n\n// Import tool implementations\nimport { analyzeZig, formatAnalyzeResult } from \"./tools/analyze.js\";\nimport { compileZig, formatCompileResult } from \"./tools/compile.js\";\nimport { getZigDocs } from \"./tools/docs.js\";\nimport { suggestFix } from \"./tools/suggest.js\";\n\n// Import configuration\nimport { SUPPORTED_ZIG_VERSIONS, DEFAULT_ZIG_VERSION } from './config.js';\n\n/**\n * Create and configure the MCP server\n */\nfunction createServer() {\n const server = new Server(\n {\n name: 'zignet',\n version: '0.15.2-h',\n },\n {\n capabilities: {\n tools: {},\n },\n }\n );\n\n /**\n * Handler for listing available tools\n */\n server.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: 'analyze_zig',\n description:\n 'Analyze Zig code for syntax errors, type mismatches, and semantic issues using the official Zig compiler',\n inputSchema: {\n type: 'object',\n properties: {\n code: {\n type: 'string',\n description: 'Zig source code to analyze',\n },\n zig_version: {\n type: 'string',\n enum: SUPPORTED_ZIG_VERSIONS as unknown as string[],\n description: `Zig version to use for validation (default: ${DEFAULT_ZIG_VERSION})`,\n },\n },\n required: ['code'],\n },\n },\n {\n name: 'compile_zig',\n description: 'Format Zig code using the official Zig formatter',\n inputSchema: {\n type: 'object',\n properties: {\n code: {\n type: 'string',\n description: 'Zig source code to format',\n },\n zig_version: {\n type: 'string',\n enum: SUPPORTED_ZIG_VERSIONS as unknown as string[],\n description: `Zig version to use for formatting (default: ${DEFAULT_ZIG_VERSION})`,\n },\n },\n required: ['code'],\n },\n },\n {\n name: 'get_zig_docs',\n description: 'Retrieve Zig documentation for specific topics',\n inputSchema: {\n type: 'object',\n properties: {\n topic: {\n type: 'string',\n description:\n \"Topic to get documentation for (e.g., 'comptime', 'generics')\",\n },\n },\n required: ['topic'],\n },\n },\n {\n name: 'suggest_fix',\n description: 'Get intelligent suggestions for fixing Zig code errors',\n inputSchema: {\n type: 'object',\n properties: {\n error: {\n type: 'string',\n description: 'Error message to get fix suggestions for',\n },\n code: {\n type: 'string',\n description: 'Code context where the error occurred',\n },\n },\n required: ['error', 'code'],\n },\n },\n ],\n };\n });\n\n /**\n * Handler for tool execution\n */\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args = {} } = request.params;\n\n switch (name) {\n case 'analyze_zig': {\n const code = (args as { code?: string; zig_version?: string }).code;\n const zig_version = (args as { zig_version?: '0.13.0' | '0.14.0' | '0.15.0' })\n .zig_version;\n\n if (!code) {\n throw new Error('Missing required argument: code');\n }\n\n const result = await analyzeZig({ code, zig_version });\n return {\n content: [\n {\n type: 'text',\n text: formatAnalyzeResult(result),\n },\n ],\n };\n }\n\n case 'compile_zig': {\n const compileArgs = args as {\n code?: string;\n zig_version?: '0.13.0' | '0.14.0' | '0.15.0';\n };\n if (!compileArgs.code) {\n throw new Error('Missing required argument: code');\n }\n\n const result = await compileZig({\n code: compileArgs.code,\n zig_version: compileArgs.zig_version,\n });\n return {\n content: [\n {\n type: 'text',\n text: formatCompileResult(result),\n },\n ],\n };\n }\n\n case \"get_zig_docs\": {\n const docsArgs = args as {\n topic?: string;\n detail_level?: \"basic\" | \"intermediate\" | \"advanced\";\n };\n if (!docsArgs.topic) {\n throw new Error(\"Missing required argument: topic\");\n }\n\n const result = await getZigDocs({\n topic: docsArgs.topic,\n detail_level: docsArgs.detail_level,\n });\n\n return {\n content: [\n {\n type: \"text\",\n text: `# Zig Documentation: ${result.topic}\\n\\n${result.documentation}`,\n },\n ],\n };\n }\n\n case \"suggest_fix\": {\n const fixArgs = args as {\n error_message?: string;\n code_context?: string;\n error_type?: \"syntax\" | \"type\" | \"semantic\" | \"runtime\";\n };\n if (!fixArgs.error_message) {\n throw new Error(\"Missing required argument: error_message\");\n }\n\n const result = await suggestFix({\n error_message: fixArgs.error_message,\n code_context: fixArgs.code_context,\n error_type: fixArgs.error_type,\n });\n\n // Format fixes\n const fixesText = result.suggested_fixes\n .map(\n (fix, i) =>\n `## Fix ${i + 1}: ${fix.description}\\n\\n\\`\\`\\`zig\\n${fix.code_after}\\n\\`\\`\\`\\n\\n**Rationale**: ${fix.rationale}`,\n )\n .join(\"\\n\\n\");\n\n return {\n content: [\n {\n type: \"text\",\n text: `# Error Fix Suggestions\\n\\n**Error**: ${result.error_summary}\\n\\n${fixesText}\\n\\n## Full Analysis\\n\\n${result.explanation}`,\n },\n ],\n };\n }\n\n default:\n throw new Error(`Unknown tool: ${name}`);\n }\n });\n\n return server;\n}\n\n/**\n * Main entry point\n */\nasync function main() {\n console.error('đ ZigNet MCP Server starting...');\n\n // Log configuration\n console.error(`đ Configuration:`);\n console.error(` - Zig versions: ${SUPPORTED_ZIG_VERSIONS.join(', ')}`);\n console.error(` - Default version: ${DEFAULT_ZIG_VERSION}`);\n\n // Check and download model if needed\n const { modelDownloader } = await import('./llm/model-downloader.js');\n const modelAvailable = modelDownloader.isModelAvailable();\n\n console.error(`đ¤ Model status:`);\n if (modelAvailable) {\n console.error(` â
Model ready: ${modelDownloader.getModelPath()}`);\n } else {\n console.error(` đĨ Model not found - downloading now...`);\n console.error(` đ Target: ${modelDownloader.getModelPath()}`);\n\n try {\n let lastLoggedPercent = -1;\n await modelDownloader.ensureModel((progress) => {\n // Log progress every 5% (only when crossing the threshold)\n const currentMilestone = Math.floor(progress.percent / 5) * 5;\n if (currentMilestone > lastLoggedPercent && currentMilestone % 5 === 0) {\n console.error(` đĻ Download progress: ${currentMilestone}% (${(progress.downloaded / 1024 / 1024).toFixed(0)}MB / ${(progress.total / 1024 / 1024).toFixed(0)}MB)`);\n lastLoggedPercent = currentMilestone;\n }\n });\n console.error(` â
Model downloaded successfully!`);\n } catch (error) {\n console.error(` â ī¸ Model download failed: ${error}`);\n console.error(` âšī¸ LLM tools (get_zig_docs, suggest_fix) will not be available`);\n console.error(` âšī¸ Deterministic tools (analyze_zig, compile_zig) will still work`);\n }\n }\n\n const server = createServer();\n const transport = new StdioServerTransport();\n\n await server.connect(transport);\n\n console.error('â
ZigNet MCP Server running on stdio');\n console.error('đĄ Available tools: analyze_zig, compile_zig, get_zig_docs, suggest_fix');\n} main().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,IAAa,YAAb,MAAuB;CACnB,A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