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.
- package/dist/index.js +30 -11
- package/package.json +1 -1
- 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 >
|
|
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
|
|
61
|
+
const os = require("os");
|
|
62
62
|
const path = require("path");
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
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
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 >
|
|
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
|
|
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
|
-
//
|
|
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.
|
|
41
44
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
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"], {
|