Skip to content

fix(mcp): rvlite tools now use ESM dynamic import for v0.2.x compatibility#306

Open
luminexo wants to merge 1 commit intoruvnet:mainfrom
luminexo:fix/mcp-rvlite-esm-import
Open

fix(mcp): rvlite tools now use ESM dynamic import for v0.2.x compatibility#306
luminexo wants to merge 1 commit intoruvnet:mainfrom
luminexo:fix/mcp-rvlite-esm-import

Conversation

@luminexo
Copy link
Copy Markdown

Summary

Fixes #302

The MCP server tools rvlite_sql, rvlite_cypher, and rvlite_sparql were failing with "rvlite package not installed" because they used CJS require('rvlite') on an ESM-only package (v0.2.x).

Root Cause

  • rvlite v0.2.x removed CJS entry point
  • require('rvlite') returns empty object {}
  • MCP tools checked for rvlite.CypherEngine, found undefined, and reported "not installed"

Fix

  • Changed from CJS require() to ESM dynamic import('rvlite/wasm')
  • Added proper WASM initialization via initSync() with buffer
  • Added engine caching to avoid re-initializing on every call
  • Added helpful error messages for ESM-related failures

Testing

The fix follows the same pattern used in the issue report's workaround:

// Before (broken)
const rvlite = require('rvlite');  // → {} (empty object)
const db = new rvlite.Database();  // → TypeError

// After (fixed)
const rvlite = await import('rvlite/wasm');
const { readFileSync } = await import('fs');
rvlite.initSync(readFileSync('node_modules/rvlite/dist/wasm/rvlite_bg.wasm'));
const db = new rvlite.Database();  // → Works!

Files Changed

  • npm/packages/ruvector/bin/mcp-server.js — Updated rvlite_sql, rvlite_cypher, rvlite_sparql handlers

Impact

  • All rvlite_* MCP tools will now work correctly with rvlite v0.2.x
  • Backward compatible with future versions that may restore CJS support
  • No changes to external API — tools return same JSON format

…ility

Issue: ruvnet#302

- Changed from CJS require('rvlite') to ESM dynamic import('rvlite/wasm')
- Added initSync() with WASM buffer for proper initialization
- Added engine caching to avoid re-initializing on every call
- Added helpful error messages for ESM-related failures

The rvlite package v0.2.x is ESM-only. The previous CJS require()
returned an empty object, causing all rvlite_sql, rvlite_cypher,
and rvlite_sparql tools to fail with 'package not installed' errors.

With this fix, the MCP server correctly loads the ESM module and
initializes the WASM binary for Node.js environments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mcp): rvlite_cypher tool reports 'not installed' — CJS require() on ESM-only package

1 participant