-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Component
MCP Server
Bug Description
Summary
When any native C++ module (better-sqlite3, onnxruntime-node, sqlite-vec) fails to load, the entire MCP server crashes and all memesh tools become completely unavailable. There is no fallback mechanism or graceful degradation.
What Happened
In Claude Desktop Cowork environment (Ubuntu 22 ARM64 sandbox), better-sqlite3 cannot compile due to:
- Plugin directory is read-only filesystem (sandbox security)
node-gypcannot download Node.js headers (network restriction, HTTP 403)
Because ConnectionPool.ts has a hard import Database from 'better-sqlite3' at the top level, the import fails immediately and the entire MCP server process crashes before any tool can register.
Expected Behavior
The MCP server should start with reduced functionality when native modules are unavailable:
- Core MCP tools should still register (even if some features are limited)
- Clear warning/error message explaining which features are degraded
- Suggest user actions (e.g., "Run npm rebuild" or "Set MEMESH_API_KEY for cloud-only mode")
Impact
- 100% of plugin functionality lost when a single native module fails
- Affects all users in sandboxed/restricted environments (Cowork, Docker, CI/CD)
- No error message visible to user — tools simply don't appear
Steps to Reproduce
- Install memesh plugin in Claude Desktop Cowork mode
- Start a new Cowork session
- The MCP server fails silently during bootstrap (
server-bootstrap.js) - No memesh tools appear in the available tools list
- User has no indication of what went wrong
Root cause chain:
server-bootstrap.js
→ ServerInitializer.ts → KnowledgeGraph.createSync()
→ ConnectionPool.ts → import Database from 'better-sqlite3'
→ Native .node binary not found → CRASH
Error Output
Error: Cannot find module 'better-sqlite3'
or: Error: The module was compiled against a different Node.js version
node-gyp rebuild errors:
gyp ERR! stack Error: 403 response downloading https://nodejs.org/download/release/v22.22.0/node-v22.22.0-headers.tar.gz
gyp ERR! System Linux 6.8.0-94-generic
gyp ERR! node -v v22.22.0
Also: .claude-plugin/memesh/ is read-only filesystem:
mkdir: cannot create directory 'node_modules': Read-only file systemMeMesh Version
2.8.10
Claude Code Client
Other
Node.js Version
v22.22.0
Operating System
Linux
MCP Configuration
{
"memesh": {
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/dist/mcp/server-bootstrap.js"],
"env": {
"NODE_ENV": "production",
"MEMESH_DISABLE_DAEMON": "1"
}
}
}Additional Context
Suggested Fix (backward compatible)
Option 1: Dynamic import with try/catch (recommended)
Wrap the better-sqlite3 import in a dynamic import with fallback:
// src/db/ConnectionPool.ts
let Database: any;
let nativeModuleAvailable = false;
try {
Database = (await import('better-sqlite3')).default;
nativeModuleAvailable = true;
} catch (e) {
logger.warn('[memesh] better-sqlite3 not available. Memory features will be limited.');
}Option 2: Ship prebuild binaries
Include prebuilt binaries for common platforms in the npm package (see issue #73 for details).
Option 3: Add sql.js as pure-JS fallback
Add sql.js (WebAssembly SQLite) as optional fallback when native module unavailable.
Related
- [Bug]: MCP Server fails to start in Claude Desktop Cowork environment (better-sqlite3 native compilation blocked) #73 — MCP Server fails to start in Claude Desktop Cowork environment
- This issue focuses on the architectural gap (no graceful degradation), while [Bug]: MCP Server fails to start in Claude Desktop Cowork environment (better-sqlite3 native compilation blocked) #73 focuses on the specific native compilation problem.
Environment
- Plugin: @pcircle/memesh v2.8.10
- Platform: Claude Desktop Cowork (Ubuntu 22.04 ARM64 sandbox)
- Node.js: v22.22.0
- All native build tools present (gcc, g++, make, python3) but blocked by sandbox