UNPKG

kuzu-mcp-server

Version:

A Model Context Protocol (MCP) server for Kuzu graph databases. Enables LLMs like Claude to execute Cypher queries and analyze graph data with path invariance support.

121 lines (82 loc) 4.22 kB
# Kuzu MCP Server Upgrade Report This document details the changes and improvements made to the Kuzu MCP server implementation. ## Summary The Kuzu MCP server has been upgraded to properly implement the Kuzu database API requirements, specifically the mandatory progress callback function for query operations. This update resolves initialization issues and ensures reliable operation of the MCP server. ## Key Changes ### 1. Progress Callback Implementation All database operations now include the required progress callback function: ```javascript const progressCallback = (pipelineProgress, numPipelinesFinished, numPipelines) => { // Can use this to show progress if desired // console.log(`Progress: ${pipelineProgress}, Finished: ${numPipelinesFinished}/${numPipelines}`); }; ``` This callback is now passed to all query operations: ```javascript const result = await connection.query(cypher, progressCallback); ``` ### 2. Database Setup Scripts Created multiple setup script versions to troubleshoot and solve the initialization issues: - `setup-with-callback.js` - The final working version with proper callbacks - `setup-async.js` - Alternative implementation using different Promise patterns - `setup-db.js` - Initial implementation (superseded) ### 3. Error Handling Improvements Enhanced error handling with specific error messages and better reporting: ```javascript try { // Database operation } catch (error) { console.error(`Error executing query: ${error.message}`); throw error; } ``` ### 4. MCP Tool Refinements Updated the MCP tools with improved descriptions and parameter handling: - `query` tool - Execute arbitrary Cypher queries - `getSchema` tool - Retrieve database schema information - `generateKuzuCypher` tool - Generate Cypher from natural language ### 5. Auto-initialization Logic Added logic to automatically initialize the database when empty: ```javascript if (tables.length === 0 && !isReadOnly) { console.log("Database is empty. Running initial setup..."); // Run setup script if available try { const setupScript = path.join(__dirname, "setup-with-callback.js"); if (fs.existsSync(setupScript)) { console.log("Running setup script to initialize database..."); require(setupScript); } } catch (setupError) { console.error(`Failed to run setup script: ${setupError.message}`); } } ``` ## Technical Details ### API Issues Resolved The Kuzu database API requires a progress callback function as the second parameter to the `query` method. Omitting this parameter was causing initialization failures and query errors. ### Schema Implementation The database schema includes: 1. **Node Tables**: - `Person` (id, name, age, occupation) - `Location` (id, name, type, latitude, longitude) - `Concept` (id, name, description, field) 2. **Relationship Tables**: - `KNOWS` (PersonPerson, since, strength) - `LIVES_IN` (PersonLocation, since, is_primary) - `VISITED` (PersonLocation, date, purpose) - `UNDERSTANDS` (PersonConcept, proficiency, learned_date) - `RELATED_TO` (ConceptConcept, relationship_type, strength) ### Test Results The updated implementation successfully passes all tests: - Initialization: ✅ - Schema retrieval: ✅ - Cypher queries:## Future Work 1. **Connection Pooling** - Implement connection pooling for better performance with multiple concurrent queries 2. **Better Progress Reporting** - Enhance the progress callback to provide visual feedback for long-running queries 3. **Additional Cypher Examples** - Add more example queries demonstrating path invariance and other graph operations 4. **Integration with Pulse Server** - Provide direct integration with the pulse-data semantic search functionality 5. **WebSocket Interface** - Consider adding a WebSocket interface for real-time query results and notifications ## Conclusion The Kuzu MCP server now correctly implements the Kuzu API requirements and provides a stable platform for graph database operations through MCP. This enhances the Infinity Topos project with robust graph database capabilities for path invariance analysis and other graph-based operations.