filebread-mcp 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/cli.js +107 -7
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -14,14 +14,17 @@ if (!command || command === "help" || command === "--help") {
14
14
  filebread - Give AI agents context about your project
15
15
 
16
16
  Commands:
17
- init Set up FileBread in the current project (creates .mcp.json)
18
- status Check connection and indexed sources
19
- upload Upload a file to your knowledge base
17
+ init Set up FileBread in the current project
18
+ connect <source> Connect a knowledge source (github, notion, slack, gdrive)
19
+ status Check connection and indexed sources
20
+ upload <file> Upload a file to your knowledge base
20
21
 
21
22
  Usage:
22
- npx filebread init
23
- npx filebread status
24
- npx filebread upload ./docs/architecture.md
23
+ npx filebread-mcp init
24
+ npx filebread-mcp connect github
25
+ npx filebread-mcp connect notion
26
+ npx filebread-mcp status
27
+ npx filebread-mcp upload ./docs/architecture.md
25
28
  `);
26
29
  process.exit(0);
27
30
  }
@@ -334,11 +337,108 @@ async function upload() {
334
337
  }
335
338
  }
336
339
 
340
+ // --- Connect ---
341
+
342
+ async function connect() {
343
+ const provider = process.argv[3];
344
+ const validProviders = ["github", "notion", "slack", "gdrive"];
345
+
346
+ if (!provider || !validProviders.includes(provider)) {
347
+ console.log("\n Usage: npx filebread-mcp connect <source>\n");
348
+ console.log(" Sources:");
349
+ console.log(" github Connect GitHub repositories");
350
+ console.log(" notion Connect Notion workspace");
351
+ console.log(" slack Connect Slack workspace");
352
+ console.log(" gdrive Connect Google Drive\n");
353
+ process.exit(1);
354
+ }
355
+
356
+ // Get API key from .mcp.json or ~/.filebread/config.json
357
+ let apiKey = null;
358
+ const mcpPath = path.join(process.cwd(), ".mcp.json");
359
+ const configPath = path.join(process.env.HOME || process.env.USERPROFILE, ".filebread", "config.json");
360
+
361
+ if (fs.existsSync(mcpPath)) {
362
+ const config = JSON.parse(fs.readFileSync(mcpPath, "utf8"));
363
+ apiKey = config.mcpServers?.filebread?.env?.FILEBREAD_API_KEY;
364
+ }
365
+ if (!apiKey && fs.existsSync(configPath)) {
366
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
367
+ apiKey = config.api_key;
368
+ }
369
+
370
+ if (!apiKey) {
371
+ console.log("\n Run `npx filebread-mcp init` first.\n");
372
+ process.exit(1);
373
+ }
374
+
375
+ const providerNames = { github: "GitHub", notion: "Notion", slack: "Slack", gdrive: "Google Drive" };
376
+ console.log(`\n Connecting ${providerNames[provider]}...\n`);
377
+
378
+ // Get OAuth URL from backend
379
+ const res = await apiRequest("GET", `/api/connect/${provider}/url?api_key=${apiKey}`, null);
380
+
381
+ if (res.status !== 200) {
382
+ console.log(` Error: ${res.body?.error || "Failed to get authorization URL"}`);
383
+ process.exit(1);
384
+ }
385
+
386
+ const { url } = res.body;
387
+
388
+ console.log(" Opening browser for authorization...\n");
389
+
390
+ // Open browser
391
+ const { exec } = require("child_process");
392
+ const openCmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
393
+ exec(`${openCmd} "${url}"`);
394
+
395
+ console.log(" Waiting for authorization...");
396
+ console.log(" (If browser didn't open, visit this URL:)");
397
+ console.log(` ${url}\n`);
398
+
399
+ // Poll for connection status
400
+ let connected = false;
401
+ const startAccounts = await getConnectedProviders(apiKey);
402
+
403
+ for (let i = 0; i < 60; i++) {
404
+ await new Promise((r) => setTimeout(r, 3000));
405
+ const current = await getConnectedProviders(apiKey);
406
+
407
+ // Check if a new account was added for this provider
408
+ const newAccount = current.find(
409
+ (a) => a.provider === (provider === "gdrive" ? "google_drive" : provider) &&
410
+ !startAccounts.find((s) => s.id === a.id)
411
+ );
412
+
413
+ if (newAccount) {
414
+ connected = true;
415
+ console.log(` Connected to ${providerNames[provider]}!`);
416
+ console.log(" Syncing files in the background...\n");
417
+ console.log(" Run `npx filebread-mcp status` to check progress.\n");
418
+ break;
419
+ }
420
+
421
+ process.stdout.write(".");
422
+ }
423
+
424
+ if (!connected) {
425
+ console.log("\n Timed out waiting for authorization.");
426
+ console.log(" Please try again.\n");
427
+ process.exit(1);
428
+ }
429
+ }
430
+
431
+ async function getConnectedProviders(apiKey) {
432
+ const res = await apiRequest("GET", `/api/connect/status?api_key=${apiKey}`, null);
433
+ return res.status === 200 ? res.body.connected || [] : [];
434
+ }
435
+
337
436
  // --- Run ---
338
437
 
339
438
  switch (command) {
340
439
  case "init": init().catch((e) => { console.error(` Error: ${e.message}`); process.exit(1); }); break;
440
+ case "connect": connect().catch((e) => { console.error(` Error: ${e.message}`); process.exit(1); }); break;
341
441
  case "status": status().catch((e) => { console.error(` Error: ${e.message}`); process.exit(1); }); break;
342
442
  case "upload": upload().catch((e) => { console.error(` Error: ${e.message}`); process.exit(1); }); break;
343
- default: console.log(` Unknown command: ${command}. Run 'npx filebread help' for usage.`); process.exit(1);
443
+ default: console.log(` Unknown command: ${command}. Run 'npx filebread-mcp help' for usage.`); process.exit(1);
344
444
  }
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // If called with a subcommand (init, status, upload, help), run the CLI instead
4
4
  const subcommand = process.argv[2];
5
- if (subcommand && ["init", "status", "upload", "help", "--help"].includes(subcommand)) {
5
+ if (subcommand && ["init", "connect", "status", "upload", "help", "--help"].includes(subcommand)) {
6
6
  require("./cli.js");
7
7
  process.exitCode = undefined; // let cli.js handle exit
8
8
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filebread-mcp",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Give AI agents context about your project. One command setup.",
5
5
  "bin": {
6
6
  "filebread-mcp": "./index.js",