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.
@@ -0,0 +1,80 @@
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
+ it("advertises screen text and preserves legacy search behavior over the built MCP transport", async () => {
11
+ const root = path.resolve(__dirname, "..");
12
+ execFileSync("bun", ["run", "build"], { cwd: root, stdio: "pipe", timeout: 120000 });
13
+ const requests: URL[] = [];
14
+ const api = createServer((req, res) => {
15
+ const url = new URL(req.url || "/", "http://localhost");
16
+ requests.push(url);
17
+ res.setHeader("Content-Type", "application/json");
18
+ if (req.headers.authorization !== "Bearer fixture-key") {
19
+ res.writeHead(403).end("{}");
20
+ return;
21
+ }
22
+ // A backend that only accepts the legacy name proves MCP translates it.
23
+ const sources = url.searchParams.get("content_type") === "ocr"
24
+ ? ["accessibility", "ocr", undefined] : [];
25
+ res.end(JSON.stringify({
26
+ data: sources.map((source, index) => ({ type: "OCR", content: {
27
+ frame_id: index + 1, app_name: "Fixture", window_name: "Screen text",
28
+ timestamp: "2026-01-01T12:00:00Z", text: `Captured text ${index + 1}`,
29
+ text_source: source, tags: ["project:fixture"], frame: "c3ludGhldGlj",
30
+ } })),
31
+ pagination: { total: sources.length ? 10 : 0, limit: 3, offset: Number(url.searchParams.get("offset") || 0) },
32
+ }));
33
+ });
34
+ await new Promise<void>(resolve => api.listen(0, "127.0.0.1", resolve));
35
+ const address = api.address();
36
+ if (!address || typeof address === "string") throw new Error("No fixture API address");
37
+ const client = new Client({ name: "screen-search-contract", version: "1.0" });
38
+ const transport = new StdioClientTransport({
39
+ command: process.execPath, args: [path.join(root, "dist/cli.js")],
40
+ env: { PATH: process.env.PATH || "", SCREENPIPE_LOCAL_API_URL: `http://127.0.0.1:${address.port}`,
41
+ SCREENPIPE_LOCAL_API_KEY: "fixture-key", SCREENPIPE_DISABLE_TELEMETRY: "1" }, stderr: "pipe",
42
+ });
43
+ try {
44
+ await client.connect(transport);
45
+ const { tools } = await client.listTools();
46
+ const property = tools.find(tool => tool.name === "search-content")!.inputSchema.properties!.content_type as { enum: string[]; description: string };
47
+ expect(property.enum).toEqual(expect.arrayContaining(["screen", "ocr", "accessibility", "all", "audio", "parsed"]));
48
+ expect(property.description).toContain("Use 'screen' for screen text");
49
+ expect(property.description).toContain("legacy alias");
50
+ for (const contentType of ["screen", "ocr"]) {
51
+ const filters = { app_name: "Fixture", window_name: "Screen text", q: "Captured", tags: "project:fixture",
52
+ include_related: true, limit: 3, offset: 3, max_content_length: 100, include_frames: true };
53
+ const result = await client.callTool({ name: "search-content", arguments: {
54
+ content_type: contentType, start_time: "2026-01-01T00:00:00Z", end_time: "2026-01-02T00:00:00Z", ...filters,
55
+ } });
56
+ expect(result.isError).not.toBe(true);
57
+ const text = JSON.stringify(result.content);
58
+ expect(text).toContain("[Screen·a11y]");
59
+ expect(text).toContain("[Screen·ocr]");
60
+ expect(text).toContain("[Screen] Fixture");
61
+ expect(text).toContain("offset=6");
62
+ expect(result.content).toEqual(expect.arrayContaining([expect.objectContaining({ type: "image", data: "c3ludGhldGlj" })]));
63
+ const params = requests.at(-1)!.searchParams;
64
+ expect(params.get("content_type")).toBe("ocr");
65
+ for (const [key, value] of Object.entries(filters)) expect(params.get(key)).toBe(String(value));
66
+ expect(Date.parse(params.get("start_time")!)).toBe(Date.parse("2026-01-01T00:00:00Z"));
67
+ expect(Date.parse(params.get("end_time")!)).toBe(Date.parse("2026-01-02T00:00:00Z"));
68
+ }
69
+ for (const contentType of ["all", "accessibility", "audio", "input", "memory", "parsed", undefined]) {
70
+ await client.callTool({ name: "search-content", arguments: {
71
+ start_time: "2026-01-01", ...(contentType ? { content_type: contentType } : {}),
72
+ } });
73
+ expect(requests.at(-1)!.searchParams.get("content_type")).toBe(contentType ?? null);
74
+ }
75
+ } finally {
76
+ await client.close();
77
+ await transport.close();
78
+ await new Promise<void>(resolve => api.close(() => resolve()));
79
+ }
80
+ }, 15000);