screenpipe-mcp 0.16.1 → 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.
Files changed (3) hide show
  1. package/dist/index.js +30 -11
  2. package/package.json +1 -1
  3. package/src/index.ts +28 -10
package/dist/index.js CHANGED
@@ -53,25 +53,44 @@ 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 via process.execPath > npx on PATH
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
- const { execFileSync, execSync } = require("child_process");
61
+ const os = require("os");
62
62
  const path = require("path");
63
- // Use the screenpipe npm package's JS API — resolves the bundled native
64
- // binary directly, no PATH dependency, no subprocess spawning of npx.
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.
65
68
  try {
66
- const { getApiKey } = require("screenpipe");
67
- const token = getApiKey();
68
- if (token)
69
- return token;
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
+ }
70
91
  }
71
92
  catch { }
72
- // Fallback: use the current Node binary to run npx (no PATH dependency).
73
- // Claude Code and other MCP hosts may strip PATH, making bare `npx` unfindable.
74
- // process.execPath is the absolute path to the Node binary running this MCP.
93
+ // Fallback: use the current Node binary to find npx (no PATH dependency)
75
94
  try {
76
95
  const npxPath = path.join(path.dirname(process.execPath), "npx");
77
96
  const token = execFileSync(npxPath, ["screenpipe@latest", "auth", "token"], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenpipe-mcp",
3
- "version": "0.16.1",
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,25 +28,43 @@ 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 via process.execPath > npx on PATH
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
- const { execFileSync, execSync } = require("child_process");
36
+ const os = require("os");
37
37
  const path = require("path");
38
+ const fs = require("fs");
39
+ const { execFileSync, execSync } = require("child_process");
38
40
 
39
- // Use the screenpipe npm package's JS API — resolves the bundled native
40
- // binary directly, no PATH dependency, no subprocess spawning of npx.
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.
41
44
  try {
42
- const { getApiKey } = require("screenpipe");
43
- const token = getApiKey();
44
- if (token) return token;
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
+ }
45
65
  } catch {}
46
66
 
47
- // Fallback: use the current Node binary to run npx (no PATH dependency).
48
- // Claude Code and other MCP hosts may strip PATH, making bare `npx` unfindable.
49
- // process.execPath is the absolute path to the Node binary running this MCP.
67
+ // Fallback: use the current Node binary to find npx (no PATH dependency)
50
68
  try {
51
69
  const npxPath = path.join(path.dirname(process.execPath), "npx");
52
70
  const token = execFileSync(npxPath, ["screenpipe@latest", "auth", "token"], {