screenpipe-mcp 0.20.3 → 0.20.5
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/LICENSE.md +10 -6
- package/README.md +69 -22
- package/dist/cli.js +157 -20
- package/dist/http-server.js +62 -5
- package/dist/index.js +140 -16
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/chat-search-transport.test.ts +63 -0
- package/src/chat-search.test.ts +33 -0
- package/src/chat-search.ts +32 -0
- package/src/helper-window.test.ts +170 -0
- package/src/http-origin.test.ts +50 -0
- package/src/http-server.test.ts +1 -1
- package/src/http-server.ts +24 -6
- package/src/index.ts +71 -12
- package/src/qualified-value.test.ts +5 -0
- package/src/qualified-value.ts +1 -1
- package/src/result-contracts-transport.test.ts +114 -0
- package/src/result-contracts.test.ts +63 -0
- package/src/result-contracts.ts +62 -0
- package/src/screen-search.test.ts +80 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// screenpipe — AI that knows everything you've seen, said, or heard
|
|
2
|
+
// https://screenpipe.com
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { request } from "node:http";
|
|
5
|
+
import { buildHttpServer } from "./http-server";
|
|
6
|
+
|
|
7
|
+
describe("HTTP MCP browser boundary", () => {
|
|
8
|
+
it("rejects rebinding and cross-origin requests before creating a session", async () => {
|
|
9
|
+
const server = buildHttpServer({ host: "127.0.0.1", mcpPort: 0, screenpipePort: 1 });
|
|
10
|
+
await new Promise<void>(resolve => server.listen(0, "127.0.0.1", resolve));
|
|
11
|
+
const address = server.address();
|
|
12
|
+
if (!address || typeof address === "string") throw Error("no listener");
|
|
13
|
+
const port = address.port;
|
|
14
|
+
const call = (headers: Record<string, string | undefined>, method = "POST", path = "/mcp") => new Promise<{status: number; session?: string; body: string}>((resolve, reject) => {
|
|
15
|
+
const req = request({ hostname: "127.0.0.1", port, method, path, headers: {
|
|
16
|
+
"content-type": "application/json", accept: "application/json, text/event-stream", ...headers,
|
|
17
|
+
} }, res => {
|
|
18
|
+
let body = "";
|
|
19
|
+
res.on("data", chunk => body += chunk);
|
|
20
|
+
res.on("end", () => resolve({status: res.statusCode!, session: res.headers["mcp-session-id"] as string | undefined, body}));
|
|
21
|
+
});
|
|
22
|
+
req.on("error", reject);
|
|
23
|
+
req.end(method === "POST" ? JSON.stringify({jsonrpc:"2.0",id:1,method:"initialize",params:{protocolVersion:"2024-11-05",capabilities:{},clientInfo:{name:"boundary-test",version:"1"}}}) : undefined);
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
for (const headers of [
|
|
27
|
+
{host: `rebind.example:${port}`, origin: `http://rebind.example:${port}`},
|
|
28
|
+
{host: `rebind.example:${port}`},
|
|
29
|
+
{host: `127.0.0.1:${port}`, origin: "https://evil.example"},
|
|
30
|
+
{host: `localhost:${port}`, origin: "null"},
|
|
31
|
+
{host: `localhost.evil.example:${port}`},
|
|
32
|
+
{host: `127.0.0.1:${port}`, origin: "http://localhost@evil.example"},
|
|
33
|
+
]) {
|
|
34
|
+
const result = await call(headers);
|
|
35
|
+
expect(result.status, JSON.stringify(headers)).toBe(401);
|
|
36
|
+
expect(result.session).toBeUndefined();
|
|
37
|
+
}
|
|
38
|
+
const health = await call({host:`127.0.0.1:${port}`}, "GET", "/health");
|
|
39
|
+
expect(JSON.parse(health.body).sessions).toBe(0);
|
|
40
|
+
const native = await call({host:`127.0.0.1:${port}`});
|
|
41
|
+
expect(native.status).toBe(200);
|
|
42
|
+
expect(native.session).toBeTruthy();
|
|
43
|
+
const localBrowser = await call({host:`localhost:${port}`, origin:`http://localhost:${port}`});
|
|
44
|
+
expect(localBrowser.status).toBe(200);
|
|
45
|
+
} finally {
|
|
46
|
+
server.closeAllConnections();
|
|
47
|
+
await new Promise<void>(resolve => server.close(() => resolve()));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
package/src/http-server.test.ts
CHANGED
|
@@ -145,7 +145,7 @@ describe("isAuthorized", () => {
|
|
|
145
145
|
});
|
|
146
146
|
const local = (auth?: string) => ({
|
|
147
147
|
socket: { remoteAddress: "127.0.0.1" },
|
|
148
|
-
headers: auth ? { authorization: auth } : {},
|
|
148
|
+
headers: { host: "127.0.0.1:3031", ...(auth ? { authorization: auth } : {}) },
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
it("allows loopback with no api key", () => {
|
package/src/http-server.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "./telemetry";
|
|
33
33
|
import { createCallObserver, currentMcpRequestId, observeSearchResult } from "./call-observation";
|
|
34
34
|
import { formatSearchHit, searchContentCap, searchResultHeader } from "./search-result";
|
|
35
|
+
import { CHAT_SEARCH_TOOL, searchChats } from "./chat-search";
|
|
35
36
|
import { PKG_VERSION } from "./version";
|
|
36
37
|
import { BUNDLED_SKILLS_TOOL, readBundledSkills } from "./bundled-skills";
|
|
37
38
|
import { normalizeTimeFields } from "./time-normalization";
|
|
@@ -126,22 +127,37 @@ export function isLoopbackRequest(req: { socket: { remoteAddress?: string } }):
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
/**
|
|
129
|
-
* Authorization decision.
|
|
130
|
+
* Authorization decision. Literal loopback hosts with no foreign Origin are allowed; other requests require
|
|
130
131
|
* a matching bearer token when one is configured. If no api key is set
|
|
131
132
|
* (loopback-only deployment), non-loopback shouldn't even be reachable —
|
|
132
133
|
* but we still 401 it as belt-and-suspenders.
|
|
133
134
|
*/
|
|
134
135
|
export function isAuthorized(
|
|
135
|
-
req: { socket: { remoteAddress?: string }; headers: { authorization?: string } },
|
|
136
|
+
req: { socket: { remoteAddress?: string }; headers: { authorization?: string; host?: string; origin?: string } },
|
|
136
137
|
apiKey: string | undefined
|
|
137
138
|
): boolean {
|
|
138
|
-
|
|
139
|
+
// The socket alone is insufficient: a browser can resolve an attacker-owned
|
|
140
|
+
// hostname to loopback, or call localhost with a foreign Origin.
|
|
141
|
+
if (isLoopbackRequest(req) && isTrustedLocalHost(req.headers.host)
|
|
142
|
+
&& (req.headers.origin === undefined || isTrustedLocalOrigin(req.headers.origin))) return true;
|
|
139
143
|
if (!apiKey) return false;
|
|
140
144
|
const expected = `Bearer ${apiKey}`;
|
|
141
145
|
const got = req.headers.authorization ?? "";
|
|
142
146
|
return constantTimeEq(got, expected);
|
|
143
147
|
}
|
|
144
148
|
|
|
149
|
+
function isTrustedLocalHost(host: string | undefined): boolean {
|
|
150
|
+
if (!host) return false;
|
|
151
|
+
// Match the raw authority, not URL-normalized input (userinfo, paths and
|
|
152
|
+
// numeric aliases must not acquire localhost privileges).
|
|
153
|
+
return /^(?:localhost|127\.0\.0\.1|\[::1\])(?::[0-9]{1,5})?$/i.test(host);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isTrustedLocalOrigin(origin: string): boolean {
|
|
157
|
+
const match = /^https?:\/\/([^/?#]+)$/.exec(origin);
|
|
158
|
+
return match !== null && isTrustedLocalHost(match[1]);
|
|
159
|
+
}
|
|
160
|
+
|
|
145
161
|
/** Constant-time string compare to keep timing attacks off the table. */
|
|
146
162
|
function constantTimeEq(a: string, b: string): boolean {
|
|
147
163
|
if (a.length !== b.length) return false;
|
|
@@ -298,19 +314,21 @@ function createMcpServer(screenpipePort: number): Server {
|
|
|
298
314
|
client,
|
|
299
315
|
);
|
|
300
316
|
|
|
301
|
-
s.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...TOOLS, BUNDLED_SKILLS_TOOL] }));
|
|
317
|
+
s.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...TOOLS, CHAT_SEARCH_TOOL, BUNDLED_SKILLS_TOOL] }));
|
|
302
318
|
|
|
303
319
|
const observeCall = createCallObserver({
|
|
304
|
-
tools: [...TOOLS.map(tool => tool.name), BUNDLED_SKILLS_TOOL.name], transport: "http", client,
|
|
320
|
+
tools: [...TOOLS.map(tool => tool.name), CHAT_SEARCH_TOOL.name, BUNDLED_SKILLS_TOOL.name], transport: "http", client,
|
|
305
321
|
send: async (payload, signal) => {
|
|
306
322
|
const response = await fetchAPI("/internal/telemetry/mcp-call", { method: "POST", body: JSON.stringify(payload), signal });
|
|
307
323
|
if (!response.ok) throw new Error("Telemetry unavailable");
|
|
308
324
|
},
|
|
309
325
|
});
|
|
310
326
|
s.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(request.params.name, async () => {
|
|
311
|
-
const { name, arguments:
|
|
327
|
+
const { name, arguments: suppliedArgs } = request.params;
|
|
328
|
+
const args = suppliedArgs ?? (name === CHAT_SEARCH_TOOL.name ? {} : undefined);
|
|
312
329
|
if (name === BUNDLED_SKILLS_TOOL.name) return readBundledSkills(args);
|
|
313
330
|
if (!args) throw Object.assign(new Error("Missing arguments"), { status: 400 });
|
|
331
|
+
if (name === CHAT_SEARCH_TOOL.name) return searchChats(args, fetchAPI);
|
|
314
332
|
if (name === "search_content") return handleSearchContent(fetchAPI, args, qualifiedValue);
|
|
315
333
|
throw Object.assign(new Error(`Unknown tool: ${name}`), { status: 400 });
|
|
316
334
|
}));
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "./qualified-value";
|
|
33
33
|
import { discoverTeamConfig } from "./team-config";
|
|
34
34
|
import { teamFrameContent, teamFramePath } from "./team-frame";
|
|
35
|
+
import { CHAT_SEARCH_TOOL, searchChats } from "./chat-search";
|
|
35
36
|
import { WORKFLOW_TOOLS, readWorkflowTool, frameAutomationContent } from "./workflow-tools";
|
|
36
37
|
import { PKG_VERSION } from "./version";
|
|
37
38
|
import { BUNDLED_SKILLS_TOOL, readBundledSkills } from "./bundled-skills";
|
|
@@ -44,6 +45,11 @@ import {
|
|
|
44
45
|
} from "./time-normalization";
|
|
45
46
|
import { createCallObserver, currentMcpRequestId, observeMcpError, observeSearchResult } from "./call-observation";
|
|
46
47
|
import { formatSearchHit, searchContentCap, searchResultHeader } from "./search-result";
|
|
48
|
+
import {
|
|
49
|
+
normalizeNonNegativeInt,
|
|
50
|
+
normalizePositiveInt,
|
|
51
|
+
zeroHitCoverageText,
|
|
52
|
+
} from "./result-contracts";
|
|
47
53
|
import { resolveScreenpipeApiBase } from "./api-base";
|
|
48
54
|
|
|
49
55
|
initMcpTelemetry({ transport: "stdio" });
|
|
@@ -128,6 +134,11 @@ async function discoverApiKey(): Promise<string> {
|
|
|
128
134
|
// spent we stop attempting further fallbacks.
|
|
129
135
|
const PER_CANDIDATE_MS = 30000;
|
|
130
136
|
const OVERALL_DEADLINE = Date.now() + 60000;
|
|
137
|
+
// Every helper below is a console program run in the background. On Windows,
|
|
138
|
+
// a host that starts this server without a console (e.g. detached) would make
|
|
139
|
+
// each helper open its own visible terminal window (#7560). windowsHide keeps
|
|
140
|
+
// the helper's console hidden whatever console state the host gave us.
|
|
141
|
+
const HIDE_HELPER_WINDOW = { windowsHide: true } as const;
|
|
131
142
|
const budgetLeft = () => Math.max(0, OVERALL_DEADLINE - Date.now());
|
|
132
143
|
|
|
133
144
|
// 2. CLI via bundled `bun` shipped with the desktop app. The Tauri
|
|
@@ -191,6 +202,7 @@ async function discoverApiKey(): Promise<string> {
|
|
|
191
202
|
const { stdout } = await execFileAsync(bunPath, ["x", "screenpipe@latest", "auth", "token"], {
|
|
192
203
|
timeout: Math.min(PER_CANDIDATE_MS, budgetLeft()),
|
|
193
204
|
encoding: "utf-8",
|
|
205
|
+
...HIDE_HELPER_WINDOW,
|
|
194
206
|
});
|
|
195
207
|
const token = String(stdout).trim();
|
|
196
208
|
if (token && token.startsWith("sp-")) return token;
|
|
@@ -208,6 +220,7 @@ async function discoverApiKey(): Promise<string> {
|
|
|
208
220
|
const { stdout } = await execFileAsync(npxPath, ["screenpipe@latest", "auth", "token"], {
|
|
209
221
|
timeout: Math.min(PER_CANDIDATE_MS, budgetLeft()),
|
|
210
222
|
encoding: "utf-8",
|
|
223
|
+
...HIDE_HELPER_WINDOW,
|
|
211
224
|
});
|
|
212
225
|
const token = String(stdout).trim();
|
|
213
226
|
if (token && token.startsWith("sp-")) return token;
|
|
@@ -221,6 +234,7 @@ async function discoverApiKey(): Promise<string> {
|
|
|
221
234
|
const { stdout } = await execAsync("npx screenpipe@latest auth token", {
|
|
222
235
|
timeout: Math.min(PER_CANDIDATE_MS, budgetLeft()),
|
|
223
236
|
encoding: "utf-8",
|
|
237
|
+
...HIDE_HELPER_WINDOW,
|
|
224
238
|
});
|
|
225
239
|
const token = String(stdout).trim();
|
|
226
240
|
if (token && token.startsWith("sp-")) return token;
|
|
@@ -325,6 +339,7 @@ const server = new Server(
|
|
|
325
339
|
// Tools
|
|
326
340
|
// ---------------------------------------------------------------------------
|
|
327
341
|
const TOOLS: Tool[] = [
|
|
342
|
+
CHAT_SEARCH_TOOL,
|
|
328
343
|
...WORKFLOW_TOOLS,
|
|
329
344
|
BUNDLED_SKILLS_TOOL,
|
|
330
345
|
{
|
|
@@ -345,9 +360,9 @@ const TOOLS: Tool[] = [
|
|
|
345
360
|
},
|
|
346
361
|
content_type: {
|
|
347
362
|
type: "string",
|
|
348
|
-
enum: ["all", "ocr", "audio", "input", "accessibility", "memory", "parsed"],
|
|
363
|
+
enum: ["all", "screen", "ocr", "audio", "input", "accessibility", "memory", "parsed"],
|
|
349
364
|
description:
|
|
350
|
-
"Filter by content type. Use '
|
|
365
|
+
"Filter by content type. Use 'screen' for screen text: accessibility is the primary capture path, with OCR fallback. Results identify the actual source as [Screen·a11y] or [Screen·ocr]; [Screen] means the source is unknown. 'ocr' is a legacy alias for 'screen', not an OCR-only filter. Use 'accessibility' only when you explicitly need accessibility-only results; it excludes OCR fallback. Use 'parsed' for compact app-specific messages, emails, tasks, documents, and code review (experimental; may be empty when parsing is disabled or unsupported), 'audio' for transcriptions, 'input' for keyboard/mouse events, 'memory' for stored facts. Default: 'all'.",
|
|
351
366
|
default: "all",
|
|
352
367
|
},
|
|
353
368
|
limit: { type: "integer", description: "Max results (default 10, max 20). Start with 5 for exploration.", default: 10 },
|
|
@@ -370,7 +385,7 @@ const TOOLS: Tool[] = [
|
|
|
370
385
|
max_length: { type: "integer", description: "Max content length in characters" },
|
|
371
386
|
include_frames: {
|
|
372
387
|
type: "boolean",
|
|
373
|
-
description: "Include base64 screenshots
|
|
388
|
+
description: "Include base64 screenshots for screen-text results, including accessibility-derived captures. Warning: large response.",
|
|
374
389
|
default: false,
|
|
375
390
|
},
|
|
376
391
|
speaker_ids: { type: "string", description: "Comma-separated speaker IDs to filter audio" },
|
|
@@ -378,7 +393,7 @@ const TOOLS: Tool[] = [
|
|
|
378
393
|
tags: {
|
|
379
394
|
type: "string",
|
|
380
395
|
description:
|
|
381
|
-
"Comma-separated tags; returns only items carrying ALL of them (e.g. 'person:ada,project:atlas'). Works for screen + audio (content_type 'ocr'/'audio'/'all', tags written by add-tags) AND memories (content_type 'memory', tags written by update-memory). Same tag string links across all three, so two items sharing a tag are connected. Use namespaced tags (person:, project:, topic:) to link people/projects/topics. content_type 'input' and 'accessibility' have no tags and return nothing when this is set; 'parsed' does not support tags.",
|
|
396
|
+
"Comma-separated tags; returns only items carrying ALL of them (e.g. 'person:ada,project:atlas'). Works for screen + audio (content_type 'screen'/'ocr'/'audio'/'all', tags written by add-tags) AND memories (content_type 'memory', tags written by update-memory). Same tag string links across all three, so two items sharing a tag are connected. Use namespaced tags (person:, project:, topic:) to link people/projects/topics. content_type 'input' and 'accessibility' have no tags and return nothing when this is set; 'parsed' does not support tags.",
|
|
382
397
|
},
|
|
383
398
|
include_related: {
|
|
384
399
|
type: "boolean",
|
|
@@ -1170,7 +1185,7 @@ current machine. Synced results must be attributed with their device and timesta
|
|
|
1170
1185
|
- **Use max_content_length=500** to keep responses compact
|
|
1171
1186
|
- **Don't use q for audio** — transcriptions are noisy, q filters too aggressively. Search audio by time range and speaker instead
|
|
1172
1187
|
- **app_name is case-sensitive** — use exact names: "Google Chrome" not "chrome"
|
|
1173
|
-
- **
|
|
1188
|
+
- **Use content_type=screen for screen text.** Screenpipe walks the OS accessibility tree first, with OCR fallback. The result label \`[Screen·a11y]\` or \`[Screen·ocr]\` identifies the actual capture source; \`[Screen]\` means unknown. \`content_type=ocr\` is a legacy alias for the same search, not an OCR-only filter. Use \`accessibility\` only for an explicit accessibility-only request, since it excludes OCR fallback.
|
|
1174
1189
|
|
|
1175
1190
|
## Common Patterns
|
|
1176
1191
|
|
|
@@ -1414,7 +1429,8 @@ const observeCall = createCallObserver({
|
|
|
1414
1429
|
send: (payload, signal) => callAPI("/internal/telemetry/mcp-call", { method: "POST", body: JSON.stringify(payload), signal }),
|
|
1415
1430
|
});
|
|
1416
1431
|
server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(request.params.name, async () => {
|
|
1417
|
-
const { name, arguments:
|
|
1432
|
+
const { name, arguments: suppliedArgs } = request.params;
|
|
1433
|
+
const args = suppliedArgs ?? (name === CHAT_SEARCH_TOOL.name ? {} : undefined);
|
|
1418
1434
|
|
|
1419
1435
|
if (name === BUNDLED_SKILLS_TOOL.name) return readBundledSkills(args);
|
|
1420
1436
|
|
|
@@ -1613,6 +1629,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
1613
1629
|
case "search-content": {
|
|
1614
1630
|
const includeFrames = args.include_frames === true;
|
|
1615
1631
|
const normalized = normalizeTimeFields(args);
|
|
1632
|
+
// Keep the clearer MCP name compatible with APIs that still call all
|
|
1633
|
+
// screen-text rows "ocr", including accessibility-derived captures.
|
|
1634
|
+
if (normalized.content_type === "screen") normalized.content_type = "ocr";
|
|
1616
1635
|
// Default text cap if the caller didn't pass max_content_length.
|
|
1617
1636
|
// Keeps single calls under Claude Code's per-tool output limit.
|
|
1618
1637
|
const userCap = normalized.max_content_length;
|
|
@@ -1631,11 +1650,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
1631
1650
|
observeSearchResult(results.length, false);
|
|
1632
1651
|
|
|
1633
1652
|
if (results.length === 0) {
|
|
1653
|
+
// A zero-hit reply is a successful result, not an error. Disclose the
|
|
1654
|
+
// exact window and filters that were scanned so callers can widen the
|
|
1655
|
+
// right knob instead of guessing or retrying the same query.
|
|
1634
1656
|
return {
|
|
1635
1657
|
content: [
|
|
1636
1658
|
{
|
|
1637
1659
|
type: "text",
|
|
1638
|
-
text: "
|
|
1660
|
+
text: zeroHitCoverageText("search-content", {
|
|
1661
|
+
query: normalized.q as string | undefined,
|
|
1662
|
+
start_time: normalized.start_time as string | undefined,
|
|
1663
|
+
end_time: normalized.end_time as string | undefined,
|
|
1664
|
+
app: (normalized.app_name ?? normalized.app_names) as string | undefined,
|
|
1665
|
+
limit: normalized.limit as string | number | undefined,
|
|
1666
|
+
offset: normalized.offset as string | number | undefined,
|
|
1667
|
+
details: `content_type=${normalized.content_type ?? "all"}`,
|
|
1668
|
+
}),
|
|
1639
1669
|
},
|
|
1640
1670
|
],
|
|
1641
1671
|
};
|
|
@@ -2138,9 +2168,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
2138
2168
|
}
|
|
2139
2169
|
|
|
2140
2170
|
case "get-meeting": {
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2171
|
+
// Clients sometimes serialize integer ids as floats or numeric strings
|
|
2172
|
+
// ("268.0"); the Rust route parses the path segment as i64 and 400s.
|
|
2173
|
+
const meetingId = normalizePositiveInt(args.id);
|
|
2174
|
+
if (meetingId === null) {
|
|
2175
|
+
return {
|
|
2176
|
+
content: [
|
|
2177
|
+
{
|
|
2178
|
+
type: "text",
|
|
2179
|
+
text: `Error: id must be a positive integer (received ${JSON.stringify(args.id)}).`,
|
|
2180
|
+
},
|
|
2181
|
+
],
|
|
2182
|
+
};
|
|
2144
2183
|
}
|
|
2145
2184
|
const response = await callAPI(`/meetings/${meetingId}`);
|
|
2146
2185
|
const meeting = await response.json();
|
|
@@ -2153,7 +2192,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
2153
2192
|
text += "\n\nTranscript: (no segments recorded for this meeting)";
|
|
2154
2193
|
} else {
|
|
2155
2194
|
// Cap the payload: long meetings can have hundreds of segments.
|
|
2156
|
-
|
|
2195
|
+
// Clients can serialize the offset as "400.0"; coerce it back to a
|
|
2196
|
+
// whole number so slice() and the "more" hint stay correct.
|
|
2197
|
+
const offset = normalizeNonNegativeInt(args.transcript_offset) ?? 0;
|
|
2157
2198
|
const MAX_SEGMENTS = 200;
|
|
2158
2199
|
const MAX_CHARS = 40_000;
|
|
2159
2200
|
const page = segments.slice(offset, offset + MAX_SEGMENTS);
|
|
@@ -2257,7 +2298,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
2257
2298
|
? data
|
|
2258
2299
|
: (data.data ?? []);
|
|
2259
2300
|
if (results.length === 0) {
|
|
2260
|
-
return {
|
|
2301
|
+
return {
|
|
2302
|
+
content: [
|
|
2303
|
+
{
|
|
2304
|
+
type: "text",
|
|
2305
|
+
text: zeroHitCoverageText("keyword-search", {
|
|
2306
|
+
query: queryStr,
|
|
2307
|
+
start_time: normalized.start_time as string | undefined,
|
|
2308
|
+
end_time: normalized.end_time as string | undefined,
|
|
2309
|
+
app: (normalized.app_name ?? normalized.app_names) as string | undefined,
|
|
2310
|
+
limit: normalized.limit as string | number | undefined,
|
|
2311
|
+
offset: normalized.offset as string | number | undefined,
|
|
2312
|
+
details: `fuzzy_match=${args.fuzzy_match ?? false}`,
|
|
2313
|
+
}),
|
|
2314
|
+
},
|
|
2315
|
+
],
|
|
2316
|
+
};
|
|
2261
2317
|
}
|
|
2262
2318
|
qualifiedValue.searchResult();
|
|
2263
2319
|
const formatted = results.map((r) => {
|
|
@@ -2277,6 +2333,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => observeCall(r
|
|
|
2277
2333
|
};
|
|
2278
2334
|
}
|
|
2279
2335
|
|
|
2336
|
+
case "search-chats":
|
|
2337
|
+
return await searchChats(args, callAPI);
|
|
2338
|
+
|
|
2280
2339
|
case "list-workflows":
|
|
2281
2340
|
case "get-workflow":
|
|
2282
2341
|
return await readWorkflowTool(name, args, callAPI);
|
|
@@ -56,6 +56,11 @@ describe("createMcpQualifiedValueReporter", () => {
|
|
|
56
56
|
["gemini", "gemini-cli", "gemini"],
|
|
57
57
|
["runner", "Runner", "runner"],
|
|
58
58
|
["vscode", "vscode", "vscode"],
|
|
59
|
+
["opencode", "OpenCode", "opencode"],
|
|
60
|
+
["antigravity", "Antigravity", "antigravity"],
|
|
61
|
+
["cline", "Cline", "cline"],
|
|
62
|
+
["kiro", "Kiro", "kiro"],
|
|
63
|
+
["perplexity", "Perplexity", "perplexity"],
|
|
59
64
|
["grokbot", "Grok Bot", "grokbot"],
|
|
60
65
|
])("recognizes configured %s and its handshake name", (configured, protocol, expected) => {
|
|
61
66
|
expect(resolveMcpClient(configured, "unrecognized-client")).toBe(expected);
|
package/src/qualified-value.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const CLIENTS = [
|
|
6
6
|
"claude", "chatgpt", "codex", "cursor", "gemini", "openclaw",
|
|
7
|
-
"hermes", "runner", "windsurf", "vscode", "grok", "grokbot",
|
|
7
|
+
"hermes", "runner", "windsurf", "vscode", "opencode", "antigravity", "cline", "kiro", "perplexity", "grok", "grokbot",
|
|
8
8
|
] as const;
|
|
9
9
|
export type McpClient = (typeof CLIENTS)[number] | "unknown";
|
|
10
10
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// screenpipe — AI that knows everything you've seen, said, or heard
|
|
2
|
+
// https://screenpipe.com
|
|
3
|
+
import { it, expect } from "vitest";
|
|
4
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
|
|
10
|
+
// End-to-end over the built stdio transport: zero-hit replies must disclose
|
|
11
|
+
// their coverage, errors must stay distinct from zero matches, and numeric
|
|
12
|
+
// arguments serialized as floats ("268.0") must reach the engine as integers.
|
|
13
|
+
it("discloses zero-hit coverage, separates errors, and normalizes meeting ids over the built MCP", async () => {
|
|
14
|
+
const root = path.resolve(__dirname, "..");
|
|
15
|
+
execFileSync("bun", ["run", "build"], { cwd: root, stdio: "pipe", timeout: 120000 });
|
|
16
|
+
const requests: URL[] = [];
|
|
17
|
+
let searchStatus = 200;
|
|
18
|
+
const api = createServer((req, res) => {
|
|
19
|
+
const url = new URL(req.url || "/", "http://localhost");
|
|
20
|
+
requests.push(url);
|
|
21
|
+
res.setHeader("Content-Type", "application/json");
|
|
22
|
+
if (req.headers.authorization !== "Bearer fixture-key") {
|
|
23
|
+
res.writeHead(403).end("{}");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const pathname = url.pathname;
|
|
27
|
+
if (pathname === "/search" || pathname === "/search/keyword") {
|
|
28
|
+
res.writeHead(searchStatus);
|
|
29
|
+
// Zero hits: /search uses {data, pagination}, /search/keyword a bare array.
|
|
30
|
+
res.end(pathname === "/search"
|
|
31
|
+
? JSON.stringify({ data: [], pagination: { total: 0, limit: 10, offset: 0 } })
|
|
32
|
+
: "[]");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (pathname === "/meetings/268") {
|
|
36
|
+
res.end(JSON.stringify({ id: 268, title: "Fixture meeting", note: "ok" }));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (pathname === "/meetings/268/transcript") {
|
|
40
|
+
// 500 short segments: a normalized offset of 400 should show 401-500.
|
|
41
|
+
res.end(JSON.stringify(Array.from({ length: 500 }, (_, i) => ({
|
|
42
|
+
capturedAt: `2026-01-01T12:00:00Z`, speakerName: "Ada", transcript: `segment ${i + 1}`,
|
|
43
|
+
}))));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
res.end("{}"); // absorb telemetry / other read-only calls
|
|
47
|
+
});
|
|
48
|
+
await new Promise<void>(resolve => api.listen(0, "127.0.0.1", resolve));
|
|
49
|
+
const address = api.address();
|
|
50
|
+
if (!address || typeof address === "string") throw new Error("No fixture API address");
|
|
51
|
+
const client = new Client({ name: "result-contracts", version: "1.0" });
|
|
52
|
+
const transport = new StdioClientTransport({
|
|
53
|
+
command: process.execPath, args: [path.join(root, "dist/cli.js")],
|
|
54
|
+
env: { PATH: process.env.PATH || "", SCREENPIPE_LOCAL_API_URL: `http://127.0.0.1:${address.port}`,
|
|
55
|
+
SCREENPIPE_LOCAL_API_KEY: "fixture-key", SCREENPIPE_DISABLE_TELEMETRY: "1" }, stderr: "pipe",
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
await client.connect(transport);
|
|
59
|
+
|
|
60
|
+
// 1. search-content zero hit: successful result, not an error, with coverage.
|
|
61
|
+
const sc = await client.callTool({ name: "search-content", arguments: {
|
|
62
|
+
q: "zephyrium", start_time: "2026-11-01T00:00:00Z", end_time: "2026-11-16T00:00:00Z",
|
|
63
|
+
app_name: "cmux", limit: 10, offset: 0,
|
|
64
|
+
} });
|
|
65
|
+
expect(sc.isError).not.toBe(true);
|
|
66
|
+
const scText = JSON.stringify(sc.content);
|
|
67
|
+
expect(scText).toContain("No results for search-content");
|
|
68
|
+
expect(scText).toContain("zero results; this is not an error");
|
|
69
|
+
expect(scText).toContain("Coverage:");
|
|
70
|
+
expect(scText).toContain("query=zephyrium");
|
|
71
|
+
expect(scText).toContain("app=cmux");
|
|
72
|
+
expect(scText).toContain("limit=10");
|
|
73
|
+
expect(scText).toContain("offset=0");
|
|
74
|
+
expect(scText).toContain("content_type=all");
|
|
75
|
+
|
|
76
|
+
// 2. keyword-search zero hit: same contract on the other search tool.
|
|
77
|
+
const kw = await client.callTool({ name: "keyword-search", arguments: {
|
|
78
|
+
q: "zephyrium", start_time: "2026-11-01T00:00:00Z", app_name: "cmux", limit: 10,
|
|
79
|
+
} });
|
|
80
|
+
expect(kw.isError).not.toBe(true);
|
|
81
|
+
const kwText = JSON.stringify(kw.content);
|
|
82
|
+
expect(kwText).toContain("No results for keyword-search");
|
|
83
|
+
expect(kwText).toContain("zero results; this is not an error");
|
|
84
|
+
expect(kwText).toContain("Coverage:");
|
|
85
|
+
expect(kwText).toContain("query=zephyrium");
|
|
86
|
+
expect(kwText).toContain("fuzzy_match=false");
|
|
87
|
+
|
|
88
|
+
// 3. A backend failure must stay an error, never a zero-hit reply.
|
|
89
|
+
searchStatus = 500;
|
|
90
|
+
const err = await client.callTool({ name: "keyword-search", arguments: { q: "zephyrium" } });
|
|
91
|
+
expect(err.isError).toBe(true);
|
|
92
|
+
expect(JSON.stringify(err.content)).not.toContain("zero results; this is not an error");
|
|
93
|
+
searchStatus = 200;
|
|
94
|
+
|
|
95
|
+
// 4. get-meeting with float-string id/offset: id must be normalized to 268,
|
|
96
|
+
// never requested as /meetings/268.0, and no error returned.
|
|
97
|
+
const gm = await client.callTool({ name: "get-meeting", arguments: {
|
|
98
|
+
id: "268.0", include_transcript: true, transcript_offset: "400.0",
|
|
99
|
+
} });
|
|
100
|
+
expect(gm.isError).not.toBe(true);
|
|
101
|
+
expect(requests.some(r => r.pathname === "/meetings/268")).toBe(true);
|
|
102
|
+
expect(requests.some(r => r.pathname === "/meetings/268.0")).toBe(false);
|
|
103
|
+
// transcript_offset "400.0" must be coerced to a whole number, not NaN.
|
|
104
|
+
expect(JSON.stringify(gm.content)).toContain("showing 401-500");
|
|
105
|
+
|
|
106
|
+
// 5. A genuinely bad id returns a clear local error, not a 400 from the engine.
|
|
107
|
+
const bad = await client.callTool({ name: "get-meeting", arguments: { id: "268.5" } });
|
|
108
|
+
expect(JSON.stringify(bad.content)).toContain("id must be a positive integer");
|
|
109
|
+
} finally {
|
|
110
|
+
await client.close();
|
|
111
|
+
await transport.close();
|
|
112
|
+
await new Promise<void>(resolve => api.close(() => resolve()));
|
|
113
|
+
}
|
|
114
|
+
}, 30000);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// screenpipe — AI that knows everything you've seen, said, or heard
|
|
2
|
+
// https://screenpipe.com
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
normalizeNonNegativeInt,
|
|
6
|
+
normalizePositiveInt,
|
|
7
|
+
zeroHitCoverageText,
|
|
8
|
+
} from "./result-contracts";
|
|
9
|
+
|
|
10
|
+
it("states coverage and distinguishes zero matches from an error", () => {
|
|
11
|
+
const text = zeroHitCoverageText("keyword-search", {
|
|
12
|
+
query: "zephyrium",
|
|
13
|
+
start_time: "2026-11-01T00:00:00Z",
|
|
14
|
+
end_time: "2026-11-16T00:00:00Z",
|
|
15
|
+
app: "cmux",
|
|
16
|
+
limit: 10,
|
|
17
|
+
offset: 0,
|
|
18
|
+
details: "fuzzy_match=false",
|
|
19
|
+
});
|
|
20
|
+
expect(text).toContain("No results for keyword-search");
|
|
21
|
+
expect(text).toContain("zero results; this is not an error");
|
|
22
|
+
expect(text).toContain("Coverage:");
|
|
23
|
+
expect(text).toContain("query=zephyrium");
|
|
24
|
+
expect(text).toContain("start_time=2026-11-01T00:00:00Z");
|
|
25
|
+
expect(text).toContain("end_time=2026-11-16T00:00:00Z");
|
|
26
|
+
expect(text).toContain("app=cmux");
|
|
27
|
+
expect(text).toContain("limit=10");
|
|
28
|
+
expect(text).toContain("offset=0");
|
|
29
|
+
expect(text).toContain("fuzzy_match=false");
|
|
30
|
+
expect(text).toContain("wider start_time/end_time");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("discloses unbounded defaults instead of hiding them", () => {
|
|
34
|
+
const text = zeroHitCoverageText("search-content");
|
|
35
|
+
expect(text).toContain("start_time=(unbounded)");
|
|
36
|
+
expect(text).toContain("end_time=(unbounded)");
|
|
37
|
+
expect(text).toContain("app=(all)");
|
|
38
|
+
expect(text).toContain("limit=(default)");
|
|
39
|
+
expect(text).toContain("offset=0");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("coerces integer arguments serialized as floats or numeric strings", () => {
|
|
43
|
+
expect(normalizePositiveInt("268.0")).toBe(268);
|
|
44
|
+
expect(normalizePositiveInt("268")).toBe(268);
|
|
45
|
+
expect(normalizePositiveInt(" 268 ")).toBe(268);
|
|
46
|
+
expect(normalizePositiveInt(268)).toBe(268);
|
|
47
|
+
expect(normalizePositiveInt(268.0)).toBe(268);
|
|
48
|
+
expect(normalizeNonNegativeInt("400.0")).toBe(400);
|
|
49
|
+
expect(normalizeNonNegativeInt(0)).toBe(0);
|
|
50
|
+
expect(normalizeNonNegativeInt("0")).toBe(0);
|
|
51
|
+
expect(normalizeNonNegativeInt(undefined)).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("rejects fractional, negative and non-numeric arguments", () => {
|
|
55
|
+
expect(normalizePositiveInt("268.5")).toBeNull();
|
|
56
|
+
expect(normalizePositiveInt("-1")).toBeNull();
|
|
57
|
+
expect(normalizePositiveInt(0)).toBeNull();
|
|
58
|
+
expect(normalizePositiveInt(-3)).toBeNull();
|
|
59
|
+
expect(normalizePositiveInt("meeting-268")).toBeNull();
|
|
60
|
+
expect(normalizePositiveInt(null)).toBeNull();
|
|
61
|
+
expect(normalizePositiveInt(1.5)).toBeNull();
|
|
62
|
+
expect(normalizeNonNegativeInt("-1")).toBeNull();
|
|
63
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// screenpipe — AI that knows everything you've seen, said, or heard
|
|
2
|
+
// https://screenpipe.com
|
|
3
|
+
|
|
4
|
+
export interface SearchCoverage {
|
|
5
|
+
query?: string;
|
|
6
|
+
start_time?: string;
|
|
7
|
+
end_time?: string;
|
|
8
|
+
app?: string;
|
|
9
|
+
limit?: string | number;
|
|
10
|
+
offset?: string | number;
|
|
11
|
+
details?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A zero-hit reply is a successful result, not an error. State what was
|
|
16
|
+
* scanned so a caller can distinguish "nothing in this window" from "wrong
|
|
17
|
+
* query" or "backend unavailable", and knows which filter to widen. Errors
|
|
18
|
+
* keep their own distinct shape and never use this text.
|
|
19
|
+
*/
|
|
20
|
+
export function zeroHitCoverageText(tool: string, c: SearchCoverage = {}): string {
|
|
21
|
+
const fields = [
|
|
22
|
+
`query=${c.query ?? "(none)"}`,
|
|
23
|
+
`start_time=${c.start_time ?? "(unbounded)"}`,
|
|
24
|
+
`end_time=${c.end_time ?? "(unbounded)"}`,
|
|
25
|
+
`app=${c.app ?? "(all)"}`,
|
|
26
|
+
`limit=${c.limit ?? "(default)"}`,
|
|
27
|
+
`offset=${c.offset ?? 0}`,
|
|
28
|
+
];
|
|
29
|
+
if (c.details) fields.push(c.details);
|
|
30
|
+
return [
|
|
31
|
+
`No results for ${tool} (successful search, zero results; this is not an error).`,
|
|
32
|
+
`Coverage: ${fields.join(", ")}.`,
|
|
33
|
+
"Try a wider start_time/end_time, fewer terms, or removing the app filter.",
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Some MCP clients serialize integer arguments as floats or numeric strings
|
|
39
|
+
* (for example "268.0"), which the Rust routes reject as a non-i64 URL segment.
|
|
40
|
+
* Accept only whole, non-negative values; reject fractional or junk input so a
|
|
41
|
+
* bad argument produces a clear local error instead of a 400 from the engine.
|
|
42
|
+
*/
|
|
43
|
+
export function normalizePositiveInt(raw: unknown): number | null {
|
|
44
|
+
return normalizeInt(raw, 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function normalizeNonNegativeInt(raw: unknown): number | null {
|
|
48
|
+
return normalizeInt(raw, 0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeInt(raw: unknown, min: number): number | null {
|
|
52
|
+
if (typeof raw === "number") {
|
|
53
|
+
return Number.isSafeInteger(raw) && raw >= min ? raw : null;
|
|
54
|
+
}
|
|
55
|
+
if (typeof raw === "string") {
|
|
56
|
+
const value = raw.trim();
|
|
57
|
+
if (!/^\d+(?:\.0+)?$/.test(value)) return null;
|
|
58
|
+
const parsed = Number(value);
|
|
59
|
+
return Number.isSafeInteger(parsed) && parsed >= min ? parsed : null;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|