-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Description
Description
The AgentDB CLI (agentdb-cli.js) fails when executed via npx agentdb with the error:
❌ __dirname is not defined
This affects all MCP tools that rely on the CLI:
agentdb_statsagentdb_pattern_storeagentdb_pattern_searchagentdb_pattern_stats
Environment
- agentic-flow version: 1.10.2
- Node.js: v22.x
- OS: macOS (Darwin 25.1.0)
Root Cause
The file dist/agentdb/cli/agentdb-cli.js is an ES module (uses import statements) but references __dirname on line 55:
const schemaPath = path.join(__dirname, '../schemas/frontier-schema.sql');In ES modules, __dirname and __filename are not available - they only exist in CommonJS modules.
Suggested Fix
Add the standard ESM polyfill at the top of the file after the existing imports:
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
// ESM __dirname polyfill
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);Source File
The fix should be applied to the TypeScript source file (likely src/agentdb/cli/agentdb-cli.ts) so it persists through builds.
Workaround
Users can manually patch the distributed JS file at:
node_modules/agentic-flow/dist/agentdb/cli/agentdb-cli.js
Or for global installs, the path in pnpm's content-addressable store.
Reported by: Adam Kovacs
Metadata
Metadata
Assignees
Labels
No labels