@iwo-szapar/data-mcp 0.3.3 → 0.5.0

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.
@@ -1,41 +1,38 @@
1
1
  /**
2
- * PocketBase Migration 008: knowledge_links collection
2
+ * PocketBase migration: knowledge_links collection
3
3
  *
4
- * Typed relationships between MemoryOS entities.
5
- * PocketBase does not support pgvector — link suggestions use keyword-based
6
- * text search fallback.
4
+ * Creates the knowledge_links collection for typed relationships
5
+ * between MemoryOS entities.
7
6
  *
8
- * PocketBase v0.23+ field format + native migrate() form
9
- * (was previously module.exports goja runtime panics on that).
7
+ * Note: PocketBase does not support pgvector.
8
+ * Link suggestions use keyword-based text search fallback.
10
9
  */
11
-
12
- /// <reference path="../pb_data/types.d.ts" />
13
-
14
- migrate((app) => {
15
- const links = new Collection({
16
- name: 'knowledge_links',
17
- type: 'base',
18
- fields: [
19
- { name: 'owner_id', type: 'text', max: 100 },
20
- { name: 'source_type', type: 'text', required: true, max: 50 },
21
- { name: 'source_id', type: 'text', required: true, max: 36 },
22
- { name: 'target_type', type: 'text', required: true, max: 50 },
23
- { name: 'target_id', type: 'text', required: true, max: 36 },
24
- { name: 'relation_type', type: 'text', required: true, max: 50 },
25
- { name: 'confidence', type: 'number', min: 0, max: 1 },
26
- { name: 'notes', type: 'text', max: 500 },
27
- { name: 'auto_suggested', type: 'bool' },
28
- { name: 'created', type: 'autodate', onCreate: true },
29
- { name: 'updated', type: 'autodate', onCreate: true, onUpdate: true },
30
- ],
31
- indexes: [
32
- 'CREATE INDEX idx_kl_source ON knowledge_links (owner_id, source_type, source_id)',
33
- 'CREATE INDEX idx_kl_target ON knowledge_links (owner_id, target_type, target_id)',
34
- 'CREATE UNIQUE INDEX idx_kl_unique ON knowledge_links (owner_id, source_type, source_id, target_type, target_id, relation_type)',
35
- ],
36
- });
37
- app.save(links);
38
- }, (app) => {
39
- const links = app.findCollectionByNameOrId('knowledge_links');
40
- if (links) app.delete(links);
41
- });
10
+ module.exports = {
11
+ async up(db) {
12
+ const collection = new Collection({
13
+ name: 'knowledge_links',
14
+ type: 'base',
15
+ schema: [
16
+ { name: 'owner_id', type: 'text', required: true, options: { maxSize: 100 } },
17
+ { name: 'source_type', type: 'text', required: true, options: { maxSize: 50 } },
18
+ { name: 'source_id', type: 'text', required: true, options: { maxSize: 36 } },
19
+ { name: 'target_type', type: 'text', required: true, options: { maxSize: 50 } },
20
+ { name: 'target_id', type: 'text', required: true, options: { maxSize: 36 } },
21
+ { name: 'relation_type', type: 'text', required: true, options: { maxSize: 50 } },
22
+ { name: 'confidence', type: 'number', options: { min: 0, max: 1 } },
23
+ { name: 'notes', type: 'text', options: { maxSize: 500 } },
24
+ { name: 'auto_suggested', type: 'bool' },
25
+ ],
26
+ indexes: [
27
+ 'CREATE INDEX idx_kl_source ON knowledge_links (owner_id, source_type, source_id)',
28
+ 'CREATE INDEX idx_kl_target ON knowledge_links (owner_id, target_type, target_id)',
29
+ 'CREATE UNIQUE INDEX idx_kl_unique ON knowledge_links (owner_id, source_type, source_id, target_type, target_id, relation_type)',
30
+ ],
31
+ });
32
+ return db.save(collection);
33
+ },
34
+ async down(db) {
35
+ const collection = await db.findCollectionByNameOrId('knowledge_links');
36
+ return db.delete(collection);
37
+ },
38
+ };
@@ -8,14 +8,12 @@
8
8
  -- 5. Add decisions-specific columns: rationale, outcome_rating, session_id
9
9
  -- 6. Make decisions.options_considered nullable (production data shows this)
10
10
  -- 7. Make goals.timeframe nullable (not always known at creation time)
11
- --
12
- -- Each `text[] -> jsonb` conversion must DROP DEFAULT first, change TYPE, then
13
- -- SET a jsonb DEFAULT. Postgres cannot auto-cast the text[] default '{}' to jsonb.
14
11
 
15
12
  -- === KNOWLEDGE ===
16
- ALTER TABLE knowledge ALTER COLUMN tags DROP DEFAULT;
13
+ -- Convert tags from text[] to jsonb
17
14
  ALTER TABLE knowledge ALTER COLUMN tags TYPE jsonb USING to_jsonb(tags);
18
15
  ALTER TABLE knowledge ALTER COLUMN tags SET DEFAULT '[]'::jsonb;
16
+ -- Add missing columns
19
17
  ALTER TABLE knowledge ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
20
18
  ALTER TABLE knowledge ADD COLUMN IF NOT EXISTS metadata jsonb DEFAULT '{}'::jsonb;
21
19
  ALTER TABLE knowledge ADD COLUMN IF NOT EXISTS source_file text;
@@ -23,13 +21,14 @@ ALTER TABLE knowledge ADD COLUMN IF NOT EXISTS decay_score numeric;
23
21
  ALTER TABLE knowledge ADD COLUMN IF NOT EXISTS triggers jsonb;
24
22
 
25
23
  -- === DECISIONS ===
26
- ALTER TABLE decisions ALTER COLUMN options_considered DROP DEFAULT;
24
+ -- Convert options_considered from text[] to jsonb
27
25
  ALTER TABLE decisions ALTER COLUMN options_considered TYPE jsonb USING to_jsonb(options_considered);
28
26
  ALTER TABLE decisions ALTER COLUMN options_considered DROP NOT NULL;
29
27
  ALTER TABLE decisions ALTER COLUMN options_considered SET DEFAULT '[]'::jsonb;
30
- ALTER TABLE decisions ALTER COLUMN tags DROP DEFAULT;
28
+ -- Convert tags from text[] to jsonb
31
29
  ALTER TABLE decisions ALTER COLUMN tags TYPE jsonb USING to_jsonb(tags);
32
30
  ALTER TABLE decisions ALTER COLUMN tags SET DEFAULT '[]'::jsonb;
31
+ -- Add missing columns
33
32
  ALTER TABLE decisions ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
34
33
  ALTER TABLE decisions ADD COLUMN IF NOT EXISTS metadata jsonb DEFAULT '{}'::jsonb;
35
34
  ALTER TABLE decisions ADD COLUMN IF NOT EXISTS rationale text;
@@ -37,33 +36,37 @@ ALTER TABLE decisions ADD COLUMN IF NOT EXISTS outcome_rating text;
37
36
  ALTER TABLE decisions ADD COLUMN IF NOT EXISTS session_id uuid;
38
37
 
39
38
  -- === SESSIONS ===
40
- ALTER TABLE sessions ALTER COLUMN skills_used DROP DEFAULT;
39
+ -- Convert skills_used, files_changed from text[] to jsonb
41
40
  ALTER TABLE sessions ALTER COLUMN skills_used TYPE jsonb USING to_jsonb(skills_used);
42
41
  ALTER TABLE sessions ALTER COLUMN skills_used SET DEFAULT '[]'::jsonb;
43
- ALTER TABLE sessions ALTER COLUMN files_changed DROP DEFAULT;
44
42
  ALTER TABLE sessions ALTER COLUMN files_changed TYPE jsonb USING to_jsonb(files_changed);
45
43
  ALTER TABLE sessions ALTER COLUMN files_changed SET DEFAULT '[]'::jsonb;
44
+ -- Add missing columns
46
45
  ALTER TABLE sessions ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
47
46
 
48
47
  -- === GOALS ===
49
- ALTER TABLE goals ALTER COLUMN tags DROP DEFAULT;
48
+ -- Convert tags from text[] to jsonb
50
49
  ALTER TABLE goals ALTER COLUMN tags TYPE jsonb USING to_jsonb(tags);
51
50
  ALTER TABLE goals ALTER COLUMN tags SET DEFAULT '[]'::jsonb;
51
+ -- Make timeframe nullable (not always known)
52
52
  ALTER TABLE goals ALTER COLUMN timeframe DROP NOT NULL;
53
+ -- Add missing columns
53
54
  ALTER TABLE goals ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
54
55
  ALTER TABLE goals ADD COLUMN IF NOT EXISTS metadata jsonb DEFAULT '{}'::jsonb;
55
56
 
56
57
  -- === TASKS ===
57
- ALTER TABLE tasks ALTER COLUMN tags DROP DEFAULT;
58
+ -- Convert tags from text[] to jsonb
58
59
  ALTER TABLE tasks ALTER COLUMN tags TYPE jsonb USING to_jsonb(tags);
59
60
  ALTER TABLE tasks ALTER COLUMN tags SET DEFAULT '[]'::jsonb;
61
+ -- Add missing columns
60
62
  ALTER TABLE tasks ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
61
63
  ALTER TABLE tasks ADD COLUMN IF NOT EXISTS metadata jsonb DEFAULT '{}'::jsonb;
62
64
 
63
65
  -- === CONTACTS ===
64
- ALTER TABLE contacts ALTER COLUMN tags DROP DEFAULT;
66
+ -- Convert tags from text[] to jsonb
65
67
  ALTER TABLE contacts ALTER COLUMN tags TYPE jsonb USING to_jsonb(tags);
66
68
  ALTER TABLE contacts ALTER COLUMN tags SET DEFAULT '[]'::jsonb;
69
+ -- Add missing columns
67
70
  ALTER TABLE contacts ADD COLUMN IF NOT EXISTS owner_id text NOT NULL DEFAULT 'default';
68
71
  ALTER TABLE contacts ADD COLUMN IF NOT EXISTS metadata jsonb DEFAULT '{}'::jsonb;
69
72
  ALTER TABLE contacts ADD COLUMN IF NOT EXISTS last_interaction_at timestamptz;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iwo-szapar/data-mcp",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "Unified data MCP server for Second Brain — PocketBase and Supabase adapters. 40 tools: knowledge, sessions, goals, tasks, contacts, CRM, blog, email, content calendar.",
5
5
  "author": "Iwo Szapar <iwo.szapar@gmail.com> (https://iwoszapar.com)",
6
6
  "homepage": "https://iwoszapar.com/second-brain-ai",
package/README.md DELETED
@@ -1,286 +0,0 @@
1
- # @iwo-szapar/data-mcp
2
-
3
- Unified data MCP server for [Second Brain](https://iwoszapar.com/second-brain-ai). One MCP, two backends: PocketBase (local, free) or Supabase (cloud, multi-device).
4
-
5
- 40 tools across knowledge, sessions, goals, tasks, contacts, CRM prospects, blog, email queue, and content calendar. Used in production by Second Brain v2 customers.
6
-
7
- ---
8
-
9
- ## Install
10
-
11
- ```bash
12
- npm install -g @iwo-szapar/data-mcp
13
- # or run on demand
14
- npx @iwo-szapar/data-mcp
15
- ```
16
-
17
- Requires Node.js `>=20`.
18
-
19
- ---
20
-
21
- ## Quick start — PocketBase (local)
22
-
23
- PocketBase runs on your laptop. Good for single-device workflows. Stops when you close the terminal.
24
-
25
- 1. **Install PocketBase** ([pocketbase.io](https://pocketbase.io)) and start it:
26
-
27
- ```bash
28
- ./pocketbase serve
29
- # Admin UI: http://127.0.0.1:8090/_/
30
- ```
31
-
32
- 2. **Create an admin account** via the Admin UI on first run.
33
-
34
- 3. **Apply the schema migrations** (required — the MCP does NOT apply them automatically):
35
-
36
- Copy the files in `migrations/pocketbase/` (shipped with this package) into your PocketBase instance's `pb_migrations/` directory, then run:
37
-
38
- ```bash
39
- ./pocketbase migrate up
40
- ```
41
-
42
- This creates all 14 collections (`knowledge`, `decisions`, `sessions`, `goals`, `tasks`, `contacts`, `entity_aliases`, `settings`, `prospects`, `blog_posts`, `email_queue`, `content_calendar`, `newsletter_subscribers`, `affiliates`).
43
-
44
- 4. **Configure your MCP client** (Claude Code, Claude Desktop, Cursor, etc.):
45
-
46
- ```json
47
- {
48
- "mcpServers": {
49
- "data-mcp": {
50
- "command": "npx",
51
- "args": ["-y", "@iwo-szapar/data-mcp"],
52
- "env": {
53
- "SB_BACKEND": "pocketbase",
54
- "SB_POCKETBASE_URL": "http://127.0.0.1:8090",
55
- "SB_POCKETBASE_ADMIN_EMAIL": "you@example.com",
56
- "SB_POCKETBASE_ADMIN_PASSWORD": "your-admin-password"
57
- }
58
- }
59
- }
60
- }
61
- ```
62
-
63
- 5. **Verify**: in your MCP client, call the `setup_status` tool. It reports which collections exist and flags any missing ones.
64
-
65
- ---
66
-
67
- ## Quick start — Supabase (cloud, multi-device)
68
-
69
- Supabase is a hosted Postgres. Runs 24/7, reachable from any device. Good for multi-device setups and phone-friendly workflows.
70
-
71
- 1. **Create a Supabase project** at [supabase.com](https://supabase.com). Note the Project URL and `service_role` key (Settings → API).
72
-
73
- 2. **Apply the SQL migrations** via the SQL editor or the Supabase CLI:
74
-
75
- ```bash
76
- # Using the Supabase CLI
77
- for f in migrations/supabase/*.sql; do
78
- psql "$SUPABASE_DB_URL" -f "$f"
79
- done
80
- ```
81
-
82
- Apply them in order `001` through `010`. The MCP does NOT apply them automatically.
83
-
84
- 3. **Configure your MCP client**:
85
-
86
- ```json
87
- {
88
- "mcpServers": {
89
- "data-mcp": {
90
- "command": "npx",
91
- "args": ["-y", "@iwo-szapar/data-mcp"],
92
- "env": {
93
- "SB_BACKEND": "supabase",
94
- "SB_SUPABASE_URL": "https://YOUR_PROJECT.supabase.co",
95
- "SB_SUPABASE_KEY": "your-service-role-key"
96
- }
97
- }
98
- }
99
- }
100
- ```
101
-
102
- Use the `service_role` key, not `anon`. The MCP needs full access.
103
-
104
- 4. **Verify** with `setup_status`.
105
-
106
- ---
107
-
108
- ## Environment variables
109
-
110
- | Variable | Required | Applies to | Description |
111
- |---|---|---|---|
112
- | `SB_BACKEND` | yes | both | `pocketbase` or `supabase` |
113
- | `SB_POCKETBASE_URL` | yes (PB) | pocketbase | e.g. `http://127.0.0.1:8090` |
114
- | `SB_POCKETBASE_ADMIN_EMAIL` | yes (PB) | pocketbase | PocketBase admin email |
115
- | `SB_POCKETBASE_ADMIN_PASSWORD` | yes (PB) | pocketbase | PocketBase admin password |
116
- | `SB_SUPABASE_URL` | yes (SB) | supabase | Project URL |
117
- | `SB_SUPABASE_KEY` | yes (SB) | supabase | `service_role` key |
118
- | `SB_SCHEMA_MAP` | no | both | JSON object mapping logical names to real table names (e.g. `{"prospects":"my_leads"}`) |
119
- | `SB_RESEND_API_KEY` | no | both | Resend key for email tooling (optional) |
120
-
121
- Missing any required var on startup → the server exits with `Missing required environment variable: SB_XXX`.
122
-
123
- ---
124
-
125
- ## Tool reference (40 tools)
126
-
127
- All tools return JSON. Every tool uses *graceful degradation*: if the required table doesn't exist, the tool returns a clear error asking you to apply migrations instead of crashing.
128
-
129
- ### Knowledge (8)
130
-
131
- | Tool | Purpose |
132
- |---|---|
133
- | `knowledge_store` | Store a fact / pattern / insight / lesson / reference. Dedup by `(type, title)`. |
134
- | `knowledge_recall` | Search knowledge by query, tags, or type. |
135
- | `knowledge_learn` | Shortcut for storing a `lesson`. |
136
- | `knowledge_decide` | Record a decision with context, options, chosen option, and rationale (writes to `decisions`). |
137
- | `knowledge_validate` | Mark an item as freshly validated (resets `last_validated_at`). |
138
- | `knowledge_update` | Update title / content / tags on an existing item. |
139
- | `knowledge_delete` | Delete a knowledge item by ID. |
140
- | `knowledge_list` | List or filter knowledge items. |
141
-
142
- ### Sessions (2)
143
-
144
- | Tool | Purpose |
145
- |---|---|
146
- | `session_log` | Log a completed work session with skills used, files changed, decisions made. |
147
- | `session_list` | List recent sessions. |
148
-
149
- ### Goals (3)
150
-
151
- | Tool | Purpose |
152
- |---|---|
153
- | `goal_create` / `goal_update` / `goal_list` | Track goals with key results. |
154
-
155
- ### Tasks (3)
156
-
157
- | Tool | Purpose |
158
- |---|---|
159
- | `task_create` / `task_update` / `task_list` | Task management with status and priority. |
160
-
161
- ### Contacts (4)
162
-
163
- | Tool | Purpose |
164
- |---|---|
165
- | `contact_create` / `contact_update` / `contact_list` / `contact_search` | Contact records with relationship type and tags. |
166
-
167
- ### Brain health (2)
168
-
169
- | Tool | Purpose |
170
- |---|---|
171
- | `brain_stats` | Aggregate counts across collections and knowledge-type distribution. |
172
- | `brain_decay` | Find stale knowledge items (not validated recently). |
173
-
174
- ### Knowledge links (4)
175
-
176
- | Tool | Purpose |
177
- |---|---|
178
- | `link_create` / `link_delete` / `link_related` / `link_suggest` | Graph-lite relationships between knowledge items. |
179
-
180
- ### Setup (3)
181
-
182
- | Tool | Purpose |
183
- |---|---|
184
- | `setup_status` | Report which collections exist. **Run this first** after installation. |
185
- | `setup_migrate` | **Reports** missing collections and points to the migration files. Does **not** apply migrations automatically — you must run them via PocketBase CLI or `psql`. |
186
- | `setup_seed` | Load seed data (e.g. `entity_aliases` for search). |
187
-
188
- ### CRM prospects (4)
189
-
190
- | Tool | Purpose |
191
- |---|---|
192
- | `prospect_create` / `prospect_update` / `prospect_list` / `prospect_search` | Sales pipeline. Stages: `new → contacted → responded → interested → ready_to_buy → proposal_sent → negotiating → closed_won / closed_lost / nurturing`. |
193
-
194
- ### Blog (4)
195
-
196
- | Tool | Purpose |
197
- |---|---|
198
- | `blog_create` / `blog_update` / `blog_list` / `blog_delete` | Blog post content management. |
199
-
200
- ### Email + content queues (3)
201
-
202
- | Tool | Purpose |
203
- |---|---|
204
- | `email_queue_add` | Queue an email (does NOT send — sending is done out-of-band). |
205
- | `content_queue_add` / `content_queue_list` | Content calendar for scheduled posts. |
206
-
207
- ---
208
-
209
- ## Common failures (and how to recover)
210
-
211
- ### "The 'X' table does not exist yet. Run setup_migrate to create the database schema."
212
-
213
- **What it means:** The collection backing this tool hasn't been created.
214
-
215
- **Fix:** `setup_migrate` only *reports* missing tables — it does not apply them. You need to run the actual migrations:
216
-
217
- - **PocketBase:** `./pocketbase migrate up` (after copying the files in `migrations/pocketbase/` into your `pb_migrations/` directory).
218
- - **Supabase:** run each file in `migrations/supabase/` in order via the SQL editor or `psql`.
219
-
220
- Then call `setup_status` to confirm.
221
-
222
- ### "Only knowledge tools work, everything else fails"
223
-
224
- **Symptom:** `knowledge_store` and `knowledge_recall` succeed but `goal_create`, `task_create`, `contact_create` all return the "table does not exist" error.
225
-
226
- **Cause:** You applied only the first migration (`001_core_schema`) which creates `knowledge`, `decisions`, and `sessions`. The rest of the collections come from migrations `002` through `010` (Supabase) or `002` through `008` (PocketBase).
227
-
228
- **Fix:** Apply all migrations in order.
229
-
230
- ### PocketBase disconnects between terminal sessions
231
-
232
- **Cause:** `pocketbase serve` runs in the foreground. When you close the terminal, the server stops.
233
-
234
- **Fix options:**
235
- - Run PocketBase under a process manager (pm2, forever) or a launchd plist on macOS.
236
- - Switch to the Supabase backend — it runs 24/7 in the cloud.
237
-
238
- ### MCP server disconnected after Claude Code restart
239
-
240
- **Cause:** Your MCP client is not reading the server config on startup, or the `npx -y` download got interrupted.
241
-
242
- **Fix:** Install globally once (`npm install -g @iwo-szapar/data-mcp`) and point `command` at `data-mcp` instead of `npx`. Restart your MCP client.
243
-
244
- ### "Database authentication failed"
245
-
246
- **PocketBase:** check `SB_POCKETBASE_ADMIN_EMAIL` / `PASSWORD` match an admin account in the Admin UI.
247
-
248
- **Supabase:** confirm you are using the `service_role` key, not `anon`. The anon key does not have write access to these tables.
249
-
250
- ---
251
-
252
- ## Schema mapping (optional)
253
-
254
- If your real tables have different names, set `SB_SCHEMA_MAP` to a JSON object:
255
-
256
- ```bash
257
- SB_SCHEMA_MAP='{"prospects":"sales_leads","contacts":"people"}'
258
- ```
259
-
260
- Logical names used by the tools (`prospects`, `contacts`, etc.) are transparently rewritten to your real table names. Empty keys or missing keys pass through unchanged.
261
-
262
- ---
263
-
264
- ## File layout
265
-
266
- ```
267
- dist/ compiled JS (entry: dist/index.js)
268
- migrations/
269
- pocketbase/ *.js migration files (PocketBase migrate format)
270
- supabase/ *.sql migration files (run in order)
271
- seed/ seed data (entity_aliases.json, etc.)
272
- ```
273
-
274
- The published package ships `dist/`, `migrations/`, `seed/`.
275
-
276
- ---
277
-
278
- ## License
279
-
280
- MIT
281
-
282
- ---
283
-
284
- ## Support
285
-
286
- This package is maintained by [Iwo Szapar](https://iwoszapar.com) as part of the Second Brain ecosystem. For issues specific to Second Brain v2 customers, reply to your purchase confirmation email. For general bugs, open an issue against the package on npm.