screenpipe-mcp 0.16.0 → 0.16.2

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/dist/index.js CHANGED
@@ -53,23 +53,57 @@ for (let i = 0; i < args.length; i++) {
53
53
  }
54
54
  }
55
55
  const SCREENPIPE_API = `http://localhost:${port}`;
56
- // Discover API key: env var > screenpipe JS lib > npx fallback
56
+ // Discover API key: env var > db.sqlite direct read > npx fallbacks
57
57
  function discoverApiKey() {
58
58
  const envKey = process.env.SCREENPIPE_LOCAL_API_KEY || process.env.SCREENPIPE_API_KEY;
59
59
  if (envKey)
60
60
  return envKey;
61
- // Use the screenpipe npm package's JS API — resolves the bundled native
62
- // binary directly, no PATH dependency, no subprocess spawning of npx.
61
+ const os = require("os");
62
+ const path = require("path");
63
+ const fs = require("fs");
64
+ const { execFileSync, execSync } = require("child_process");
65
+ // Read api_auth_key directly from ~/.screenpipe/db.sqlite.
66
+ // The local API key is stored as base64 plaintext (nonce=zeros, not encrypted).
67
+ // This is the most reliable method — no PATH, no subprocess, no keychain.
63
68
  try {
64
- const { getApiKey } = require("screenpipe");
65
- const token = getApiKey();
69
+ const dbPath = path.join(os.homedir(), ".screenpipe", "db.sqlite");
70
+ if (fs.existsSync(dbPath)) {
71
+ // Use sqlite3 CLI which is pre-installed on macOS/Linux
72
+ const sqliteBin = process.platform === "win32" ? "sqlite3.exe" : "sqlite3";
73
+ const result = execFileSync(sqliteBin, [
74
+ dbPath,
75
+ "SELECT value FROM secrets WHERE key = 'api_auth_key';",
76
+ ], {
77
+ timeout: 5000,
78
+ encoding: "utf-8",
79
+ stdio: ["pipe", "pipe", "pipe"],
80
+ }).trim();
81
+ if (result) {
82
+ // Value is base64-encoded — decode it
83
+ const decoded = Buffer.from(result, "base64").toString("utf-8");
84
+ if (decoded && decoded.startsWith("sp-"))
85
+ return decoded;
86
+ // If not base64 or not sp- prefixed, use raw value
87
+ if (result.startsWith("sp-"))
88
+ return result;
89
+ }
90
+ }
91
+ }
92
+ catch { }
93
+ // Fallback: use the current Node binary to find npx (no PATH dependency)
94
+ try {
95
+ const npxPath = path.join(path.dirname(process.execPath), "npx");
96
+ const token = execFileSync(npxPath, ["screenpipe@latest", "auth", "token"], {
97
+ timeout: 15000,
98
+ encoding: "utf-8",
99
+ stdio: ["pipe", "pipe", "pipe"],
100
+ }).trim();
66
101
  if (token)
67
102
  return token;
68
103
  }
69
104
  catch { }
70
- // Fallback: shell out to npx (works when screenpipe pkg isn't installed as dependency)
105
+ // Last resort: npx on PATH
71
106
  try {
72
- const { execSync } = require("child_process");
73
107
  const token = execSync("npx screenpipe@latest auth token", {
74
108
  timeout: 15000,
75
109
  encoding: "utf-8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenpipe-mcp",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "description": "MCP server for screenpipe - search your screen recordings and audio transcriptions",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -28,22 +28,55 @@ for (let i = 0; i < args.length; i++) {
28
28
 
29
29
  const SCREENPIPE_API = `http://localhost:${port}`;
30
30
 
31
- // Discover API key: env var > screenpipe JS lib > npx fallback
31
+ // Discover API key: env var > db.sqlite direct read > npx fallbacks
32
32
  function discoverApiKey(): string {
33
33
  const envKey = process.env.SCREENPIPE_LOCAL_API_KEY || process.env.SCREENPIPE_API_KEY;
34
34
  if (envKey) return envKey;
35
35
 
36
- // Use the screenpipe npm package's JS API — resolves the bundled native
37
- // binary directly, no PATH dependency, no subprocess spawning of npx.
36
+ const os = require("os");
37
+ const path = require("path");
38
+ const fs = require("fs");
39
+ const { execFileSync, execSync } = require("child_process");
40
+
41
+ // Read api_auth_key directly from ~/.screenpipe/db.sqlite.
42
+ // The local API key is stored as base64 plaintext (nonce=zeros, not encrypted).
43
+ // This is the most reliable method — no PATH, no subprocess, no keychain.
44
+ try {
45
+ const dbPath = path.join(os.homedir(), ".screenpipe", "db.sqlite");
46
+ if (fs.existsSync(dbPath)) {
47
+ // Use sqlite3 CLI which is pre-installed on macOS/Linux
48
+ const sqliteBin = process.platform === "win32" ? "sqlite3.exe" : "sqlite3";
49
+ const result = execFileSync(sqliteBin, [
50
+ dbPath,
51
+ "SELECT value FROM secrets WHERE key = 'api_auth_key';",
52
+ ], {
53
+ timeout: 5000,
54
+ encoding: "utf-8",
55
+ stdio: ["pipe", "pipe", "pipe"],
56
+ }).trim();
57
+ if (result) {
58
+ // Value is base64-encoded — decode it
59
+ const decoded = Buffer.from(result, "base64").toString("utf-8");
60
+ if (decoded && decoded.startsWith("sp-")) return decoded;
61
+ // If not base64 or not sp- prefixed, use raw value
62
+ if (result.startsWith("sp-")) return result;
63
+ }
64
+ }
65
+ } catch {}
66
+
67
+ // Fallback: use the current Node binary to find npx (no PATH dependency)
38
68
  try {
39
- const { getApiKey } = require("screenpipe");
40
- const token = getApiKey();
69
+ const npxPath = path.join(path.dirname(process.execPath), "npx");
70
+ const token = execFileSync(npxPath, ["screenpipe@latest", "auth", "token"], {
71
+ timeout: 15000,
72
+ encoding: "utf-8",
73
+ stdio: ["pipe", "pipe", "pipe"],
74
+ }).trim();
41
75
  if (token) return token;
42
76
  } catch {}
43
77
 
44
- // Fallback: shell out to npx (works when screenpipe pkg isn't installed as dependency)
78
+ // Last resort: npx on PATH
45
79
  try {
46
- const { execSync } = require("child_process");
47
80
  const token = execSync("npx screenpipe@latest auth token", {
48
81
  timeout: 15000,
49
82
  encoding: "utf-8",