@brainbank/mcp 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -42
- package/dist/mcp-server.js +301 -315
- package/dist/mcp-server.js.map +1 -1
- package/package.json +15 -3
- package/src/mcp-server.ts +265 -0
- package/src/workspace-factory.ts +66 -0
- package/src/workspace-pool.ts +224 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @brainbank/mcp
|
|
2
2
|
|
|
3
|
-
[MCP](https://modelcontextprotocol.io/) server for [BrainBank](https://github.com/pinecall/brainbank) — exposes code
|
|
3
|
+
[MCP](https://modelcontextprotocol.io/) server for [BrainBank](https://github.com/pinecall/brainbank) — exposes code context as a single tool for AI agents via stdio transport.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
npm install @brainbank/mcp
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Plugin packages are optional peer dependencies — install whichever you need:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @brainbank/code @brainbank/git @brainbank/docs
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
## Quick Start
|
|
12
18
|
|
|
13
19
|
### Antigravity
|
|
@@ -19,10 +25,7 @@ Add to `~/.gemini/antigravity/mcp_config.json`:
|
|
|
19
25
|
"mcpServers": {
|
|
20
26
|
"brainbank": {
|
|
21
27
|
"command": "npx",
|
|
22
|
-
"args": ["-y", "@brainbank/mcp"]
|
|
23
|
-
"env": {
|
|
24
|
-
"BRAINBANK_EMBEDDING": "openai"
|
|
25
|
-
}
|
|
28
|
+
"args": ["-y", "@brainbank/mcp"]
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
}
|
|
@@ -37,11 +40,7 @@ Add to Claude Desktop settings → Developer → MCP Servers:
|
|
|
37
40
|
"mcpServers": {
|
|
38
41
|
"brainbank": {
|
|
39
42
|
"command": "npx",
|
|
40
|
-
"args": ["-y", "@brainbank/mcp"]
|
|
41
|
-
"env": {
|
|
42
|
-
"BRAINBANK_EMBEDDING": "openai",
|
|
43
|
-
"OPENAI_API_KEY": "sk-..."
|
|
44
|
-
}
|
|
43
|
+
"args": ["-y", "@brainbank/mcp"]
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -56,10 +55,7 @@ Add to `.cursor/mcp.json` in your project:
|
|
|
56
55
|
"mcpServers": {
|
|
57
56
|
"brainbank": {
|
|
58
57
|
"command": "npx",
|
|
59
|
-
"args": ["-y", "@brainbank/mcp"]
|
|
60
|
-
"env": {
|
|
61
|
-
"BRAINBANK_EMBEDDING": "openai"
|
|
62
|
-
}
|
|
58
|
+
"args": ["-y", "@brainbank/mcp"]
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
}
|
|
@@ -71,41 +67,90 @@ Add to `.cursor/mcp.json` in your project:
|
|
|
71
67
|
brainbank serve
|
|
72
68
|
```
|
|
73
69
|
|
|
74
|
-
##
|
|
70
|
+
## Zero-Config
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|----------|-------------|---------|
|
|
78
|
-
| `BRAINBANK_REPO` | Default repo path (fallback if `repo` param not provided) | — |
|
|
79
|
-
| `BRAINBANK_EMBEDDING` | Embedding provider: `local`, `openai`, `perplexity`, `perplexity-context` | `local` |
|
|
80
|
-
| `OPENAI_API_KEY` | Required when using `openai` embeddings | — |
|
|
81
|
-
| `PERPLEXITY_API_KEY` | Required when using `perplexity` or `perplexity-context` embeddings | — |
|
|
72
|
+
The MCP server auto-detects everything:
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
- **Repo path** — from `repo` tool param > `BRAINBANK_REPO` env > `findRepoRoot(cwd)`
|
|
75
|
+
- **Embedding provider** — from `.brainbank/config.json` > `BRAINBANK_EMBEDDING` env > `provider_key` stored in DB > falls back to local
|
|
76
|
+
- **Plugins** — reads `plugins` array from `config.json` (default: `['code']`). Loaded dynamically by the core factory — no hardcoded imports
|
|
84
77
|
|
|
85
|
-
|
|
78
|
+
Index your repo once with the CLI:
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
| `brainbank_context` | Formatted context block for a task (code + git + co-edits) |
|
|
91
|
-
| `brainbank_index` | Trigger incremental code/git/docs indexing |
|
|
92
|
-
| `brainbank_stats` | Index statistics (files, commits, chunks, collections) |
|
|
93
|
-
| `brainbank_history` | Git history for a specific file |
|
|
94
|
-
| `brainbank_collection` | KV collection ops — `action: add`, `search`, or `trim` |
|
|
80
|
+
```bash
|
|
81
|
+
brainbank index . --yes
|
|
82
|
+
```
|
|
95
83
|
|
|
96
|
-
|
|
84
|
+
After that, the MCP server auto-resolves the correct provider — no env vars needed.
|
|
85
|
+
|
|
86
|
+
## Tools (2)
|
|
87
|
+
|
|
88
|
+
### `brainbank_context`
|
|
89
|
+
|
|
90
|
+
**Primary tool.** Returns a Workflow Trace:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
brainbank_context({
|
|
94
|
+
task: string, // what you're trying to understand or implement
|
|
95
|
+
affectedFiles?: string[], // files you plan to modify (improves co-edit suggestions)
|
|
96
|
+
codeResults?: number, // max code results (default: 6)
|
|
97
|
+
gitResults?: number, // max git commit results (default: 5)
|
|
98
|
+
repo?: string, // repository path (default: auto-detect)
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Returns a **Workflow Trace** — a single flat `## Code Context` section with:
|
|
103
|
+
- Search hits with `% match` scores
|
|
104
|
+
- Full call tree (3 levels deep) with `called by` annotations
|
|
105
|
+
- Part adjacency boost (multi-part functions shown complete)
|
|
106
|
+
- Trivial wrapper collapse (one-liners for delegation)
|
|
107
|
+
- All source code included — no trimming, no truncation
|
|
97
108
|
|
|
98
|
-
|
|
109
|
+
If the project is **not indexed**, the tool returns an error with the CLI command to run.
|
|
110
|
+
|
|
111
|
+
### `brainbank_index`
|
|
112
|
+
|
|
113
|
+
Re-index code/git/docs. Requires `.brainbank/config.json`. Incremental — only changed files are processed.
|
|
99
114
|
|
|
100
115
|
```typescript
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
brainbank_index({
|
|
117
|
+
forceReindex?: boolean, // force full re-index (default: false)
|
|
118
|
+
repo?: string, // repository path
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Multi-Workspace
|
|
103
123
|
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
The MCP server manages a `WorkspacePool` of BrainBank instances — one per unique `repo` path. The pool uses memory-pressure eviction (configurable max memory) and TTL eviction (configurable idle timeout):
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
brainbank_context({ task: "login form", repo: "/project-a" })
|
|
128
|
+
brainbank_context({ task: "API routes", repo: "/project-b" })
|
|
106
129
|
```
|
|
107
130
|
|
|
108
|
-
Instances are cached in memory after first initialization (~480ms)
|
|
131
|
+
Instances are cached in memory after first initialization (~480ms). Active operations are tracked — the pool never evicts a workspace with in-flight queries.
|
|
132
|
+
|
|
133
|
+
## Environment Variables
|
|
134
|
+
|
|
135
|
+
All optional — the server works without any env vars.
|
|
136
|
+
|
|
137
|
+
| Variable | Description | Default |
|
|
138
|
+
|----------|-------------|---------|
|
|
139
|
+
| `BRAINBANK_REPO` | Fallback repo path | auto-detect from cwd |
|
|
140
|
+
| `BRAINBANK_EMBEDDING` | Embedding provider key | from `config.json` or DB |
|
|
141
|
+
| `BRAINBANK_MAX_MEMORY_MB` | Maximum total pool memory in MB | `2048` |
|
|
142
|
+
| `BRAINBANK_TTL_MINUTES` | Idle workspace eviction timeout in minutes | `30` |
|
|
143
|
+
| `OPENAI_API_KEY` | Required when embedding provider is `openai` | — |
|
|
144
|
+
| `PERPLEXITY_API_KEY` | Required when embedding provider is `perplexity` / `perplexity-context` | — |
|
|
145
|
+
|
|
146
|
+
## Architecture
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
@brainbank/mcp
|
|
150
|
+
├── mcp-server.ts ← MCP stdio server (1 tool: brainbank_context)
|
|
151
|
+
├── workspace-pool.ts ← Memory-pressure + TTL eviction, active-op tracking
|
|
152
|
+
└── workspace-factory.ts ← Delegates to core createBrain() — no plugin hardcoding
|
|
153
|
+
```
|
|
109
154
|
|
|
110
155
|
## How it works
|
|
111
156
|
|
|
@@ -113,10 +158,11 @@ Instances are cached in memory after first initialization (~480ms), so subsequen
|
|
|
113
158
|
AI Agent ←→ stdio ←→ @brainbank/mcp ←→ BrainBank core ←→ SQLite
|
|
114
159
|
```
|
|
115
160
|
|
|
116
|
-
1. Agent sends
|
|
117
|
-
2.
|
|
118
|
-
3. BrainBank
|
|
119
|
-
4.
|
|
161
|
+
1. Agent sends `brainbank_context({ task: "..." })`
|
|
162
|
+
2. `WorkspacePool` resolves `repo` → gets/creates a BrainBank instance
|
|
163
|
+
3. BrainBank calls `ensureFresh()` → hot-reloads stale HNSW if needed
|
|
164
|
+
4. BrainBank executes search + call tree + formatting
|
|
165
|
+
5. Workflow Trace returned as markdown to the agent
|
|
120
166
|
|
|
121
167
|
## License
|
|
122
168
|
|