@nestcorehq/mcp-server 1.6.0 → 1.8.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.
package/README.md CHANGED
@@ -1,501 +1,510 @@
1
- # NestCore MCP Server
2
-
3
- A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server for [NestCore](https://nestcore.io) that enables AI agents (Claude, etc.) to manage your NestCore projects, databases, edge functions, storage, and more through a structured tool interface.
4
-
5
- ## Architecture
6
-
7
- ```
8
- Claude / AI Agent
9
- ↓ MCP Protocol (stdio)
10
- NestCore MCP Server ← this project
11
- ↓ REST API + JWT
12
- NestCore Backend (https://api.nestcore.io)
13
- ↓
14
- PostgreSQL / Storage / Edge Functions
15
- ```
16
-
17
- The MCP server **never accesses the database directly** — all operations are proxied through the NestCore backend API with full JWT authentication.
18
-
19
- ---
20
-
21
- ## Prerequisites
22
-
23
- - **Node.js** v18 or later
24
- - **npm** v9 or later
25
- - Access to the GitHub repository `Orbitnest/nestcore_mcp` (or install `@nestcorehq/mcp-server` from npm)
26
- - NestCore account — sign in at [nestcore.io](https://nestcore.io)
27
-
28
- ---
29
-
30
- ## Installation
31
-
32
- ### Option A — Install directly from GitHub (recommended for new devices)
33
-
34
- No cloning required. `npm install` downloads the package from GitHub and automatically compiles it via the `prepare` script.
35
-
36
- ```bash
37
- npm install -g github:Orbitnest/nestcore_mcp
38
- ```
39
-
40
- After installation the `nestcore-mcp` binary is available globally:
41
-
42
- ```bash
43
- nestcore-mcp # starts the MCP server
44
- ```
45
-
46
- The pre-rename `orbitnest-mcp` command is installed too and starts the same server.
47
-
48
- To install a specific commit or tag:
49
-
50
- ```bash
51
- npm install -g github:Orbitnest/nestcore_mcp#v1.0.0
52
- ```
53
-
54
- > **Private repo?** Make sure the machine has GitHub access. Either:
55
- > - SSH key added to the GitHub account (`git@github.com:...`), or
56
- > - A [Personal Access Token](https://github.com/settings/tokens) with `repo` scope configured in `~/.npmrc`:
57
- > ```
58
- > //npm.pkg.github.com/:_authToken=YOUR_TOKEN
59
- > ```
60
-
61
- ---
62
-
63
- ### Option B — Clone and build locally (for development)
64
-
65
- ```bash
66
- git clone https://github.com/Orbitnest/nestcore_mcp.git
67
- cd nestcore_mcp
68
- npm install # also runs `npm run build` automatically via prepare script
69
- ```
70
-
71
- ---
72
-
73
- ## Configuration
74
-
75
- All settings are passed as environment variables. No `.env` file is required when configuring via an MCP client (see below) — simply set them in the `env` block of your MCP config.
76
-
77
- For standalone use, copy the example file:
78
-
79
- ```bash
80
- cp .env.example .env
81
- # then edit .env as needed
82
- ```
83
-
84
- | Variable | Default | Description |
85
- |----------|---------|-------------|
86
- | `NESTCORE_API_URL` | `https://api.nestcore.io` | NestCore backend URL (falls back to `ORBITNEST_API_URL`) |
87
- | `NESTCORE_API_BASE_PATH` | `/api` | API base path (falls back to `ORBITNEST_API_BASE_PATH`) |
88
- | `NESTCORE_MIGRATIONS_DIR` | `migrations` | Default migrations directory (falls back to `ORBITNEST_MIGRATIONS_DIR`) |
89
- | `MCP_SERVER_NAME` | `nestcore` | MCP server identifier |
90
- | `LOG_LEVEL` | `info` | Logging level: `debug`, `info`, `warn`, `error` |
91
- | `DEFAULT_PROJECT_ID` | _(empty)_ | Auto-select project on startup |
92
- | `ENABLE_SQL_GUARD` | `true` | Validate SQL before execution |
93
- | `BLOCK_AUTH_TABLE_MUTATIONS` | `true` | Block writes to `auth_*` tables |
94
- | `SCHEMA_CACHE_TTL` | `300000` | Schema cache lifetime in ms (5 min) |
95
- | `TOKEN_REFRESH_THRESHOLD` | `60000` | Refresh token when < 60s from expiry |
96
-
97
- ---
98
-
99
- ## Connecting to Claude Code
100
-
101
- ### Option 1 — Via GitHub (no local clone needed)
102
-
103
- Add the server globally so it is available in any project. Claude Code will run it directly from the GitHub package:
104
-
105
- ```bash
106
- claude mcp add nestcore -- npx -y github:Orbitnest/nestcore_mcp
107
- ```
108
-
109
- Or edit `~/.claude.json` manually:
110
-
111
- ```json
112
- {
113
- "mcpServers": {
114
- "nestcore": {
115
- "command": "npx",
116
- "args": ["-y", "github:Orbitnest/nestcore_mcp"],
117
- "env": {
118
- "NESTCORE_API_URL": "https://api.nestcore.io"
119
- }
120
- }
121
- }
122
- }
123
- ```
124
-
125
- ### Option 2 — Via globally installed binary
126
-
127
- If you installed with `npm install -g`:
128
-
129
- ```bash
130
- claude mcp add nestcore -- nestcore-mcp
131
- ```
132
-
133
- ### Option 3 — Project-level from local clone
134
-
135
- The repository's `.mcp.json` is picked up automatically when you open this directory in Claude Code:
136
-
137
- ```bash
138
- npm run build # only needed the first time if prepare didn't run
139
- ```
140
-
141
- ### Verifying the connection
142
-
143
- ```bash
144
- claude mcp list
145
- # Should show: nestcore connected
146
- ```
147
-
148
- ---
149
-
150
- ## Connecting to VSCode
151
-
152
- The repository includes `.vscode/mcp.json` which is automatically picked up by the **GitHub Copilot / Claude VSCode extension** with MCP support enabled.
153
-
154
- **Using a local clone (development):**
155
-
156
- 1. Open this folder in VSCode
157
- 2. The `nestcore` server entry in `.vscode/mcp.json` points to `dist/index.js` and starts automatically
158
-
159
- **Using GitHub install on any other machine:**
160
-
161
- 1. Create or edit `.vscode/mcp.json` in your project:
162
-
163
- ```jsonc
164
- {
165
- "servers": {
166
- "nestcore": {
167
- "type": "stdio",
168
- "command": "npx",
169
- "args": ["-y", "github:Orbitnest/nestcore_mcp"],
170
- "env": {
171
- "NESTCORE_API_URL": "https://api.nestcore.io",
172
- "LOG_LEVEL": "info",
173
- "ENABLE_SQL_GUARD": "true",
174
- "BLOCK_AUTH_TABLE_MUTATIONS": "true"
175
- }
176
- }
177
- }
178
- }
179
- ```
180
-
181
- 2. Reload the VSCode window (`Ctrl+Shift+P` → `Developer: Reload Window`) — the server starts automatically.
182
-
183
- To point at a different backend URL, change `NESTCORE_API_URL` in the `env` block.
184
-
185
- ---
186
-
187
- ## First-Time Setup
188
-
189
- Once connected via Claude Code or VSCode, authenticate and set your project context:
190
-
191
- **1. Sign in as admin:**
192
-
193
- If your account has a password:
194
- ```
195
- Use nestcore_admin_signin with:
196
- email: "admin@example.com"
197
- password: "your-password"
198
- ```
199
-
200
- If you signed up with **Google, GitHub, or Apple** (no password), use OAuth.
201
- This opens your browser to complete sign-in and captures the session
202
- automatically via a one-time localhost callback:
203
- ```
204
- Use nestcore_login with:
205
- provider: "google" # or "github" / "apple"
206
- ```
207
-
208
- Credentials are saved to `~/.nestcore/credentials.json` and reloaded automatically on subsequent starts.
209
-
210
- > `nestcore_login` opens a browser, so run it on the machine where the MCP
211
- > server runs. It requires `NESTCORE_API_URL` to point at the NestCore API
212
- > whose console hosts the OAuth callback page (default `https://api.nestcore.io`).
213
-
214
- **2. List your projects:**
215
- ```
216
- Use nestcore_list_projects
217
- ```
218
-
219
- **3. Set active project:**
220
- ```
221
- Use nestcore_set_active_project with:
222
- projectId: "proj_abc123"
223
- ```
224
-
225
- All subsequent tools automatically use the active project — you rarely need to specify `projectId` again.
226
-
227
- ---
228
-
229
- ## Available Tools
230
-
231
- Every tool is named `nestcore_*`. Tools were called `orbitnest_*` before the
232
- rename: `tools/list` only returns the new names, but a `tools/call` for an old
233
- `orbitnest_*` name still runs the matching `nestcore_*` tool, so clients with a
234
- cached tool list keep working.
235
-
236
- ### Authentication (8 tools)
237
- | Tool | Description |
238
- |------|-------------|
239
- | `nestcore_admin_signin` | Sign in with email + password and save JWT credentials |
240
- | `nestcore_login` | Sign in with Google / GitHub / Apple via browser (for password-less accounts) |
241
- | `nestcore_admin_signup` | Create a new admin account |
242
- | `nestcore_admin_signup_verified` | Signup with email verification |
243
- | `nestcore_request_verification` | Request verification code |
244
- | `nestcore_refresh_token` | Manually refresh JWT token |
245
- | `nestcore_admin_signout` | Sign out and clear saved credentials |
246
- | `nestcore_get_profile` | Get current admin profile |
247
-
248
- ### Projects (7 tools)
249
- | Tool | Description |
250
- |------|-------------|
251
- | `nestcore_create_project` | Create project with dedicated database |
252
- | `nestcore_list_projects` | List all projects |
253
- | `nestcore_get_project` | Get project details |
254
- | `nestcore_update_project` | Rename or update project settings |
255
- | `nestcore_delete_project` | Delete project (requires `confirmDeletion: true`) |
256
- | `nestcore_get_project_stats` | Get project statistics |
257
- | `nestcore_get_project_health` | Check project health status |
258
-
259
- ### Database (12 tools)
260
- | Tool | Description |
261
- |------|-------------|
262
- | `nestcore_get_schema` | Fetch full database schema (cached 5 min) |
263
- | `nestcore_execute_sql` | Execute raw SQL with safety validation |
264
- | `nestcore_create_table` | Create a table from a structured definition |
265
- | `nestcore_list_tables` | List all tables |
266
- | `nestcore_get_table_data` | Query table data with pagination and filtering |
267
- | `nestcore_insert_row` | Insert a single row |
268
- | `nestcore_update_row` | Update a row by ID |
269
- | `nestcore_delete_row` | Delete a row by ID |
270
- | `nestcore_bulk_insert` | Insert multiple rows |
271
- | `nestcore_bulk_update` | Update multiple rows |
272
- | `nestcore_bulk_delete` | Delete multiple rows |
273
- | `nestcore_get_sql_history` | Retrieve SQL query history |
274
-
275
- ### Row-Level Security (6 tools)
276
- | Tool | Description |
277
- |------|-------------|
278
- | `nestcore_get_rls_status` | Check RLS status on a table |
279
- | `nestcore_enable_rls` | Enable RLS on a table |
280
- | `nestcore_disable_rls` | Disable RLS on a table |
281
- | `nestcore_list_policies` | List RLS policies |
282
- | `nestcore_create_policy` | Create a new RLS policy |
283
- | `nestcore_delete_policy` | Delete an RLS policy |
284
-
285
- ### Edge Functions (7 tools)
286
- | Tool | Description |
287
- |------|-------------|
288
- | `nestcore_create_function` | Create an edge function |
289
- | `nestcore_list_functions` | List all functions |
290
- | `nestcore_get_function` | Get function details |
291
- | `nestcore_update_function` | Update function source code |
292
- | `nestcore_delete_function` | Delete a function |
293
- | `nestcore_invoke_function` | Execute a function |
294
- | `nestcore_get_function_logs` | Get function execution logs |
295
-
296
- > **Function environment:** inside a function, read env vars with `Deno.env.get('NAME')`. Available by default: `NESTCORE_URL`, `NESTCORE_ANON_KEY` (public/RLS-protected), `PROJECT_ID`, `PROJECT_URL`, `FUNCTION_NAME`, plus any project env vars you add. **`NESTCORE_SERVICE_ROLE_KEY` (RLS-bypassing) is NOT provided by default** — if a function needs privileged DB access, add it as a project env var (copy the service_role key from the dashboard → API Keys, or use `nestcore_create_env_variable`). See `docs/known-issues.md` §7.
297
-
298
- ### Storage (9 tools)
299
- | Tool | Description |
300
- |------|-------------|
301
- | `nestcore_list_buckets` | List storage buckets |
302
- | `nestcore_create_bucket` | Create a new bucket |
303
- | `nestcore_upload_file` | Upload a file to a bucket |
304
- | `nestcore_download_file` | Download a file |
305
- | `nestcore_list_files` | List files in a bucket |
306
- | `nestcore_delete_files` | Delete files |
307
- | `nestcore_delete_bucket` | Delete a bucket |
308
- | `nestcore_get_bucket_size` | Get bucket storage usage |
309
- | `nestcore_get_public_url` | Get a public file URL |
310
-
311
- ### Logging (6 tools)
312
- | Tool | Description |
313
- |------|-------------|
314
- | `nestcore_get_logs` | Get general logs with filtering |
315
- | `nestcore_get_database_logs` | Get database operation logs |
316
- | `nestcore_get_slow_query_logs` | Get slow query logs |
317
- | `nestcore_get_auth_logs` | Get authentication logs |
318
- | `nestcore_get_edge_function_logs` | Get edge function logs |
319
- | `nestcore_export_logs` | Export logs in a specified format |
320
-
321
- ### Admin Management (6 tools)
322
- | Tool | Description |
323
- |------|-------------|
324
- | `nestcore_list_admins` | List all admin users |
325
- | `nestcore_create_admin` | Create a new admin |
326
- | `nestcore_get_admin` | Get admin details |
327
- | `nestcore_update_admin` | Update admin settings |
328
- | `nestcore_delete_admin` | Delete an admin user |
329
- | `nestcore_update_admin_password` | Reset admin password |
330
-
331
- ### SMTP (4 tools)
332
- | Tool | Description |
333
- |------|-------------|
334
- | `nestcore_get_smtp_settings` | Get SMTP configuration |
335
- | `nestcore_update_smtp_settings` | Update SMTP settings |
336
- | `nestcore_delete_smtp_settings` | Remove SMTP configuration |
337
- | `nestcore_test_smtp_connection` | Test SMTP connectivity |
338
-
339
- ### Integrations (13 tools)
340
- | Tool | Description |
341
- |------|-------------|
342
- | `nestcore_get_connection_string` | Get the direct Postgres connection string (when enabled) |
343
- | `nestcore_get_auth_security` | End-user auth limits in force (code length, wrong codes, codes per hour, lockout) |
344
- | `nestcore_set_auth_security` | Change those limits (admin) |
345
- | `nestcore_get_ai_settings` | AI gateway keys (masked), default models and spend caps |
346
- | `nestcore_ai_usage` | AI calls, tokens and cost per day, model and end user |
347
- | `nestcore_list_webhooks` | List database webhooks |
348
- | `nestcore_create_webhook` | Create a signed row-change webhook |
349
- | `nestcore_delete_webhook` | Delete a webhook |
350
- | `nestcore_test_webhook` | Send a test event to a webhook |
351
- | `nestcore_get_sms_config` | Get the project's Twilio/SMS config |
352
- | `nestcore_set_sms_config` | Configure Twilio (auth token stored encrypted) |
353
- | `nestcore_test_sms` | Send a test SMS |
354
- | `nestcore_enable_extension` | Enable a Postgres extension (e.g. `vector` for pgvector) |
355
-
356
- ### AI data (6 tools)
357
- | Tool | Description |
358
- |------|-------------|
359
- | `nestcore_ai_overview` | Counts of memories, subjects, collections, documents, threads, messages, traces (24 h) and embedded columns |
360
- | `nestcore_list_collections` | Vector collections with model, chunking and document counts |
361
- | `nestcore_memory_subjects` | Subjects that have memories (`user:<id>`, `agent:support`, ...) with counts |
362
- | `nestcore_list_embeddings` | Automatically embedded columns with progress (rows, embedded, pending, failed, last error) |
363
- | `nestcore_ai_traces` | Recent AI calls: model, tokens, cost, latency, status (never prompt text) |
364
- | `nestcore_enable_embeddings` | Embed a table's text columns into a `vector(768)` column kept up to date (admin; requires `confirmEnable: true`) |
365
-
366
- ### Dashboard (2 tools)
367
- | Tool | Description |
368
- |------|-------------|
369
- | `nestcore_get_dashboard_stats` | Get overall statistics |
370
- | `nestcore_get_dashboard_activity` | Get recent activity feed |
371
-
372
- ---
373
-
374
- ## Safety Features
375
-
376
- ### SQL Guard
377
- - Detects and blocks SQL injection patterns
378
- - Requires `confirmDestructive: true` for `DROP`, `TRUNCATE`, `DELETE` without `WHERE`
379
- - Blocks mutations on `auth_*` tables (configurable via `BLOCK_AUTH_TABLE_MUTATIONS`)
380
-
381
- ### Operation Guard
382
- - Bulk operations affecting more than 1,000 rows require explicit confirmation
383
- - Project deletion always requires `confirmDeletion: true`
384
- - RLS cannot be disabled on auth tables
385
-
386
- ### Auth Table Protection
387
- - Tables prefixed with `auth_` are read-only by default
388
- - Schema changes and direct mutations are blocked
389
-
390
- ---
391
-
392
- ## Common Workflows
393
-
394
- **Create a table with RLS:**
395
- ```
396
- nestcore_create_table({
397
- tableName: "posts",
398
- columns: [
399
- { name: "id", type: "uuid", primaryKey: true, default: "gen_random_uuid()" },
400
- { name: "title", type: "text", nullable: false },
401
- { name: "body", type: "text" },
402
- { name: "created_at", type: "timestamptz", default: "now()" }
403
- ],
404
- enableRLS: true
405
- })
406
- ```
407
-
408
- **Execute a safe query:**
409
- ```
410
- nestcore_execute_sql({ sql: "SELECT * FROM posts ORDER BY created_at DESC LIMIT 10" })
411
- ```
412
-
413
- **Execute a destructive query (requires explicit confirmation):**
414
- ```
415
- nestcore_execute_sql({
416
- sql: "DELETE FROM posts WHERE status = 'draft'",
417
- confirmDestructive: true
418
- })
419
- ```
420
-
421
- **Deploy an edge function:**
422
- ```
423
- nestcore_create_function({
424
- name: "send-welcome",
425
- sourceCode: "export default async (req) => { return new Response('Hello!'); }"
426
- })
427
- ```
428
-
429
- ---
430
-
431
- ## Development
432
-
433
- ```bash
434
- npm install # installs deps and runs `npm run build` automatically (prepare script)
435
- npm run dev # TypeScript watch mode (tsx)
436
- npm run build # Compile to dist/
437
- npm start # Run compiled server
438
- ```
439
-
440
- Logs are written to **stderr** (MCP protocol uses stdout for communication), so they do not interfere with the MCP message stream.
441
-
442
- ---
443
-
444
- ## Workspace Auto-Detection
445
-
446
- If your project root contains `.nestcore/config.json`, the MCP server automatically loads the project context on startup:
447
-
448
- ```json
449
- {
450
- "projectId": "proj_abc123",
451
- "projectSlug": "my-project",
452
- "name": "My Project",
453
- "apiUrl": "https://api.nestcore.io"
454
- }
455
- ```
456
-
457
- This is the same file `nestcore link` (the CLI) writes; older CLI versions wrote `slug` instead of `projectSlug`, which is still read. A pre-rename `.orbitnest/config.json` is read when a directory has no `.nestcore/config.json`; saving the active project then writes `.nestcore/config.json`. `nestcore_set_active_project` updates this file when one was found, and never creates one elsewhere.
458
-
459
- ---
460
-
461
- ## Credentials Storage
462
-
463
- After signing in, tokens are persisted to `~/.nestcore/credentials.json` (mode `0600`) and automatically reloaded on the next server start. If that file doesn't exist yet, the pre-rename `~/.orbitnest/credentials.json` is used (and kept in sync while it exists, so older CLI/MCP versions sharing it stay signed in). Tokens are refreshed automatically when they are within 60 seconds of expiry.
464
-
465
- ---
466
-
467
- ## Troubleshooting
468
-
469
- **Server fails to start**
470
- - If using a local clone, run `npm run build` — the `dist/` directory must exist
471
- - Check that Node.js v18+ is installed: `node --version`
472
- - If using `npx github:Orbitnest/nestcore_mcp`, ensure you have GitHub access (SSH key or token)
473
-
474
- **`Not authenticated` errors**
475
- - Run `nestcore_admin_signin` to sign in
476
- - Credentials are stored in `~/.nestcore/credentials.json`
477
-
478
- **`No active project` errors**
479
- - Run `nestcore_list_projects` then `nestcore_set_active_project`
480
- - Or set `DEFAULT_PROJECT_ID` in your environment / MCP `env` block
481
-
482
- **MCP server not appearing in VSCode**
483
- - Ensure MCP support is enabled in the extension settings
484
- - Confirm `npm run build` has been run if using a local clone
485
- - Reload the VSCode window (`Ctrl+Shift+P` → `Developer: Reload Window`)
486
- - When using `npx github:...`, the first start may take a few seconds while npm downloads the package
487
-
488
- **MCP server not appearing in Claude Code**
489
- - Run `claude mcp list` to see registered servers
490
- - Re-register: `claude mcp remove nestcore && claude mcp add nestcore -- npx -y github:Orbitnest/nestcore_mcp`
491
- - If using project-level `.mcp.json`, ensure you opened Claude Code from this project directory
492
-
493
- **GitHub access errors during npx install**
494
- - Add your SSH key: `ssh-add ~/.ssh/id_rsa`
495
- - Or create a GitHub Personal Access Token with `repo` scope and set it in `~/.npmrc`:
496
-
497
- ---
498
-
499
- ## License
500
-
501
- MIT — NestCore Team
1
+ # NestCore MCP Server
2
+
3
+ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server for [NestCore](https://nestcore.io) that enables AI agents (Claude, etc.) to manage your NestCore projects, databases, edge functions, storage, and more through a structured tool interface.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ Claude / AI Agent
9
+ ↓ MCP Protocol (stdio)
10
+ NestCore MCP Server ← this project
11
+ ↓ REST API + JWT
12
+ NestCore Backend (https://api.nestcore.io)
13
+ ↓
14
+ PostgreSQL / Storage / Edge Functions
15
+ ```
16
+
17
+ The MCP server **never accesses the database directly** — all operations are proxied through the NestCore backend API with full JWT authentication.
18
+
19
+ ---
20
+
21
+ ## Prerequisites
22
+
23
+ - **Node.js** v18 or later
24
+ - **npm** v9 or later
25
+ - Access to the GitHub repository `Orbitnest/nestcore_mcp` (or install `@nestcorehq/mcp-server` from npm)
26
+ - NestCore account — sign in at [nestcore.io](https://nestcore.io)
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ ### Option A — Install directly from GitHub (recommended for new devices)
33
+
34
+ No cloning required. `npm install` downloads the package from GitHub and automatically compiles it via the `prepare` script.
35
+
36
+ ```bash
37
+ npm install -g github:Orbitnest/nestcore_mcp
38
+ ```
39
+
40
+ After installation the `nestcore-mcp` binary is available globally:
41
+
42
+ ```bash
43
+ nestcore-mcp # starts the MCP server
44
+ ```
45
+
46
+ The pre-rename `orbitnest-mcp` command is installed too and starts the same server.
47
+
48
+ To install a specific commit or tag:
49
+
50
+ ```bash
51
+ npm install -g github:Orbitnest/nestcore_mcp#v1.0.0
52
+ ```
53
+
54
+ > **Private repo?** Make sure the machine has GitHub access. Either:
55
+ > - SSH key added to the GitHub account (`git@github.com:...`), or
56
+ > - A [Personal Access Token](https://github.com/settings/tokens) with `repo` scope configured in `~/.npmrc`:
57
+ > ```
58
+ > //npm.pkg.github.com/:_authToken=YOUR_TOKEN
59
+ > ```
60
+
61
+ ---
62
+
63
+ ### Option B — Clone and build locally (for development)
64
+
65
+ ```bash
66
+ git clone https://github.com/Orbitnest/nestcore_mcp.git
67
+ cd nestcore_mcp
68
+ npm install # also runs `npm run build` automatically via prepare script
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Configuration
74
+
75
+ All settings are passed as environment variables. No `.env` file is required when configuring via an MCP client (see below) — simply set them in the `env` block of your MCP config.
76
+
77
+ For standalone use, copy the example file:
78
+
79
+ ```bash
80
+ cp .env.example .env
81
+ # then edit .env as needed
82
+ ```
83
+
84
+ | Variable | Default | Description |
85
+ |----------|---------|-------------|
86
+ | `NESTCORE_API_URL` | `https://api.nestcore.io` | NestCore backend URL (falls back to `ORBITNEST_API_URL`) |
87
+ | `NESTCORE_API_BASE_PATH` | `/api` | API base path (falls back to `ORBITNEST_API_BASE_PATH`) |
88
+ | `NESTCORE_MIGRATIONS_DIR` | `migrations` | Default migrations directory (falls back to `ORBITNEST_MIGRATIONS_DIR`) |
89
+ | `MCP_SERVER_NAME` | `nestcore` | MCP server identifier |
90
+ | `LOG_LEVEL` | `info` | Logging level: `debug`, `info`, `warn`, `error` |
91
+ | `DEFAULT_PROJECT_ID` | _(empty)_ | Auto-select project on startup |
92
+ | `ENABLE_SQL_GUARD` | `true` | Validate SQL before execution |
93
+ | `BLOCK_AUTH_TABLE_MUTATIONS` | `true` | Block writes to `auth_*` tables |
94
+ | `SCHEMA_CACHE_TTL` | `300000` | Schema cache lifetime in ms (5 min) |
95
+ | `TOKEN_REFRESH_THRESHOLD` | `60000` | Refresh token when < 60s from expiry |
96
+
97
+ ---
98
+
99
+ ## Connecting to Claude Code
100
+
101
+ ### Option 1 — Via GitHub (no local clone needed)
102
+
103
+ Add the server globally so it is available in any project. Claude Code will run it directly from the GitHub package:
104
+
105
+ ```bash
106
+ claude mcp add nestcore -- npx -y github:Orbitnest/nestcore_mcp
107
+ ```
108
+
109
+ Or edit `~/.claude.json` manually:
110
+
111
+ ```json
112
+ {
113
+ "mcpServers": {
114
+ "nestcore": {
115
+ "command": "npx",
116
+ "args": ["-y", "github:Orbitnest/nestcore_mcp"],
117
+ "env": {
118
+ "NESTCORE_API_URL": "https://api.nestcore.io"
119
+ }
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ ### Option 2 — Via globally installed binary
126
+
127
+ If you installed with `npm install -g`:
128
+
129
+ ```bash
130
+ claude mcp add nestcore -- nestcore-mcp
131
+ ```
132
+
133
+ ### Option 3 — Project-level from local clone
134
+
135
+ The repository's `.mcp.json` is picked up automatically when you open this directory in Claude Code:
136
+
137
+ ```bash
138
+ npm run build # only needed the first time if prepare didn't run
139
+ ```
140
+
141
+ ### Verifying the connection
142
+
143
+ ```bash
144
+ claude mcp list
145
+ # Should show: nestcore connected
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Connecting to VSCode
151
+
152
+ The repository includes `.vscode/mcp.json` which is automatically picked up by the **GitHub Copilot / Claude VSCode extension** with MCP support enabled.
153
+
154
+ **Using a local clone (development):**
155
+
156
+ 1. Open this folder in VSCode
157
+ 2. The `nestcore` server entry in `.vscode/mcp.json` points to `dist/index.js` and starts automatically
158
+
159
+ **Using GitHub install on any other machine:**
160
+
161
+ 1. Create or edit `.vscode/mcp.json` in your project:
162
+
163
+ ```jsonc
164
+ {
165
+ "servers": {
166
+ "nestcore": {
167
+ "type": "stdio",
168
+ "command": "npx",
169
+ "args": ["-y", "github:Orbitnest/nestcore_mcp"],
170
+ "env": {
171
+ "NESTCORE_API_URL": "https://api.nestcore.io",
172
+ "LOG_LEVEL": "info",
173
+ "ENABLE_SQL_GUARD": "true",
174
+ "BLOCK_AUTH_TABLE_MUTATIONS": "true"
175
+ }
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ 2. Reload the VSCode window (`Ctrl+Shift+P` → `Developer: Reload Window`) — the server starts automatically.
182
+
183
+ To point at a different backend URL, change `NESTCORE_API_URL` in the `env` block.
184
+
185
+ ---
186
+
187
+ ## First-Time Setup
188
+
189
+ Once connected via Claude Code or VSCode, authenticate and set your project context:
190
+
191
+ **1. Sign in as admin:**
192
+
193
+ If your account has a password:
194
+ ```
195
+ Use nestcore_admin_signin with:
196
+ email: "admin@example.com"
197
+ password: "your-password"
198
+ ```
199
+
200
+ If you signed up with **Google, GitHub, or Apple** (no password), use OAuth.
201
+ This opens your browser to complete sign-in and captures the session
202
+ automatically via a one-time localhost callback:
203
+ ```
204
+ Use nestcore_login with:
205
+ provider: "google" # or "github" / "apple"
206
+ ```
207
+
208
+ Credentials are saved to `~/.nestcore/credentials.json` and reloaded automatically on subsequent starts.
209
+
210
+ > `nestcore_login` opens a browser, so run it on the machine where the MCP
211
+ > server runs. It requires `NESTCORE_API_URL` to point at the NestCore API
212
+ > whose console hosts the OAuth callback page (default `https://api.nestcore.io`).
213
+
214
+ **2. List your projects:**
215
+ ```
216
+ Use nestcore_list_projects
217
+ ```
218
+
219
+ **3. Set active project:**
220
+ ```
221
+ Use nestcore_set_active_project with:
222
+ projectId: "proj_abc123"
223
+ ```
224
+
225
+ All subsequent tools automatically use the active project — you rarely need to specify `projectId` again.
226
+
227
+ ---
228
+
229
+ ## Available Tools
230
+
231
+ Every tool is named `nestcore_*`. Tools were called `orbitnest_*` before the
232
+ rename: `tools/list` only returns the new names, but a `tools/call` for an old
233
+ `orbitnest_*` name still runs the matching `nestcore_*` tool, so clients with a
234
+ cached tool list keep working.
235
+
236
+ ### Authentication (8 tools)
237
+ | Tool | Description |
238
+ |------|-------------|
239
+ | `nestcore_admin_signin` | Sign in with email + password and save JWT credentials |
240
+ | `nestcore_login` | Sign in with Google / GitHub / Apple via browser (for password-less accounts) |
241
+ | `nestcore_admin_signup` | Create a new admin account |
242
+ | `nestcore_admin_signup_verified` | Signup with email verification |
243
+ | `nestcore_request_verification` | Request verification code |
244
+ | `nestcore_refresh_token` | Manually refresh JWT token |
245
+ | `nestcore_admin_signout` | Sign out and clear saved credentials |
246
+ | `nestcore_get_profile` | Get current admin profile |
247
+
248
+ ### Projects (7 tools)
249
+ | Tool | Description |
250
+ |------|-------------|
251
+ | `nestcore_create_project` | Create project with dedicated database |
252
+ | `nestcore_list_projects` | List all projects |
253
+ | `nestcore_get_project` | Get project details |
254
+ | `nestcore_update_project` | Rename or update project settings |
255
+ | `nestcore_delete_project` | Delete project (requires `confirmDeletion: true`) |
256
+ | `nestcore_get_project_stats` | Get project statistics |
257
+ | `nestcore_get_project_health` | Check project health status |
258
+
259
+ ### Database (12 tools)
260
+ | Tool | Description |
261
+ |------|-------------|
262
+ | `nestcore_get_schema` | Fetch full database schema (cached 5 min) |
263
+ | `nestcore_execute_sql` | Execute raw SQL with safety validation |
264
+ | `nestcore_create_table` | Create a table from a structured definition |
265
+ | `nestcore_list_tables` | List all tables |
266
+ | `nestcore_get_table_data` | Query table data with pagination and filtering |
267
+ | `nestcore_insert_row` | Insert a single row |
268
+ | `nestcore_update_row` | Update a row by ID |
269
+ | `nestcore_delete_row` | Delete a row by ID |
270
+ | `nestcore_bulk_insert` | Insert multiple rows |
271
+ | `nestcore_bulk_update` | Update multiple rows |
272
+ | `nestcore_bulk_delete` | Delete multiple rows |
273
+ | `nestcore_get_sql_history` | Retrieve SQL query history |
274
+
275
+ ### Row-Level Security (6 tools)
276
+ | Tool | Description |
277
+ |------|-------------|
278
+ | `nestcore_get_rls_status` | Check RLS status on a table |
279
+ | `nestcore_enable_rls` | Enable RLS on a table |
280
+ | `nestcore_disable_rls` | Disable RLS on a table |
281
+ | `nestcore_list_policies` | List RLS policies |
282
+ | `nestcore_create_policy` | Create a new RLS policy |
283
+ | `nestcore_delete_policy` | Delete an RLS policy |
284
+
285
+ ### Edge Functions (7 tools)
286
+ | Tool | Description |
287
+ |------|-------------|
288
+ | `nestcore_create_function` | Create an edge function |
289
+ | `nestcore_list_functions` | List all functions |
290
+ | `nestcore_get_function` | Get function details |
291
+ | `nestcore_update_function` | Update function source code |
292
+ | `nestcore_delete_function` | Delete a function |
293
+ | `nestcore_invoke_function` | Execute a function |
294
+ | `nestcore_get_function_logs` | Get function execution logs |
295
+
296
+ > **Function environment:** inside a function, read env vars with `Deno.env.get('NAME')`. Available by default: `NESTCORE_URL`, `NESTCORE_ANON_KEY` (public/RLS-protected), `PROJECT_ID`, `PROJECT_URL`, `FUNCTION_NAME`, plus any project env vars you add. **`NESTCORE_SERVICE_ROLE_KEY` (RLS-bypassing) is NOT provided by default** — if a function needs privileged DB access, add it as a project env var (copy the service_role key from the dashboard → API Keys, or use `nestcore_create_env_variable`). See `docs/known-issues.md` §7.
297
+
298
+ ### Storage (9 tools)
299
+ | Tool | Description |
300
+ |------|-------------|
301
+ | `nestcore_list_buckets` | List storage buckets |
302
+ | `nestcore_create_bucket` | Create a new bucket |
303
+ | `nestcore_upload_file` | Upload a file to a bucket |
304
+ | `nestcore_download_file` | Download a file |
305
+ | `nestcore_list_files` | List files in a bucket |
306
+ | `nestcore_delete_files` | Delete files |
307
+ | `nestcore_delete_bucket` | Delete a bucket |
308
+ | `nestcore_get_bucket_size` | Get bucket storage usage |
309
+ | `nestcore_get_public_url` | Get a public file URL |
310
+
311
+ ### Logging (6 tools)
312
+ | Tool | Description |
313
+ |------|-------------|
314
+ | `nestcore_get_logs` | Get general logs with filtering |
315
+ | `nestcore_get_database_logs` | Get database operation logs |
316
+ | `nestcore_get_slow_query_logs` | Get slow query logs |
317
+ | `nestcore_get_auth_logs` | Get authentication logs |
318
+ | `nestcore_get_edge_function_logs` | Get edge function logs |
319
+ | `nestcore_export_logs` | Export logs in a specified format |
320
+
321
+ ### Admin Management (6 tools)
322
+ | Tool | Description |
323
+ |------|-------------|
324
+ | `nestcore_list_admins` | List all admin users |
325
+ | `nestcore_create_admin` | Create a new admin |
326
+ | `nestcore_get_admin` | Get admin details |
327
+ | `nestcore_update_admin` | Update admin settings |
328
+ | `nestcore_delete_admin` | Delete an admin user |
329
+ | `nestcore_update_admin_password` | Reset admin password |
330
+
331
+ ### SMTP (4 tools)
332
+ | Tool | Description |
333
+ |------|-------------|
334
+ | `nestcore_get_smtp_settings` | Get SMTP configuration |
335
+ | `nestcore_update_smtp_settings` | Update SMTP settings |
336
+ | `nestcore_delete_smtp_settings` | Remove SMTP configuration |
337
+ | `nestcore_test_smtp_connection` | Test SMTP connectivity |
338
+
339
+ ### Integrations (13 tools)
340
+ | Tool | Description |
341
+ |------|-------------|
342
+ | `nestcore_get_connection_string` | Get the direct Postgres connection string (when enabled) |
343
+ | `nestcore_get_auth_security` | End-user auth limits in force (code length, wrong codes, codes per hour, lockout) |
344
+ | `nestcore_set_auth_security` | Change those limits (admin) |
345
+ | `nestcore_get_ai_settings` | AI gateway keys (masked), default models and spend caps |
346
+ | `nestcore_ai_usage` | AI calls, tokens and cost per day, model and end user |
347
+ | `nestcore_list_webhooks` | List database webhooks |
348
+ | `nestcore_create_webhook` | Create a signed row-change webhook |
349
+ | `nestcore_delete_webhook` | Delete a webhook |
350
+ | `nestcore_test_webhook` | Send a test event to a webhook |
351
+ | `nestcore_get_sms_config` | Get the project's Twilio/SMS config |
352
+ | `nestcore_set_sms_config` | Configure Twilio (auth token stored encrypted) |
353
+ | `nestcore_test_sms` | Send a test SMS |
354
+ | `nestcore_enable_extension` | Enable a Postgres extension (e.g. `vector` for pgvector) |
355
+
356
+ ### AI data (6 tools)
357
+ | Tool | Description |
358
+ |------|-------------|
359
+ | `nestcore_ai_overview` | Counts of memories, subjects, collections, documents, threads, messages, traces (24 h) and embedded columns |
360
+ | `nestcore_list_collections` | Vector collections with model, chunking and document counts |
361
+ | `nestcore_memory_subjects` | Subjects that have memories (`user:<id>`, `agent:support`, ...) with counts |
362
+ | `nestcore_list_embeddings` | Automatically embedded columns with progress (rows, embedded, pending, failed, last error) |
363
+ | `nestcore_ai_traces` | Recent AI calls: model, tokens, cost, latency, status (never prompt text) |
364
+ | `nestcore_enable_embeddings` | Embed a table's text columns into a `vector(768)` column kept up to date (admin; requires `confirmEnable: true`) |
365
+
366
+ ### AI credits (3 tools)
367
+ Prepaid AI credit is per workspace and pays for AI calls of projects without their own provider key (a project's own key always wins). Calls paid from credit fail with `CREDITS_EXHAUSTED` (`reason`: `balance` or `spend_cap`, plus `buyUrl`) when the balance is gone or the monthly cap is reached.
368
+
369
+ | Tool | Description |
370
+ |------|-------------|
371
+ | `nestcore_get_credits` | Balance, monthly cap, this month's spend, availability, credit packs and the recent ledger |
372
+ | `nestcore_set_credit_cap` | Set the monthly cap in USD, or `null` to remove it (admin) |
373
+ | `nestcore_buy_credits` | Stripe Checkout link for a credit pack, for a person to open and pay (admin; adds no credit by itself) |
374
+
375
+ ### Dashboard (2 tools)
376
+ | Tool | Description |
377
+ |------|-------------|
378
+ | `nestcore_get_dashboard_stats` | Get overall statistics |
379
+ | `nestcore_get_dashboard_activity` | Get recent activity feed |
380
+
381
+ ---
382
+
383
+ ## Safety Features
384
+
385
+ ### SQL Guard
386
+ - Detects and blocks SQL injection patterns
387
+ - Requires `confirmDestructive: true` for `DROP`, `TRUNCATE`, `DELETE` without `WHERE`
388
+ - Blocks mutations on `auth_*` tables (configurable via `BLOCK_AUTH_TABLE_MUTATIONS`)
389
+
390
+ ### Operation Guard
391
+ - Bulk operations affecting more than 1,000 rows require explicit confirmation
392
+ - Project deletion always requires `confirmDeletion: true`
393
+ - RLS cannot be disabled on auth tables
394
+
395
+ ### Auth Table Protection
396
+ - Tables prefixed with `auth_` are read-only by default
397
+ - Schema changes and direct mutations are blocked
398
+
399
+ ---
400
+
401
+ ## Common Workflows
402
+
403
+ **Create a table with RLS:**
404
+ ```
405
+ nestcore_create_table({
406
+ tableName: "posts",
407
+ columns: [
408
+ { name: "id", type: "uuid", primaryKey: true, default: "gen_random_uuid()" },
409
+ { name: "title", type: "text", nullable: false },
410
+ { name: "body", type: "text" },
411
+ { name: "created_at", type: "timestamptz", default: "now()" }
412
+ ],
413
+ enableRLS: true
414
+ })
415
+ ```
416
+
417
+ **Execute a safe query:**
418
+ ```
419
+ nestcore_execute_sql({ sql: "SELECT * FROM posts ORDER BY created_at DESC LIMIT 10" })
420
+ ```
421
+
422
+ **Execute a destructive query (requires explicit confirmation):**
423
+ ```
424
+ nestcore_execute_sql({
425
+ sql: "DELETE FROM posts WHERE status = 'draft'",
426
+ confirmDestructive: true
427
+ })
428
+ ```
429
+
430
+ **Deploy an edge function:**
431
+ ```
432
+ nestcore_create_function({
433
+ name: "send-welcome",
434
+ sourceCode: "export default async (req) => { return new Response('Hello!'); }"
435
+ })
436
+ ```
437
+
438
+ ---
439
+
440
+ ## Development
441
+
442
+ ```bash
443
+ npm install # installs deps and runs `npm run build` automatically (prepare script)
444
+ npm run dev # TypeScript watch mode (tsx)
445
+ npm run build # Compile to dist/
446
+ npm start # Run compiled server
447
+ ```
448
+
449
+ Logs are written to **stderr** (MCP protocol uses stdout for communication), so they do not interfere with the MCP message stream.
450
+
451
+ ---
452
+
453
+ ## Workspace Auto-Detection
454
+
455
+ If your project root contains `.nestcore/config.json`, the MCP server automatically loads the project context on startup:
456
+
457
+ ```json
458
+ {
459
+ "projectId": "proj_abc123",
460
+ "projectSlug": "my-project",
461
+ "name": "My Project",
462
+ "apiUrl": "https://api.nestcore.io"
463
+ }
464
+ ```
465
+
466
+ This is the same file `nestcore link` (the CLI) writes; older CLI versions wrote `slug` instead of `projectSlug`, which is still read. A pre-rename `.orbitnest/config.json` is read when a directory has no `.nestcore/config.json`; saving the active project then writes `.nestcore/config.json`. `nestcore_set_active_project` updates this file when one was found, and never creates one elsewhere.
467
+
468
+ ---
469
+
470
+ ## Credentials Storage
471
+
472
+ After signing in, tokens are persisted to `~/.nestcore/credentials.json` (mode `0600`) and automatically reloaded on the next server start. If that file doesn't exist yet, the pre-rename `~/.orbitnest/credentials.json` is used (and kept in sync while it exists, so older CLI/MCP versions sharing it stay signed in). Tokens are refreshed automatically when they are within 60 seconds of expiry.
473
+
474
+ ---
475
+
476
+ ## Troubleshooting
477
+
478
+ **Server fails to start**
479
+ - If using a local clone, run `npm run build` — the `dist/` directory must exist
480
+ - Check that Node.js v18+ is installed: `node --version`
481
+ - If using `npx github:Orbitnest/nestcore_mcp`, ensure you have GitHub access (SSH key or token)
482
+
483
+ **`Not authenticated` errors**
484
+ - Run `nestcore_admin_signin` to sign in
485
+ - Credentials are stored in `~/.nestcore/credentials.json`
486
+
487
+ **`No active project` errors**
488
+ - Run `nestcore_list_projects` then `nestcore_set_active_project`
489
+ - Or set `DEFAULT_PROJECT_ID` in your environment / MCP `env` block
490
+
491
+ **MCP server not appearing in VSCode**
492
+ - Ensure MCP support is enabled in the extension settings
493
+ - Confirm `npm run build` has been run if using a local clone
494
+ - Reload the VSCode window (`Ctrl+Shift+P` → `Developer: Reload Window`)
495
+ - When using `npx github:...`, the first start may take a few seconds while npm downloads the package
496
+
497
+ **MCP server not appearing in Claude Code**
498
+ - Run `claude mcp list` to see registered servers
499
+ - Re-register: `claude mcp remove nestcore && claude mcp add nestcore -- npx -y github:Orbitnest/nestcore_mcp`
500
+ - If using project-level `.mcp.json`, ensure you opened Claude Code from this project directory
501
+
502
+ **GitHub access errors during npx install**
503
+ - Add your SSH key: `ssh-add ~/.ssh/id_rsa`
504
+ - Or create a GitHub Personal Access Token with `repo` scope and set it in `~/.npmrc`:
505
+
506
+ ---
507
+
508
+ ## License
509
+
510
+ MIT — NestCore Team