mindkeg-mcp 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carlo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # Mind Keg MCP
2
+
3
+ A persistent memory MCP server for AI coding agents. Stores atomic learnings — debugging insights, architectural decisions, codebase conventions — so every agent session starts with relevant institutional knowledge.
4
+
5
+ ## Problem
6
+
7
+ AI coding agents (Claude Code, Cursor, Windsurf) lose context between sessions. Hard-won insights are forgotten the moment a conversation ends. Developers repeatedly re-explain the same things; agents repeatedly make the same mistakes.
8
+
9
+ **Mind Keg** solves this with a centralized, persistent brain that any MCP-compatible agent can query and contribute to.
10
+
11
+ ## How It Works
12
+
13
+ Mind Keg implements a **RAG (Retrieval-Augmented Generation)** pattern for AI coding agents:
14
+
15
+ 1. **Retrieval** — Agent searches the brain for relevant learnings using semantic or keyword search
16
+ 2. **Augmentation** — Retrieved learnings are injected into the agent's conversation context
17
+ 3. **Generation** — The agent responds with awareness of past discoveries and decisions
18
+
19
+ Unlike traditional RAG systems that chunk large documents, Mind Keg stores **pre-curated atomic learnings** (max 500 chars each). No chunking strategy needed — each learning IS the retrieval unit. The agent controls both retrieval and storage, creating a feedback loop where knowledge improves over time.
20
+
21
+ ## Features
22
+
23
+ - Store and retrieve atomic learnings (max 500 chars, one insight per entry)
24
+ - Semantic search with three provider options:
25
+ - **FastEmbed** (free, local, ONNX-based — `BAAI/bge-small-en-v1.5`, 384 dims)
26
+ - **OpenAI** (paid, best quality — `text-embedding-3-small`, 1536 dims)
27
+ - **None** (FTS5 keyword fallback — zero external dependencies)
28
+ - Six categories: `architecture`, `conventions`, `debugging`, `gotchas`, `dependencies`, `decisions`
29
+ - Free-form tags and group linking
30
+ - Three scoping levels: repository-specific, workspace-wide, and global learnings
31
+ - Dual transport: stdio (local) + HTTP+SSE (remote)
32
+ - API key authentication with per-repository access control
33
+ - SQLite storage (zero dependencies, zero config)
34
+ - Import/export for backup and migration
35
+
36
+ ## Quick Start
37
+
38
+ ### Install
39
+
40
+ ```bash
41
+ npm install -g mindkeg-mcp
42
+ ```
43
+
44
+ ### Create an API key
45
+
46
+ ```bash
47
+ mindkeg api-key create --name "My Laptop"
48
+ # Displays the key ONCE — save it securely
49
+ # mk_abc123...
50
+ ```
51
+
52
+ ### Connect your AI agent
53
+
54
+ Mind Keg works with any MCP-compatible AI coding agent. Choose your setup:
55
+
56
+ #### Claude Code (stdio)
57
+
58
+ Add to `~/.claude.json` or your project's MCP settings:
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "mindkeg": {
64
+ "command": "mindkeg",
65
+ "args": ["serve", "--stdio"],
66
+ "env": {
67
+ "MINDKEG_API_KEY": "mk_your_key_here"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ #### Cursor
75
+
76
+ Add to your Cursor MCP settings (`.cursor/mcp.json` or global settings):
77
+
78
+ ```json
79
+ {
80
+ "mcpServers": {
81
+ "mindkeg": {
82
+ "command": "mindkeg",
83
+ "args": ["serve", "--stdio"],
84
+ "env": {
85
+ "MINDKEG_API_KEY": "mk_your_key_here"
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ #### Windsurf
93
+
94
+ Add to your Windsurf MCP configuration (`~/.codeium/windsurf/mcp_config.json`):
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "mindkeg": {
100
+ "command": "mindkeg",
101
+ "args": ["serve", "--stdio"],
102
+ "env": {
103
+ "MINDKEG_API_KEY": "mk_your_key_here"
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ #### HTTP mode (any MCP client)
111
+
112
+ For agents that connect via HTTP instead of stdio:
113
+
114
+ ```bash
115
+ MINDKEG_API_KEY=mk_your_key mindkeg serve --http
116
+ # Listening on http://127.0.0.1:52100/mcp
117
+ ```
118
+
119
+ ```json
120
+ {
121
+ "mcpServers": {
122
+ "mindkeg": {
123
+ "type": "http",
124
+ "url": "http://127.0.0.1:52100/mcp",
125
+ "headers": {
126
+ "Authorization": "Bearer mk_your_key_here"
127
+ }
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ #### Other MCP-compatible agents
134
+
135
+ Mind Keg works with any agent that supports the [Model Context Protocol](https://modelcontextprotocol.io) — including Codex CLI, Gemini CLI, GitHub Copilot, and more. Use the stdio config above adapted to your agent's MCP settings format.
136
+
137
+ ### Add Mind Keg instructions to your repository
138
+
139
+ Copy `templates/AGENTS.md` to the root of any repository where you want agents to use Mind Keg.
140
+
141
+ `AGENTS.md` is the industry standard supported by 20+ AI tools (Cursor, Windsurf, Codex, Gemini CLI, GitHub Copilot, etc.).
142
+
143
+ > **Claude Code only**: Claude Code doesn't auto-load `AGENTS.md` natively. Add `@AGENTS.md` to your `CLAUDE.md` to bridge it.
144
+
145
+ ## MCP Tools
146
+
147
+ | Tool | Description |
148
+ |----------------------|------------------------------------------------------|
149
+ | `store_learning` | Store a new atomic learning (repo, workspace, or global scope) |
150
+ | `search_learnings` | Semantic/keyword search for relevant learnings |
151
+ | `update_learning` | Update content, category, or tags |
152
+ | `deprecate_learning` | Mark a learning as deprecated |
153
+ | `flag_stale` | Flag a learning as potentially outdated |
154
+ | `delete_learning` | Permanently delete a learning |
155
+ | `list_repositories` | List all repositories with learning counts |
156
+ | `list_workspaces` | List all workspaces with learning counts |
157
+
158
+ ## CLI Commands
159
+
160
+ ```bash
161
+ # Start in stdio mode (for local agent connections)
162
+ mindkeg serve --stdio
163
+
164
+ # Start in HTTP mode (for remote connections)
165
+ mindkeg serve --http
166
+
167
+ # API key management
168
+ mindkeg api-key create --name "My Key"
169
+ mindkeg api-key create --name "Team Key" --repositories /repo/a /repo/b
170
+ mindkeg api-key list
171
+ mindkeg api-key revoke <prefix>
172
+
173
+ # Database
174
+ mindkeg migrate
175
+
176
+ # Backup and restore
177
+ mindkeg export --output backup.json
178
+ mindkeg import backup.json --regenerate-embeddings
179
+ ```
180
+
181
+ ## Configuration
182
+
183
+ | Environment Variable | Default | Description |
184
+ |-------------------------------|------------------------------|-------------------------------------|
185
+ | `MINDKEG_SQLITE_PATH` | `~/.mindkeg/brain.db` | SQLite database file |
186
+ | `MINDKEG_EMBEDDING_PROVIDER` | `fastembed` | `fastembed`, `openai`, or `none` |
187
+ | `OPENAI_API_KEY` | (none) | OpenAI API key (when provider=openai)|
188
+ | `MINDKEG_HOST` | `127.0.0.1` | HTTP server bind address |
189
+ | `MINDKEG_PORT` | `52100` | HTTP server port |
190
+ | `MINDKEG_LOG_LEVEL` | `info` | `debug`, `info`, `warn`, `error` |
191
+ | `MINDKEG_API_KEY` | (none) | API key for stdio transport |
192
+
193
+ ### Embedding providers
194
+
195
+ **FastEmbed (default, free, local)**
196
+
197
+ Semantic search works out of the box using FastEmbed — no API key needed, no network calls. Uses `BAAI/bge-small-en-v1.5` (384 dimensions) via local ONNX Runtime. Model files are downloaded once on first use (~50MB).
198
+
199
+ **OpenAI (paid, best quality)**
200
+
201
+ ```bash
202
+ export MINDKEG_EMBEDDING_PROVIDER=openai
203
+ export OPENAI_API_KEY=sk-...
204
+ ```
205
+
206
+ Uses `text-embedding-3-small` (1536 dimensions). Best semantic search quality but requires an API key and incurs per-request costs.
207
+
208
+ **None (keyword search only)**
209
+
210
+ ```bash
211
+ export MINDKEG_EMBEDDING_PROVIDER=none
212
+ ```
213
+
214
+ Disables semantic search and falls back to SQLite FTS5 full-text search — all other features work identically.
215
+
216
+ ## Data Model
217
+
218
+ Each learning contains:
219
+
220
+ | Field | Type | Notes |
221
+ |--------------|-------------------|------------------------------------------------|
222
+ | `id` | UUID | Auto-generated |
223
+ | `content` | string (max 500) | The atomic learning text |
224
+ | `category` | enum | One of 6 categories |
225
+ | `tags` | string[] | Free-form labels |
226
+ | `repository` | string or null | Repo path; null = workspace or global |
227
+ | `workspace` | string or null | Workspace path; null = repo-specific or global |
228
+ | `group_id` | UUID or null | Link related learnings |
229
+ | `source` | string | Who created this (e.g., "claude-code") |
230
+ | `status` | enum | `active` or `deprecated` |
231
+ | `stale_flag` | boolean | Agent-flagged as potentially outdated |
232
+ | `created_at` | ISO 8601 | Auto-set on creation |
233
+ | `updated_at` | ISO 8601 | Auto-updated on modification |
234
+
235
+ ## Scoping
236
+
237
+ Learnings have three scope levels:
238
+
239
+ | Scope | `repository` | `workspace` | Visible where |
240
+ |-------|-------------|-------------|---------------|
241
+ | **Repo-specific** | set | null | Only that repo |
242
+ | **Workspace-wide** | null | set | All repos in the same parent folder |
243
+ | **Global** | null | null | Everywhere |
244
+
245
+ **Workspaces are auto-detected** from the parent folder of a repository path. For example, if your repos are organized as:
246
+
247
+ ```
248
+ repositories/
249
+ personal/ ← workspace
250
+ app-a/
251
+ app-b/
252
+ work/ ← workspace
253
+ project-x/
254
+ ```
255
+
256
+ A workspace learning stored under `repositories/personal/` is shared across `app-a` and `app-b` but not `project-x`.
257
+
258
+ When searching, results include all three scopes: repo-specific + workspace + global. Each result has a `scope` field indicating its level.
259
+
260
+ ## What Makes a Good Learning?
261
+
262
+ - **Atomic**: One insight per entry. Max 500 characters.
263
+ - **Actionable**: What to DO or AVOID, not just what exists.
264
+ - **Specific**: Mentions the concrete context (library, pattern, file).
265
+
266
+ **Good**: "Always wrap Prisma queries in try/catch — it throws on constraint violations, not returns null."
267
+
268
+ **Bad**: "Be careful with the database." (too vague)
269
+
270
+ ## Development
271
+
272
+ ```bash
273
+ # Clone and install
274
+ git clone ...
275
+ npm install
276
+
277
+ # Run tests
278
+ npm test
279
+
280
+ # Build
281
+ npm run build
282
+
283
+ # Development mode (rebuilds on change)
284
+ npm run dev
285
+
286
+ # Type check
287
+ npm run typecheck
288
+ ```
289
+
290
+ ### Running without external APIs
291
+
292
+ Mind Keg works fully offline by default. FastEmbed provides free, local semantic search using ONNX Runtime — no API keys or network calls required. All CRUD operations and search work out of the box.
293
+
294
+ ## Architecture
295
+
296
+ ```
297
+ CLI (Commander.js)
298
+ └── serve / api-key / migrate / export / import
299
+
300
+ src/
301
+ index.ts Entry point, stdio + HTTP transports
302
+ server.ts MCP server + tool registration
303
+ config.ts Config loading (env vars → defaults)
304
+ auth/ API key generation + validation middleware
305
+ tools/ One file per MCP tool (8 tools)
306
+ services/ LearningService + EmbeddingService
307
+ storage/ StorageAdapter interface + SQLite impl
308
+ models/ Zod schemas + TypeScript types
309
+ utils/ Logger (pino → stderr) + error classes
310
+
311
+ templates/
312
+ AGENTS.md Template for instructing agents to use Mind Keg
313
+ ```
314
+
315
+ See `CLAUDE.md` for detailed development conventions.
316
+
317
+ ## License
318
+
319
+ MIT
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node