@productbrain/mcp 0.0.1-beta.0 → 0.0.1-beta.10
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/.env.mcp.example +10 -19
- package/dist/chunk-XBMI6QHR.js +100 -0
- package/dist/chunk-XBMI6QHR.js.map +1 -0
- package/dist/chunk-ZMGVB2VY.js +1136 -0
- package/dist/chunk-ZMGVB2VY.js.map +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/index.js +3172 -1223
- package/dist/index.js.map +1 -1
- package/dist/setup-6KVGMTRP.js +330 -0
- package/dist/setup-6KVGMTRP.js.map +1 -0
- package/dist/smart-capture-YUVDO42L.js +14 -0
- package/package.json +10 -26
- package/README.md +0 -238
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/setup-K757L5KR.js +0 -227
- package/dist/setup-K757L5KR.js.map +0 -1
- /package/dist/{chunk-DGUM43GV.js.map → smart-capture-YUVDO42L.js.map} +0 -0
package/README.md
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
# ProductBrain
|
|
2
|
-
|
|
3
|
-
The single source of truth for product knowledge — glossary, business rules, tensions, decisions, labels, and relations — accessible as an MCP server in [Claude Desktop](https://claude.ai/download), [Cursor](https://cursor.com), and any MCP-compatible AI assistant.
|
|
4
|
-
|
|
5
|
-
ProductBrain connects your AI assistant to your team's knowledge base. Ask questions, capture decisions, and build a living knowledge graph without leaving your editor.
|
|
6
|
-
|
|
7
|
-
## Quick Start (Cloud)
|
|
8
|
-
|
|
9
|
-
### Option A: Guided setup (recommended)
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npx productbrain setup
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
This opens SynergyOS → Settings → API Keys, prompts you to paste your key, and writes the config for Cursor or Claude Desktop.
|
|
16
|
-
|
|
17
|
-
### Option B: Manual config
|
|
18
|
-
|
|
19
|
-
**1. Get your API key**
|
|
20
|
-
|
|
21
|
-
Go to **SynergyOS → Settings → API Keys** and click **Generate Key**. Copy the `pb_sk_...` key.
|
|
22
|
-
|
|
23
|
-
**2. Configure your AI assistant**
|
|
24
|
-
|
|
25
|
-
**Claude Desktop** — edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"mcpServers": {
|
|
30
|
-
"productbrain": {
|
|
31
|
-
"command": "npx",
|
|
32
|
-
"args": ["-y", "productbrain"],
|
|
33
|
-
"env": {
|
|
34
|
-
"PRODUCTBRAIN_API_KEY": "pb_sk_your_key_here"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
**Cursor** — edit `.cursor/mcp.json` in your project:
|
|
42
|
-
|
|
43
|
-
```json
|
|
44
|
-
{
|
|
45
|
-
"mcpServers": {
|
|
46
|
-
"productbrain": {
|
|
47
|
-
"command": "npx",
|
|
48
|
-
"args": ["-y", "productbrain"],
|
|
49
|
-
"env": {
|
|
50
|
-
"PRODUCTBRAIN_API_KEY": "pb_sk_your_key_here"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**3. Restart your assistant and verify**
|
|
58
|
-
|
|
59
|
-
Ask:
|
|
60
|
-
|
|
61
|
-
> "Use the health tool to check ProductBrain connectivity"
|
|
62
|
-
|
|
63
|
-
You should see your workspace ID, collection count, and latency.
|
|
64
|
-
|
|
65
|
-
## Self-Hosted Setup
|
|
66
|
-
|
|
67
|
-
If you're running your own Convex deployment, use the three-variable config:
|
|
68
|
-
|
|
69
|
-
```json
|
|
70
|
-
{
|
|
71
|
-
"mcpServers": {
|
|
72
|
-
"productbrain": {
|
|
73
|
-
"command": "npx",
|
|
74
|
-
"args": ["-y", "productbrain"],
|
|
75
|
-
"env": {
|
|
76
|
-
"CONVEX_SITE_URL": "https://your-deployment.convex.site",
|
|
77
|
-
"MCP_API_KEY": "your-shared-api-key",
|
|
78
|
-
"WORKSPACE_SLUG": "your-workspace-slug"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
| Variable | Where to find it |
|
|
86
|
-
|----------|-----------------|
|
|
87
|
-
| `CONVEX_SITE_URL` | Convex dashboard → Settings → URL (use `*.convex.site`, not `*.convex.cloud`) |
|
|
88
|
-
| `MCP_API_KEY` | Must match the `MCP_API_KEY` env var in your Convex deployment |
|
|
89
|
-
| `WORKSPACE_SLUG` | Your workspace slug from the SynergyOS URL |
|
|
90
|
-
|
|
91
|
-
## Dev vs Production
|
|
92
|
-
|
|
93
|
-
Set `PRODUCTBRAIN_URL` to switch between environments:
|
|
94
|
-
|
|
95
|
-
```json
|
|
96
|
-
{
|
|
97
|
-
"env": {
|
|
98
|
-
"PRODUCTBRAIN_API_KEY": "pb_sk_your_key_here",
|
|
99
|
-
"PRODUCTBRAIN_URL": "http://localhost:3210"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Omit `PRODUCTBRAIN_URL` to default to production.
|
|
105
|
-
|
|
106
|
-
## What You Can Do
|
|
107
|
-
|
|
108
|
-
### Search and explore
|
|
109
|
-
|
|
110
|
-
- *"Search the glossary for 'tension'"*
|
|
111
|
-
- *"List all business rules in the Governance domain"*
|
|
112
|
-
- *"What is the canonical definition of 'supplier'?"*
|
|
113
|
-
|
|
114
|
-
### Capture knowledge
|
|
115
|
-
|
|
116
|
-
- *"Capture a tension: our MCP entry creation takes too many steps"*
|
|
117
|
-
- *"Draft a decision record for choosing Convex over Supabase"*
|
|
118
|
-
- *"Create a business rule about API key rotation"*
|
|
119
|
-
|
|
120
|
-
### Navigate the knowledge graph
|
|
121
|
-
|
|
122
|
-
- *"Gather full context around FEAT-001"*
|
|
123
|
-
- *"What entries are related to GT-019?"*
|
|
124
|
-
- *"Suggest links for this new tension"*
|
|
125
|
-
|
|
126
|
-
### Check quality
|
|
127
|
-
|
|
128
|
-
- *"Run a quality check on TEN-graph-db"*
|
|
129
|
-
- *"Review business rules for the AI & MCP Integration domain"*
|
|
130
|
-
- *"Verify the glossary against the codebase"*
|
|
131
|
-
|
|
132
|
-
## Tools (20+)
|
|
133
|
-
|
|
134
|
-
| Tool | What it does |
|
|
135
|
-
|------|-------------|
|
|
136
|
-
| `health` | Verify connectivity and get workspace stats |
|
|
137
|
-
| `kb-search` | Full-text search across all knowledge entries |
|
|
138
|
-
| `list-collections` | Browse all collection schemas |
|
|
139
|
-
| `list-entries` | Browse entries with optional filters |
|
|
140
|
-
| `get-entry` | Full record with data, labels, relations, history |
|
|
141
|
-
| `smart-capture` | One-call entry creation with auto-linking and quality scoring |
|
|
142
|
-
| `create-entry` | Create with full field control |
|
|
143
|
-
| `update-entry` | Partial update (merges with existing data) |
|
|
144
|
-
| `gather-context` | Multi-hop graph traversal around an entry |
|
|
145
|
-
| `suggest-links` | Discover potential connections |
|
|
146
|
-
| `relate-entries` | Create typed relations between entries |
|
|
147
|
-
| `find-related` | List direct relations for an entry |
|
|
148
|
-
| `quality-check` | Score an entry against collection-specific criteria |
|
|
149
|
-
| `review-rules` | Surface business rules for a domain |
|
|
150
|
-
| `verify` | Check knowledge entries against the actual codebase |
|
|
151
|
-
| `list-labels` | Browse workspace labels |
|
|
152
|
-
| `manage-labels` | Create, update, or delete labels |
|
|
153
|
-
| `label-entry` | Apply or remove labels from entries |
|
|
154
|
-
| `quick-capture` | Minimal-ceremony entry creation |
|
|
155
|
-
| `mcp-audit` | Session audit log with call statistics |
|
|
156
|
-
|
|
157
|
-
## Resources
|
|
158
|
-
|
|
159
|
-
| URI | Content |
|
|
160
|
-
|-----|---------|
|
|
161
|
-
| `productbrain://orientation` | System map: architecture, data model, rules, analytics |
|
|
162
|
-
| `productbrain://terminology` | Glossary + standards summary |
|
|
163
|
-
| `productbrain://collections` | All collection schemas with field definitions |
|
|
164
|
-
| `productbrain://{slug}/entries` | All entries in a given collection |
|
|
165
|
-
| `productbrain://labels` | Workspace labels with hierarchy |
|
|
166
|
-
|
|
167
|
-
## Prompts
|
|
168
|
-
|
|
169
|
-
| Prompt | Purpose |
|
|
170
|
-
|--------|---------|
|
|
171
|
-
| `review-against-rules` | Structured compliance review against business rules |
|
|
172
|
-
| `name-check` | Check variable/field names against the glossary |
|
|
173
|
-
| `draft-decision-record` | Draft a decision record from context |
|
|
174
|
-
| `draft-rule-from-context` | Draft a business rule from an observation |
|
|
175
|
-
|
|
176
|
-
## Security
|
|
177
|
-
|
|
178
|
-
- **Your data stays yours.** The MCP server connects only to your authenticated Convex deployment. No data is shared with third parties.
|
|
179
|
-
- **API key handling.** Cloud keys (`pb_sk_...`) are SHA-256 hashed before storage. Only the prefix is persisted for display. Keys are sent as Bearer tokens over HTTPS.
|
|
180
|
-
- **Workspace scoping.** Each API key is bound to a single workspace. No cross-workspace access is possible.
|
|
181
|
-
- **Analytics are opt-in.** Set `POSTHOG_MCP_KEY` to enable usage analytics. Omit it entirely to disable all tracking.
|
|
182
|
-
|
|
183
|
-
## Troubleshooting
|
|
184
|
-
|
|
185
|
-
### "Missing API key" or "Invalid API key"
|
|
186
|
-
|
|
187
|
-
Your `PRODUCTBRAIN_API_KEY` is missing or incorrect. Generate a new key from SynergyOS Settings → API Keys.
|
|
188
|
-
|
|
189
|
-
### "CONVEX_SITE_URL environment variable is required"
|
|
190
|
-
|
|
191
|
-
You're using self-hosted mode but missing the `env` block. Make sure all three variables are set.
|
|
192
|
-
|
|
193
|
-
### "Workspace not found"
|
|
194
|
-
|
|
195
|
-
For self-hosted: check your `WORKSPACE_SLUG`. For cloud: your API key may have been revoked.
|
|
196
|
-
|
|
197
|
-
### "MCP call network error"
|
|
198
|
-
|
|
199
|
-
The backend is unreachable. If using `PRODUCTBRAIN_URL`, verify the URL is correct and the server is running.
|
|
200
|
-
|
|
201
|
-
### Server doesn't appear in Claude Desktop / Cursor
|
|
202
|
-
|
|
203
|
-
Restart the application after editing the config file. In Cursor, check the MCP panel (Cmd+Shift+P → "MCP: Show Panel") for startup errors.
|
|
204
|
-
|
|
205
|
-
### Enable debug logging
|
|
206
|
-
|
|
207
|
-
Set `MCP_DEBUG=1` in your config's `env` block to see audit logs in stderr.
|
|
208
|
-
|
|
209
|
-
## Development
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
# Clone and install
|
|
213
|
-
git clone https://github.com/synergyai-os/productbrain.git
|
|
214
|
-
cd productbrain
|
|
215
|
-
npm install
|
|
216
|
-
|
|
217
|
-
# Copy env template and fill in your values
|
|
218
|
-
cp .env.mcp.example .env.mcp
|
|
219
|
-
|
|
220
|
-
# Run in dev mode (TypeScript, hot reload)
|
|
221
|
-
npm run dev
|
|
222
|
-
|
|
223
|
-
# Build for production
|
|
224
|
-
npm run build
|
|
225
|
-
|
|
226
|
-
# Run the built version
|
|
227
|
-
npm start
|
|
228
|
-
|
|
229
|
-
# Typecheck
|
|
230
|
-
npm run typecheck
|
|
231
|
-
|
|
232
|
-
# Publish beta
|
|
233
|
-
npm run publish:beta
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
## License
|
|
237
|
-
|
|
238
|
-
MIT
|
package/dist/chunk-DGUM43GV.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
__require
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=chunk-DGUM43GV.js.map
|
package/dist/setup-K757L5KR.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
__require
|
|
4
|
-
} from "./chunk-DGUM43GV.js";
|
|
5
|
-
|
|
6
|
-
// src/cli/setup.ts
|
|
7
|
-
import { createInterface } from "readline";
|
|
8
|
-
|
|
9
|
-
// src/cli/config-writer.ts
|
|
10
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
11
|
-
import { join, dirname } from "path";
|
|
12
|
-
import { homedir, platform } from "os";
|
|
13
|
-
var SERVER_ENTRY_KEY = "productbrain";
|
|
14
|
-
function buildServerEntry(apiKey) {
|
|
15
|
-
return {
|
|
16
|
-
command: "npx",
|
|
17
|
-
args: ["-y", "productbrain"],
|
|
18
|
-
env: { PRODUCTBRAIN_API_KEY: apiKey }
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function getCursorConfigPath() {
|
|
22
|
-
return join(process.cwd(), ".cursor", "mcp.json");
|
|
23
|
-
}
|
|
24
|
-
function getClaudeDesktopConfigPath() {
|
|
25
|
-
const os = platform();
|
|
26
|
-
if (os === "darwin") {
|
|
27
|
-
return join(
|
|
28
|
-
homedir(),
|
|
29
|
-
"Library",
|
|
30
|
-
"Application Support",
|
|
31
|
-
"Claude",
|
|
32
|
-
"claude_desktop_config.json"
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
if (os === "win32") {
|
|
36
|
-
const appData = process.env.APPDATA ?? join(homedir(), "AppData", "Roaming");
|
|
37
|
-
return join(appData, "Claude", "claude_desktop_config.json");
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
function isCursorProject() {
|
|
42
|
-
return existsSync(join(process.cwd(), ".cursor")) || existsSync(join(process.cwd(), ".cursorignore"));
|
|
43
|
-
}
|
|
44
|
-
function isClaudeDesktopInstalled() {
|
|
45
|
-
const configPath = getClaudeDesktopConfigPath();
|
|
46
|
-
if (!configPath) return false;
|
|
47
|
-
return existsSync(dirname(configPath));
|
|
48
|
-
}
|
|
49
|
-
function detectClients() {
|
|
50
|
-
const clients = [];
|
|
51
|
-
if (isCursorProject()) {
|
|
52
|
-
clients.push({ name: "Cursor", configPath: getCursorConfigPath() });
|
|
53
|
-
}
|
|
54
|
-
if (isClaudeDesktopInstalled()) {
|
|
55
|
-
clients.push({
|
|
56
|
-
name: "Claude Desktop",
|
|
57
|
-
configPath: getClaudeDesktopConfigPath()
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return clients;
|
|
61
|
-
}
|
|
62
|
-
function readJsonSafe(path) {
|
|
63
|
-
if (!existsSync(path)) return {};
|
|
64
|
-
try {
|
|
65
|
-
return JSON.parse(readFileSync(path, "utf-8"));
|
|
66
|
-
} catch {
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async function writeClientConfig(client, apiKey) {
|
|
71
|
-
const config = readJsonSafe(client.configPath);
|
|
72
|
-
const serversKey = "mcpServers";
|
|
73
|
-
if (!config[serversKey]) config[serversKey] = {};
|
|
74
|
-
if (config[serversKey][SERVER_ENTRY_KEY]) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
config[serversKey][SERVER_ENTRY_KEY] = buildServerEntry(apiKey);
|
|
78
|
-
const dir = dirname(client.configPath);
|
|
79
|
-
if (!existsSync(dir)) {
|
|
80
|
-
mkdirSync(dir, { recursive: true });
|
|
81
|
-
}
|
|
82
|
-
writeFileSync(client.configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/cli/setup.ts
|
|
87
|
-
var SYNERGYOS_APP_URL = process.env.SYNERGYOS_APP_URL ?? process.env.PRODUCTBRAIN_APP_URL ?? "http://localhost:5173";
|
|
88
|
-
function bold(s) {
|
|
89
|
-
return `\x1B[1m${s}\x1B[0m`;
|
|
90
|
-
}
|
|
91
|
-
function green(s) {
|
|
92
|
-
return `\x1B[32m${s}\x1B[0m`;
|
|
93
|
-
}
|
|
94
|
-
function dim(s) {
|
|
95
|
-
return `\x1B[2m${s}\x1B[0m`;
|
|
96
|
-
}
|
|
97
|
-
function orange(s) {
|
|
98
|
-
return `\x1B[33m${s}\x1B[0m`;
|
|
99
|
-
}
|
|
100
|
-
function log(msg) {
|
|
101
|
-
process.stdout.write(`${msg}
|
|
102
|
-
`);
|
|
103
|
-
}
|
|
104
|
-
function openBrowser(url) {
|
|
105
|
-
const { execSync } = __require("child_process");
|
|
106
|
-
const platform2 = process.platform;
|
|
107
|
-
try {
|
|
108
|
-
if (platform2 === "darwin") execSync(`open "${url}"`);
|
|
109
|
-
else if (platform2 === "win32") execSync(`start "" "${url}"`);
|
|
110
|
-
else execSync(`xdg-open "${url}"`);
|
|
111
|
-
} catch {
|
|
112
|
-
log(dim(` Could not open browser automatically.`));
|
|
113
|
-
log(` Open this URL manually: ${url}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function prompt(question) {
|
|
117
|
-
return new Promise((resolve) => {
|
|
118
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
119
|
-
rl.question(question, (answer) => {
|
|
120
|
-
rl.close();
|
|
121
|
-
resolve(answer.trim());
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function promptChoice(question, choices) {
|
|
126
|
-
return new Promise((resolve) => {
|
|
127
|
-
log("");
|
|
128
|
-
log(bold(question));
|
|
129
|
-
choices.forEach((c, i) => log(` ${i + 1}) ${c}`));
|
|
130
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
131
|
-
rl.question(`
|
|
132
|
-
${dim("Choice [1]:")} `, (line) => {
|
|
133
|
-
rl.close();
|
|
134
|
-
const n = parseInt(line.trim(), 10);
|
|
135
|
-
if (isNaN(n) || n < 1 || n > choices.length) {
|
|
136
|
-
resolve(0);
|
|
137
|
-
} else {
|
|
138
|
-
resolve(n - 1);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
async function runSetup() {
|
|
144
|
-
log("");
|
|
145
|
-
log(bold(` Product${orange("Brain")} Setup`));
|
|
146
|
-
log(dim(" Connect your AI assistant to your knowledge base\n"));
|
|
147
|
-
const apiKeysUrl = `${SYNERGYOS_APP_URL}/settings/api-keys`;
|
|
148
|
-
log(` ${dim("1. Get your API key from SynergyOS")}`);
|
|
149
|
-
log(` ${dim(apiKeysUrl)}
|
|
150
|
-
`);
|
|
151
|
-
const openNow = await prompt(` Open this URL in your browser? [Y/n]: `);
|
|
152
|
-
if (openNow.toLowerCase() !== "n" && openNow.toLowerCase() !== "no") {
|
|
153
|
-
openBrowser(apiKeysUrl);
|
|
154
|
-
}
|
|
155
|
-
log("");
|
|
156
|
-
log(` ${dim("2. Generate a key (if you don't have one), then copy it.\n")}`);
|
|
157
|
-
const apiKey = await prompt(` Paste your API key (pb_sk_...): `);
|
|
158
|
-
if (!apiKey || !apiKey.startsWith("pb_sk_")) {
|
|
159
|
-
log(` ${orange("!")} Invalid key format. Keys start with pb_sk_.`);
|
|
160
|
-
log(` Get one at ${apiKeysUrl}
|
|
161
|
-
`);
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
log(` ${green("\u2713")} Key received
|
|
165
|
-
`);
|
|
166
|
-
const clients = detectClients();
|
|
167
|
-
if (clients.length === 0) {
|
|
168
|
-
log(bold(" No supported MCP clients detected.\n"));
|
|
169
|
-
printConfigSnippet(apiKey);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const clientNames = clients.map((c) => c.name);
|
|
173
|
-
const allOption = clients.length > 1 ? [...clientNames, "All of the above", "Just show me the config"] : [...clientNames, "Just show me the config"];
|
|
174
|
-
const choice = await promptChoice("Which AI assistant should I configure?", allOption);
|
|
175
|
-
if (choice === allOption.length - 1) {
|
|
176
|
-
printConfigSnippet(apiKey);
|
|
177
|
-
} else if (clients.length > 1 && choice === allOption.length - 2) {
|
|
178
|
-
for (const client of clients) {
|
|
179
|
-
await writeConfig(client, apiKey);
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
await writeConfig(clients[choice], apiKey);
|
|
183
|
-
}
|
|
184
|
-
log("");
|
|
185
|
-
log(
|
|
186
|
-
` ${green("\u2713")} Done! Restart your AI assistant and try: ${bold('"Use the health tool"')}`
|
|
187
|
-
);
|
|
188
|
-
log("");
|
|
189
|
-
}
|
|
190
|
-
async function writeConfig(client, apiKey) {
|
|
191
|
-
try {
|
|
192
|
-
const wrote = await writeClientConfig(client, apiKey);
|
|
193
|
-
if (wrote) {
|
|
194
|
-
log(` ${green("\u2713")} Wrote config to ${dim(client.configPath)}`);
|
|
195
|
-
} else {
|
|
196
|
-
log(` ${dim("\u2139")} ${client.name} already configured \u2014 skipped`);
|
|
197
|
-
}
|
|
198
|
-
} catch (err) {
|
|
199
|
-
log(` ${orange("!")} Could not write ${client.name} config: ${err.message}`);
|
|
200
|
-
printConfigSnippet(apiKey);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function printConfigSnippet(apiKey) {
|
|
204
|
-
log("");
|
|
205
|
-
log(bold(" Add this to your MCP client config:\n"));
|
|
206
|
-
const snippet = JSON.stringify(
|
|
207
|
-
{
|
|
208
|
-
mcpServers: {
|
|
209
|
-
productbrain: {
|
|
210
|
-
command: "npx",
|
|
211
|
-
args: ["-y", "productbrain"],
|
|
212
|
-
env: { PRODUCTBRAIN_API_KEY: apiKey }
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
null,
|
|
217
|
-
2
|
|
218
|
-
);
|
|
219
|
-
for (const line of snippet.split("\n")) {
|
|
220
|
-
log(` ${line}`);
|
|
221
|
-
}
|
|
222
|
-
log("");
|
|
223
|
-
}
|
|
224
|
-
export {
|
|
225
|
-
runSetup
|
|
226
|
-
};
|
|
227
|
-
//# sourceMappingURL=setup-K757L5KR.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/setup.ts","../src/cli/config-writer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * `npx productbrain setup`\n *\n * Guided onboarding: get API key from SynergyOS, paste it, and write MCP config.\n * No GitHub — keys come from SynergyOS → Settings → API Keys.\n */\n\nimport { createInterface } from \"node:readline\";\nimport { detectClients, writeClientConfig, type McpClientInfo } from \"./config-writer.js\";\n\nconst SYNERGYOS_APP_URL =\n process.env.SYNERGYOS_APP_URL ?? process.env.PRODUCTBRAIN_APP_URL ?? \"http://localhost:5173\";\n\n// ── Helpers ─────────────────────────────────────────────────────────────\n\nfunction bold(s: string) {\n return `\\x1b[1m${s}\\x1b[0m`;\n}\nfunction green(s: string) {\n return `\\x1b[32m${s}\\x1b[0m`;\n}\nfunction dim(s: string) {\n return `\\x1b[2m${s}\\x1b[0m`;\n}\nfunction orange(s: string) {\n return `\\x1b[33m${s}\\x1b[0m`;\n}\n\nfunction log(msg: string) {\n process.stdout.write(`${msg}\\n`);\n}\n\nfunction openBrowser(url: string) {\n const { execSync } = require(\"node:child_process\") as typeof import(\"node:child_process\");\n const platform = process.platform;\n try {\n if (platform === \"darwin\") execSync(`open \"${url}\"`);\n else if (platform === \"win32\") execSync(`start \"\" \"${url}\"`);\n else execSync(`xdg-open \"${url}\"`);\n } catch {\n log(dim(` Could not open browser automatically.`));\n log(` Open this URL manually: ${url}`);\n }\n}\n\nfunction prompt(question: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n rl.question(question, (answer) => {\n rl.close();\n resolve(answer.trim());\n });\n });\n}\n\nfunction promptChoice(question: string, choices: string[]): Promise<number> {\n return new Promise((resolve) => {\n log(\"\");\n log(bold(question));\n choices.forEach((c, i) => log(` ${i + 1}) ${c}`));\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n rl.question(`\\n ${dim(\"Choice [1]:\")} `, (line) => {\n rl.close();\n const n = parseInt(line.trim(), 10);\n if (isNaN(n) || n < 1 || n > choices.length) {\n resolve(0);\n } else {\n resolve(n - 1);\n }\n });\n });\n}\n\n// ── Main ────────────────────────────────────────────────────────────────\n\nexport async function runSetup() {\n log(\"\");\n log(bold(` Product${orange(\"Brain\")} Setup`));\n log(dim(\" Connect your AI assistant to your knowledge base\\n\"));\n\n const apiKeysUrl = `${SYNERGYOS_APP_URL}/settings/api-keys`;\n\n log(` ${dim(\"1. Get your API key from SynergyOS\")}`);\n log(` ${dim(apiKeysUrl)}\\n`);\n\n const openNow = await prompt(` Open this URL in your browser? [Y/n]: `);\n if (openNow.toLowerCase() !== \"n\" && openNow.toLowerCase() !== \"no\") {\n openBrowser(apiKeysUrl);\n }\n\n log(\"\");\n log(` ${dim(\"2. Generate a key (if you don't have one), then copy it.\\n\")}`);\n\n const apiKey = await prompt(` Paste your API key (pb_sk_...): `);\n\n if (!apiKey || !apiKey.startsWith(\"pb_sk_\")) {\n log(` ${orange(\"!\")} Invalid key format. Keys start with pb_sk_.`);\n log(` Get one at ${apiKeysUrl}\\n`);\n process.exit(1);\n }\n\n log(` ${green(\"✓\")} Key received\\n`);\n\n // 3. Detect MCP clients and write config\n const clients = detectClients();\n\n if (clients.length === 0) {\n log(bold(\" No supported MCP clients detected.\\n\"));\n printConfigSnippet(apiKey);\n return;\n }\n\n const clientNames = clients.map((c) => c.name);\n const allOption =\n clients.length > 1\n ? [...clientNames, \"All of the above\", \"Just show me the config\"]\n : [...clientNames, \"Just show me the config\"];\n\n const choice = await promptChoice(\"Which AI assistant should I configure?\", allOption);\n\n if (choice === allOption.length - 1) {\n printConfigSnippet(apiKey);\n } else if (clients.length > 1 && choice === allOption.length - 2) {\n for (const client of clients) {\n await writeConfig(client, apiKey);\n }\n } else {\n await writeConfig(clients[choice], apiKey);\n }\n\n log(\"\");\n log(\n ` ${green(\"✓\")} Done! Restart your AI assistant and try: ${bold('\"Use the health tool\"')}`,\n );\n log(\"\");\n}\n\nasync function writeConfig(client: McpClientInfo, apiKey: string) {\n try {\n const wrote = await writeClientConfig(client, apiKey);\n if (wrote) {\n log(` ${green(\"✓\")} Wrote config to ${dim(client.configPath)}`);\n } else {\n log(` ${dim(\"ℹ\")} ${client.name} already configured — skipped`);\n }\n } catch (err: any) {\n log(` ${orange(\"!\")} Could not write ${client.name} config: ${err.message}`);\n printConfigSnippet(apiKey);\n }\n}\n\nfunction printConfigSnippet(apiKey: string) {\n log(\"\");\n log(bold(\" Add this to your MCP client config:\\n\"));\n const snippet = JSON.stringify(\n {\n mcpServers: {\n productbrain: {\n command: \"npx\",\n args: [\"-y\", \"productbrain\"],\n env: { PRODUCTBRAIN_API_KEY: apiKey },\n },\n },\n },\n null,\n 2,\n );\n for (const line of snippet.split(\"\\n\")) {\n log(` ${line}`);\n }\n log(\"\");\n}\n","/**\n * Multi-client MCP config detection and writer.\n *\n * Supports:\n * - Cursor: .cursor/mcp.json in cwd (project-level)\n * - Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)\n * %APPDATA%/Claude/claude_desktop_config.json (Windows)\n *\n * The writer reads existing config, merges the new server entry (never\n * overwrites existing entries), and writes back. Falls back to printing\n * a snippet for unsupported OS or unknown formats.\n */\n\nimport { existsSync, readFileSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { join, dirname } from \"node:path\";\nimport { homedir, platform } from \"node:os\";\n\nexport interface McpClientInfo {\n name: string;\n configPath: string;\n}\n\nconst SERVER_ENTRY_KEY = \"productbrain\";\n\nfunction buildServerEntry(apiKey: string) {\n return {\n command: \"npx\",\n args: [\"-y\", \"productbrain\"],\n env: { PRODUCTBRAIN_API_KEY: apiKey },\n };\n}\n\n// ── Detection ───────────────────────────────────────────────────────────\n\nfunction getCursorConfigPath(): string {\n return join(process.cwd(), \".cursor\", \"mcp.json\");\n}\n\nfunction getClaudeDesktopConfigPath(): string | null {\n const os = platform();\n if (os === \"darwin\") {\n return join(\n homedir(),\n \"Library\",\n \"Application Support\",\n \"Claude\",\n \"claude_desktop_config.json\",\n );\n }\n if (os === \"win32\") {\n const appData = process.env.APPDATA ?? join(homedir(), \"AppData\", \"Roaming\");\n return join(appData, \"Claude\", \"claude_desktop_config.json\");\n }\n // Linux: no official Claude Desktop location yet\n return null;\n}\n\nfunction isCursorProject(): boolean {\n return existsSync(join(process.cwd(), \".cursor\")) || existsSync(join(process.cwd(), \".cursorignore\"));\n}\n\nfunction isClaudeDesktopInstalled(): boolean {\n const configPath = getClaudeDesktopConfigPath();\n if (!configPath) return false;\n // Check if the Claude directory exists (config file may not exist yet)\n return existsSync(dirname(configPath));\n}\n\nexport function detectClients(): McpClientInfo[] {\n const clients: McpClientInfo[] = [];\n\n if (isCursorProject()) {\n clients.push({ name: \"Cursor\", configPath: getCursorConfigPath() });\n }\n\n if (isClaudeDesktopInstalled()) {\n clients.push({\n name: \"Claude Desktop\",\n configPath: getClaudeDesktopConfigPath()!,\n });\n }\n\n return clients;\n}\n\n// ── Writing ─────────────────────────────────────────────────────────────\n\nfunction readJsonSafe(path: string): Record<string, any> {\n if (!existsSync(path)) return {};\n try {\n return JSON.parse(readFileSync(path, \"utf-8\"));\n } catch {\n return {};\n }\n}\n\n/**\n * Write or merge the productbrain server entry into a client config file.\n * Returns true if the config was written, false if already present.\n */\nexport async function writeClientConfig(\n client: McpClientInfo,\n apiKey: string,\n): Promise<boolean> {\n const config = readJsonSafe(client.configPath);\n\n const serversKey = \"mcpServers\";\n if (!config[serversKey]) config[serversKey] = {};\n\n // Don't overwrite an existing productbrain entry\n if (config[serversKey][SERVER_ENTRY_KEY]) {\n return false;\n }\n\n config[serversKey][SERVER_ENTRY_KEY] = buildServerEntry(apiKey);\n\n const dir = dirname(client.configPath);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n writeFileSync(client.configPath, JSON.stringify(config, null, 2) + \"\\n\", \"utf-8\");\n return true;\n}\n"],"mappings":";;;;;;AASA,SAAS,uBAAuB;;;ACIhC,SAAS,YAAY,cAAc,eAAe,iBAAiB;AACnE,SAA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