chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
# codebase-memory-mcp
|
||||
|
||||
[](https://www.npmjs.com/package/codebase-memory-mcp)
|
||||
[](https://github.com/DeusData/codebase-memory-mcp/releases/latest)
|
||||
[](https://github.com/DeusData/codebase-memory-mcp/blob/main/LICENSE)
|
||||
[](https://github.com/DeusData/codebase-memory-mcp/releases/latest)
|
||||
|
||||
**The fastest and most efficient code intelligence engine for AI coding agents.** Full-indexes an average repository in milliseconds, the Linux kernel (28M LOC, 75K files) in 3 minutes. Answers structural queries in under 1ms. Ships as a single static binary — this package downloads and runs it automatically.
|
||||
|
||||
High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-sitter/) AST analysis across 159 languages — producing a persistent knowledge graph of functions, classes, call chains, HTTP routes, and cross-service links. 14 MCP tools. Zero dependencies. Plug and play across 11 coding agents.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install -g codebase-memory-mcp
|
||||
```
|
||||
|
||||
The binary for your platform is downloaded automatically at install time. Then configure your coding agents:
|
||||
|
||||
```bash
|
||||
codebase-memory-mcp install
|
||||
```
|
||||
|
||||
Restart your agent. Say **"Index this project"** — done.
|
||||
|
||||
## Why codebase-memory-mcp
|
||||
|
||||
- **Extreme indexing speed** — Linux kernel (28M LOC, 75K files) in 3 minutes. RAM-first pipeline with LZ4 compression and in-memory SQLite.
|
||||
- **Plug and play** — single static binary for macOS (arm64/amd64), Linux (arm64/amd64), and Windows (amd64). No Docker, no runtime dependencies, no API keys.
|
||||
- **159 languages** — vendored tree-sitter grammars compiled into the binary. Nothing to install, nothing that breaks.
|
||||
- **120x fewer tokens** — 5 structural queries: ~3,400 tokens vs ~412,000 via file-by-file search.
|
||||
- **11 agents, one command** — `install` auto-detects Claude Code, Codex CLI, Gemini CLI, Zed, OpenCode, Antigravity, Aider, KiloCode, VS Code, OpenClaw, and Kiro.
|
||||
- **14 MCP tools** — search, trace, architecture, impact analysis, Cypher queries, dead code detection, cross-service HTTP linking, ADR management, and more.
|
||||
|
||||
## Supported Platforms
|
||||
|
||||
| OS | Architecture |
|
||||
|---------|-------------|
|
||||
| macOS | arm64, amd64 |
|
||||
| Linux | arm64, amd64 |
|
||||
| Windows | amd64 |
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
codebase-memory-mcp install # configure all detected coding agents
|
||||
codebase-memory-mcp --version
|
||||
codebase-memory-mcp --help
|
||||
codebase-memory-mcp update # update to latest release
|
||||
codebase-memory-mcp uninstall # remove agent configs
|
||||
```
|
||||
|
||||
### CLI Mode
|
||||
|
||||
Every MCP tool is also available directly from the command line:
|
||||
|
||||
```bash
|
||||
codebase-memory-mcp cli index_repository '{"repo_path": "/path/to/repo"}'
|
||||
codebase-memory-mcp cli search_graph '{"name_pattern": ".*Handler.*", "label": "Function"}'
|
||||
codebase-memory-mcp cli trace_call_path '{"function_name": "main", "direction": "both"}'
|
||||
codebase-memory-mcp cli get_architecture '{}'
|
||||
```
|
||||
|
||||
## MCP Tools
|
||||
|
||||
| Category | Tools |
|
||||
|----------|-------|
|
||||
| **Indexing** | `index_repository`, `list_projects`, `delete_project`, `index_status` |
|
||||
| **Querying** | `search_graph`, `trace_call_path`, `detect_changes`, `query_graph` |
|
||||
| **Analysis** | `get_architecture`, `get_graph_schema`, `get_code_snippet`, `search_code` |
|
||||
| **Advanced** | `manage_adr`, `ingest_traces` |
|
||||
|
||||
## Performance
|
||||
|
||||
Benchmarked on Apple M3 Pro:
|
||||
|
||||
| Operation | Time |
|
||||
|-----------|------|
|
||||
| Linux kernel full index (28M LOC, 75K files) | 3 min |
|
||||
| Django full index | ~6s |
|
||||
| Cypher query | <1ms |
|
||||
| Trace call path (depth=5) | <10ms |
|
||||
|
||||
## Full Documentation
|
||||
|
||||
See [github.com/DeusData/codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp) for the full README including all MCP tools, configuration options, graph data model, and language support details.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
// CLI shim: resolves the downloaded binary and replaces the current process with it.
|
||||
// If the binary is missing (e.g. --ignore-scripts), attempts a one-time download.
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { spawnSync } = require('child_process');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
const binName = isWindows ? 'codebase-memory-mcp.exe' : 'codebase-memory-mcp';
|
||||
const binPath = path.join(__dirname, 'bin', binName);
|
||||
|
||||
if (!fs.existsSync(binPath)) {
|
||||
// Binary missing — try running the install script (handles --ignore-scripts case)
|
||||
process.stderr.write('codebase-memory-mcp: binary not found, downloading...\n');
|
||||
const installResult = spawnSync(process.execPath, [path.join(__dirname, 'install.js')], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (installResult.status !== 0 || !fs.existsSync(binPath)) {
|
||||
process.stderr.write(
|
||||
'codebase-memory-mcp: download failed.\n' +
|
||||
'Try reinstalling: npm install -g codebase-memory-mcp\n'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const result = spawnSync(binPath, process.argv.slice(2), {
|
||||
stdio: 'inherit',
|
||||
windowsHide: false,
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
process.stderr.write(`codebase-memory-mcp: ${result.error.message}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(result.status ?? 0);
|
||||
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
// Postinstall script: downloads the platform-appropriate binary from GitHub Releases.
|
||||
// Runs automatically via `postinstall` in package.json.
|
||||
|
||||
const https = require('https');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { execFileSync } = require('child_process');
|
||||
|
||||
const REPO = 'DeusData/codebase-memory-mcp';
|
||||
const VERSION = require('./package.json').version;
|
||||
const BIN_DIR = path.join(__dirname, 'bin');
|
||||
|
||||
function getPlatform() {
|
||||
switch (process.platform) {
|
||||
case 'linux': return 'linux';
|
||||
case 'darwin': return 'darwin';
|
||||
case 'win32': return 'windows';
|
||||
default: throw new Error(`Unsupported platform: ${process.platform}`);
|
||||
}
|
||||
}
|
||||
|
||||
function getArch() {
|
||||
switch (process.arch) {
|
||||
case 'arm64': return 'arm64';
|
||||
case 'x64': return 'amd64';
|
||||
default: throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Security: only follow HTTPS URLs (defense-in-depth).
|
||||
function validateUrl(url) {
|
||||
if (!url.startsWith('https://')) {
|
||||
throw new Error(`Refusing non-HTTPS URL: ${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
function download(url, dest) {
|
||||
validateUrl(url);
|
||||
return new Promise((resolve, reject) => {
|
||||
function follow(u, depth) {
|
||||
if (depth > 5) return reject(new Error('Too many redirects'));
|
||||
validateUrl(u);
|
||||
https.get(u, (res) => {
|
||||
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||
const loc = res.headers.location;
|
||||
if (!loc) return reject(new Error('Redirect with no location'));
|
||||
const next = loc.startsWith('/') ? new URL(loc, u).href : loc;
|
||||
return follow(next, depth + 1);
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
return reject(new Error(`HTTP ${res.statusCode} for ${u}`));
|
||||
}
|
||||
const file = fs.createWriteStream(dest);
|
||||
res.pipe(file);
|
||||
file.on('finish', () => file.close(resolve));
|
||||
file.on('error', reject);
|
||||
}).on('error', reject);
|
||||
}
|
||||
follow(url, 0);
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch checksums.txt and verify the archive hash.
|
||||
async function verifyChecksum(archivePath, archiveName) {
|
||||
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/checksums.txt`;
|
||||
const tmpChecksums = archivePath + '.checksums';
|
||||
try {
|
||||
await download(url, tmpChecksums);
|
||||
const lines = fs.readFileSync(tmpChecksums, 'utf-8').split('\n');
|
||||
const match = lines.find((l) => l.includes(archiveName));
|
||||
if (!match) return; // checksum line not found — non-fatal
|
||||
const expected = match.split(/\s+/)[0];
|
||||
const actual = crypto
|
||||
.createHash('sha256')
|
||||
.update(fs.readFileSync(archivePath))
|
||||
.digest('hex');
|
||||
if (expected !== actual) {
|
||||
throw new Error(
|
||||
`Checksum mismatch for ${archiveName}:\n expected: ${expected}\n actual: ${actual}`,
|
||||
);
|
||||
}
|
||||
process.stdout.write('codebase-memory-mcp: checksum verified.\n');
|
||||
} catch (err) {
|
||||
if (err.message.startsWith('Checksum mismatch')) throw err;
|
||||
// Non-fatal: checksum unavailable (network issue, pre-release, etc.)
|
||||
} finally {
|
||||
try { fs.unlinkSync(tmpChecksums); } catch (_) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const platform = getPlatform();
|
||||
const arch = getArch();
|
||||
const ext = platform === 'windows' ? 'zip' : 'tar.gz';
|
||||
const binName = platform === 'windows' ? 'codebase-memory-mcp.exe' : 'codebase-memory-mcp';
|
||||
const binPath = path.join(BIN_DIR, binName);
|
||||
|
||||
if (fs.existsSync(binPath)) {
|
||||
return; // already installed, nothing to do
|
||||
}
|
||||
|
||||
fs.mkdirSync(BIN_DIR, { recursive: true });
|
||||
|
||||
// Linux ships a fully-static "-portable" build; the standard linux binary
|
||||
// dynamically links glibc 2.38+ and fails on older distros. macOS/Windows
|
||||
// have no such variant. Keep in sync with install.sh / pypi _cli.py / cli.c.
|
||||
const variant = platform === 'linux' ? '-portable' : '';
|
||||
// Opt into the UI build (embedded graph visualization) with CBM_VARIANT=ui.
|
||||
// Default is the standard (headless) build. Mirrors install.sh --ui.
|
||||
const ui = (process.env.CBM_VARIANT || '').toLowerCase() === 'ui' ? 'ui-' : '';
|
||||
const archive = `codebase-memory-mcp-${ui}${platform}-${arch}${variant}.${ext}`;
|
||||
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archive}`;
|
||||
|
||||
const uiLabel = ui ? '(ui) ' : '';
|
||||
process.stdout.write(`codebase-memory-mcp: downloading v${VERSION} ${uiLabel}for ${platform}/${arch}...\n`);
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cbm-install-'));
|
||||
const tmpArchive = path.join(tmpDir, `cbm.${ext}`);
|
||||
|
||||
try {
|
||||
await download(url, tmpArchive);
|
||||
await verifyChecksum(tmpArchive, archive);
|
||||
|
||||
// Extract using execFileSync (array args — no shell injection).
|
||||
if (ext === 'tar.gz') {
|
||||
execFileSync('tar', ['-xzf', tmpArchive, '-C', tmpDir, '--no-same-owner']);
|
||||
} else {
|
||||
execFileSync('powershell', [
|
||||
'-NoProfile', '-Command',
|
||||
`Expand-Archive -Path '${tmpArchive}' -DestinationPath '${tmpDir}' -Force`,
|
||||
]);
|
||||
}
|
||||
|
||||
// Validate extracted path doesn't escape tmpDir (tar-slip defense).
|
||||
const extracted = path.join(tmpDir, binName);
|
||||
const resolvedExtracted = path.resolve(extracted);
|
||||
const resolvedTmpDir = path.resolve(tmpDir);
|
||||
if (!resolvedExtracted.startsWith(resolvedTmpDir + path.sep)) {
|
||||
throw new Error(`Path traversal detected in archive: ${binName}`);
|
||||
}
|
||||
if (!fs.existsSync(extracted)) {
|
||||
throw new Error(`Binary not found after extraction at ${extracted}`);
|
||||
}
|
||||
|
||||
fs.copyFileSync(extracted, binPath);
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
|
||||
process.stdout.write('codebase-memory-mcp: ready.\n');
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
process.stderr.write(`\ncodebase-memory-mcp: install failed — ${err.message}\n`);
|
||||
process.stderr.write(`You can install manually: https://github.com/${REPO}#installation\n`);
|
||||
// Non-fatal: don't block the rest of npm install
|
||||
process.exit(0);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "codebase-memory-mcp",
|
||||
"version": "0.8.1",
|
||||
"description": "Fast code intelligence engine for AI coding agents — single static binary MCP server",
|
||||
"mcpName": "io.github.DeusData/codebase-memory-mcp",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/DeusData/codebase-memory-mcp.git"
|
||||
},
|
||||
"homepage": "https://github.com/DeusData/codebase-memory-mcp",
|
||||
"bugs": {
|
||||
"url": "https://github.com/DeusData/codebase-memory-mcp/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"mcp",
|
||||
"claude",
|
||||
"code-intelligence",
|
||||
"codebase",
|
||||
"memory",
|
||||
"ai",
|
||||
"llm",
|
||||
"tree-sitter"
|
||||
],
|
||||
"bin": {
|
||||
"codebase-memory-mcp": "./bin.js"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node install.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"os": ["linux", "darwin", "win32"],
|
||||
"cpu": ["x64", "arm64"],
|
||||
"files": [
|
||||
"bin.js",
|
||||
"install.js",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user