@clipy/mcp 0.8.6 → 0.9.0
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/README.md +3 -0
- package/dist/arecRange.js +98 -0
- package/dist/index.js +175 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -111,6 +111,9 @@ or the Windsurf MCP config) directly:
|
|
|
111
111
|
| `add_chapter` | Drop a `=== CHAPTER: <label> ===` boundary into the active session — split a recording into named sections (ideal for before/after demos). |
|
|
112
112
|
| `stop_recording` | Finish the session: close the browser, upload, return the share + agent-context URLs. |
|
|
113
113
|
| `abort_recording` | Discard the active session; nothing is uploaded. |
|
|
114
|
+
| `list_context_documents` | List the user's **context documents** — YouTube videos and local video files they imported with `clipy context import`, so agents can read them. A separate library from their own screen recordings. |
|
|
115
|
+
| `get_context_document` | One context document's metadata: source, duration, tags, the server's classification (video type, whether visual evidence is needed, planned moments), and which transcript/frames exist. Not the transcript itself. |
|
|
116
|
+
| `read_context_document` | Read a context document as compiled markdown — header, metadata, then the timestamped transcript with frame captions interleaved. Takes `startMs`/`endMs` so you can walk a two-hour video section by section instead of flooding your context. |
|
|
114
117
|
| `replace_transcript` | **Replace a recording's transcript** with text you author (needs the `ingest` scope). Fix a bad speech-to-text pass, translate, or enrich a silent agent capture; the summary regenerates automatically. Marked as agent-edited, never passed off as speech-to-text. |
|
|
115
118
|
|
|
116
119
|
Read tools accept a recording's **public id** (the slug in its share URL) or the full
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Range slicing for compiled AREC markdown (`recording.md`).
|
|
3
|
+
*
|
|
4
|
+
* The compiler emits a header block (title, metadata, visual gaps, frames)
|
|
5
|
+
* followed by `## Transcript` and then one `### MM:SS` heading every ~150s,
|
|
6
|
+
* with `[MM:SS] spoken text` lines under it. Slicing at heading granularity
|
|
7
|
+
* keeps a section's interleaved frame images attached to the words they
|
|
8
|
+
* illustrate, which per-line filtering would strip.
|
|
9
|
+
*
|
|
10
|
+
* Kept dependency-free and side-effect-free so it can be unit tested offline.
|
|
11
|
+
*/
|
|
12
|
+
const HEADING = /^###\s+(\d{1,2}:\d{2}(?::\d{2})?)\s*$/;
|
|
13
|
+
/** `MM:SS` or `H:MM:SS` → milliseconds. Returns null if it isn't a timestamp. */
|
|
14
|
+
export function parseTimestamp(value) {
|
|
15
|
+
const parts = value.trim().split(":");
|
|
16
|
+
if (parts.length < 2 || parts.length > 3)
|
|
17
|
+
return null;
|
|
18
|
+
const nums = parts.map((p) => Number(p));
|
|
19
|
+
if (nums.some((n) => !Number.isFinite(n) || n < 0))
|
|
20
|
+
return null;
|
|
21
|
+
const [h, m, s] = parts.length === 3 ? nums : [0, nums[0], nums[1]];
|
|
22
|
+
return (h * 3600 + m * 60 + s) * 1000;
|
|
23
|
+
}
|
|
24
|
+
/** Splits compiled AREC markdown into its header block and timestamped sections. */
|
|
25
|
+
export function parseArecMarkdown(markdown) {
|
|
26
|
+
const lines = markdown.split("\n");
|
|
27
|
+
const headerLines = [];
|
|
28
|
+
const sections = [];
|
|
29
|
+
let current = null;
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
const m = HEADING.exec(line);
|
|
32
|
+
const ms = m ? parseTimestamp(m[1]) : null;
|
|
33
|
+
if (ms !== null) {
|
|
34
|
+
if (current) {
|
|
35
|
+
sections.push({ startMs: current.startMs, endMs: ms, text: current.lines.join("\n").trim() });
|
|
36
|
+
}
|
|
37
|
+
current = { startMs: ms, lines: [line] };
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (current)
|
|
41
|
+
current.lines.push(line);
|
|
42
|
+
else
|
|
43
|
+
headerLines.push(line);
|
|
44
|
+
}
|
|
45
|
+
if (current) {
|
|
46
|
+
sections.push({
|
|
47
|
+
startMs: current.startMs,
|
|
48
|
+
endMs: Number.POSITIVE_INFINITY,
|
|
49
|
+
text: current.lines.join("\n").trim(),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { header: headerLines.join("\n").trim(), sections };
|
|
53
|
+
}
|
|
54
|
+
/** Default ceiling on a full (unranged) read, in characters. */
|
|
55
|
+
export const MAX_MARKDOWN_CHARS = 60_000;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the header block plus every section overlapping [startMs, endMs).
|
|
58
|
+
* An open-ended range (either bound omitted) extends to the document edge.
|
|
59
|
+
*/
|
|
60
|
+
export function sliceArecMarkdown(markdown, range = {}, maxChars = MAX_MARKDOWN_CHARS) {
|
|
61
|
+
const { header, sections } = parseArecMarkdown(markdown);
|
|
62
|
+
const hasRange = range.startMs !== undefined || range.endMs !== undefined;
|
|
63
|
+
if (!hasRange) {
|
|
64
|
+
if (markdown.length <= maxChars) {
|
|
65
|
+
return {
|
|
66
|
+
markdown,
|
|
67
|
+
sectionsReturned: sections.length,
|
|
68
|
+
sectionsTotal: sections.length,
|
|
69
|
+
truncated: false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
markdown: `${markdown.slice(0, maxChars)}\n\n[... truncated at ${maxChars} characters. This recording is long — re-read a portion with startMs/endMs (the document is sectioned every ~150s, headings are the [MM:SS] markers).]\n`,
|
|
74
|
+
sectionsReturned: sections.length,
|
|
75
|
+
sectionsTotal: sections.length,
|
|
76
|
+
truncated: true,
|
|
77
|
+
note: "Truncated. Use startMs/endMs to read a specific span.",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const from = range.startMs ?? 0;
|
|
81
|
+
const to = range.endMs ?? Number.POSITIVE_INFINITY;
|
|
82
|
+
const kept = sections.filter((s) => s.startMs < to && s.endMs > from);
|
|
83
|
+
const body = kept.length
|
|
84
|
+
? kept.map((s) => s.text).join("\n\n")
|
|
85
|
+
: "_No transcript sections fall in that range._";
|
|
86
|
+
let out = `${header}\n\n${body}\n`;
|
|
87
|
+
let truncated = false;
|
|
88
|
+
if (out.length > maxChars) {
|
|
89
|
+
out = `${out.slice(0, maxChars)}\n\n[... truncated at ${maxChars} characters. Narrow the range.]\n`;
|
|
90
|
+
truncated = true;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
markdown: out,
|
|
94
|
+
sectionsReturned: kept.length,
|
|
95
|
+
sectionsTotal: sections.length,
|
|
96
|
+
truncated,
|
|
97
|
+
};
|
|
98
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25
25
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
26
26
|
import { z } from "zod";
|
|
27
|
+
import { MAX_MARKDOWN_CHARS, sliceArecMarkdown } from "./arecRange.js";
|
|
27
28
|
import { chmodSync, closeSync, cpSync, createWriteStream, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, rmSync, statSync } from "node:fs";
|
|
28
29
|
import { randomUUID } from "node:crypto";
|
|
29
30
|
import { createServer } from "node:net";
|
|
@@ -33,7 +34,7 @@ import { Readable } from "node:stream";
|
|
|
33
34
|
import { pipeline } from "node:stream/promises";
|
|
34
35
|
const API_URL = (process.env.CLIPY_API_URL || "https://clipy.online").replace(/\/+$/, "");
|
|
35
36
|
const API_KEY = process.env.CLIPY_API_KEY;
|
|
36
|
-
const SERVER_VERSION = "0.
|
|
37
|
+
const SERVER_VERSION = "0.9.0";
|
|
37
38
|
// The key is checked lazily (per tool call, not at startup) so the server can
|
|
38
39
|
// start and answer introspection (initialize / tools/list) in keyless
|
|
39
40
|
// environments like directory health checks.
|
|
@@ -85,6 +86,50 @@ async function api(path) {
|
|
|
85
86
|
}
|
|
86
87
|
return body;
|
|
87
88
|
}
|
|
89
|
+
/** Same call shape as `api()` but for endpoints that return text/markdown. */
|
|
90
|
+
async function apiText(path) {
|
|
91
|
+
if (!API_KEY) {
|
|
92
|
+
throw new Error(`Missing CLIPY_API_KEY. Create a free API key at ${API_URL}/settings/api-keys ` +
|
|
93
|
+
"and set it in your MCP client config, then try again.");
|
|
94
|
+
}
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
97
|
+
let res;
|
|
98
|
+
try {
|
|
99
|
+
res = await fetch(`${API_URL}${path}`, {
|
|
100
|
+
headers: {
|
|
101
|
+
Authorization: `Bearer ${API_KEY}`,
|
|
102
|
+
Accept: "text/markdown, text/plain, */*",
|
|
103
|
+
"User-Agent": `clipy-mcp/${SERVER_VERSION}`,
|
|
104
|
+
},
|
|
105
|
+
signal: controller.signal,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
if (e.name === "AbortError") {
|
|
110
|
+
throw new Error(`Clipy API request timed out after ${FETCH_TIMEOUT_MS / 1000}s`);
|
|
111
|
+
}
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
}
|
|
117
|
+
const text = await res.text();
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
// Errors come back as JSON even from the markdown route.
|
|
120
|
+
let msg = `Clipy API error ${res.status}`;
|
|
121
|
+
try {
|
|
122
|
+
const body = JSON.parse(text);
|
|
123
|
+
if (typeof body.error === "string")
|
|
124
|
+
msg = body.error;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
/* keep the status-based message */
|
|
128
|
+
}
|
|
129
|
+
throw new Error(msg);
|
|
130
|
+
}
|
|
131
|
+
return text;
|
|
132
|
+
}
|
|
88
133
|
// ---------------------------------------------------------------------------
|
|
89
134
|
// Ingest (write) helpers — used only by the `record` tool. These POST to the
|
|
90
135
|
// raw-upload pipeline with the API key (which must carry the `ingest` scope).
|
|
@@ -2366,6 +2411,135 @@ server.tool("abort_recording", "Discard the active recording session: closes the
|
|
|
2366
2411
|
return fail(e.message);
|
|
2367
2412
|
}
|
|
2368
2413
|
});
|
|
2414
|
+
// ---------------------------------------------------------------------------
|
|
2415
|
+
// Context documents — the user's memory of videos Clipy did NOT record
|
|
2416
|
+
// (YouTube imports, local video files). Read-only; separate library from
|
|
2417
|
+
// recordings, with its own ids.
|
|
2418
|
+
// ---------------------------------------------------------------------------
|
|
2419
|
+
const contextDocIdSchema = z
|
|
2420
|
+
.string()
|
|
2421
|
+
.describe("The context document's public id (or internal id), as returned by list_context_documents.");
|
|
2422
|
+
server.tool("list_context_documents", "List the user's context documents — their imported/watched-video memory: YouTube videos and local video files they imported into Clipy so agents can read them. This is a SEPARATE library from the user's own screen recordings (use list_recordings/search_recordings for those). Returns compact metadata only; call read_context_document for the transcript.", {
|
|
2423
|
+
query: z
|
|
2424
|
+
.string()
|
|
2425
|
+
.optional()
|
|
2426
|
+
.describe("Keywords to match against title and transcript text."),
|
|
2427
|
+
tag: z.string().optional().describe("Filter to documents carrying this tag."),
|
|
2428
|
+
limit: z.number().int().min(1).max(100).optional().describe("Max results (default 25)."),
|
|
2429
|
+
}, async ({ query, tag, limit }) => {
|
|
2430
|
+
try {
|
|
2431
|
+
const params = new URLSearchParams();
|
|
2432
|
+
if (query)
|
|
2433
|
+
params.set("q", query);
|
|
2434
|
+
if (tag)
|
|
2435
|
+
params.set("tag", tag);
|
|
2436
|
+
if (limit)
|
|
2437
|
+
params.set("limit", String(limit));
|
|
2438
|
+
const qs = params.toString();
|
|
2439
|
+
const body = await api(`/api/v1/context-documents${qs ? `?${qs}` : ""}`);
|
|
2440
|
+
const docs = Array.isArray(body.documents) ? body.documents : [];
|
|
2441
|
+
return ok({
|
|
2442
|
+
documents: docs.map((d) => ({
|
|
2443
|
+
publicId: d.publicId,
|
|
2444
|
+
title: d.title,
|
|
2445
|
+
sourceKind: d.sourceKind,
|
|
2446
|
+
sourceUrl: d.sourceUrl,
|
|
2447
|
+
durationMs: d.durationMs,
|
|
2448
|
+
language: d.language,
|
|
2449
|
+
tags: d.tags,
|
|
2450
|
+
segmentCount: d.segmentCount,
|
|
2451
|
+
frameCount: d.frameCount,
|
|
2452
|
+
ingestStatus: d.ingestStatus,
|
|
2453
|
+
createdAt: d.createdAt,
|
|
2454
|
+
})),
|
|
2455
|
+
pagination: body.pagination,
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
catch (e) {
|
|
2459
|
+
return fail(e.message);
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
server.tool("get_context_document", "Get one context document's metadata: source (YouTube URL or local file), duration, tags, its server-side classification (video type, whether visual evidence is needed, planned moments), and what transcript/frames are available. Deliberately does NOT return the transcript — call read_context_document for that.", { id: contextDocIdSchema }, async ({ id }) => {
|
|
2463
|
+
try {
|
|
2464
|
+
const body = await api(`/api/v1/context-documents/${encodeURIComponent(id.trim())}`);
|
|
2465
|
+
const doc = (body.document ?? {});
|
|
2466
|
+
const transcript = (doc.transcript ?? {});
|
|
2467
|
+
const segments = Array.isArray(transcript.segments) ? transcript.segments : [];
|
|
2468
|
+
const plaintext = typeof transcript.plaintext === "string" ? transcript.plaintext : "";
|
|
2469
|
+
const markdown = typeof doc.arecMarkdown === "string" ? doc.arecMarkdown : "";
|
|
2470
|
+
const artifacts = Array.isArray(doc.artifacts) ? doc.artifacts : [];
|
|
2471
|
+
return ok({
|
|
2472
|
+
publicId: doc.publicId,
|
|
2473
|
+
title: doc.title,
|
|
2474
|
+
sourceKind: doc.sourceKind,
|
|
2475
|
+
source: doc.source,
|
|
2476
|
+
durationMs: doc.durationMs,
|
|
2477
|
+
language: doc.language,
|
|
2478
|
+
profile: doc.profile,
|
|
2479
|
+
tags: doc.tags,
|
|
2480
|
+
ingestStatus: doc.ingestStatus,
|
|
2481
|
+
createdAt: doc.createdAt,
|
|
2482
|
+
updatedAt: doc.updatedAt,
|
|
2483
|
+
classification: doc.classification,
|
|
2484
|
+
sufficiency: doc.sufficiency,
|
|
2485
|
+
transcript: {
|
|
2486
|
+
source: transcript.source,
|
|
2487
|
+
language: transcript.language,
|
|
2488
|
+
segmentCount: segments.length,
|
|
2489
|
+
plaintextChars: plaintext.length,
|
|
2490
|
+
available: segments.length > 0 || plaintext.length > 0,
|
|
2491
|
+
},
|
|
2492
|
+
frames: artifacts.map((a) => ({
|
|
2493
|
+
id: a.id,
|
|
2494
|
+
kind: a.kind,
|
|
2495
|
+
timestampMs: a.timestampMs,
|
|
2496
|
+
caption: a.caption,
|
|
2497
|
+
})),
|
|
2498
|
+
markdownChars: markdown.length,
|
|
2499
|
+
hint: "Read the document with read_context_document; pass startMs/endMs on long videos.",
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
catch (e) {
|
|
2503
|
+
return fail(e.message);
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
server.tool("read_context_document", "Read a context document as compiled markdown: header + metadata, then the timestamped transcript (with frame captions interleaved). Pass startMs/endMs to read only the part of a long video you care about — the document is sectioned roughly every 150s and only sections overlapping your range come back, so you can walk a two-hour video without flooding your context.", {
|
|
2507
|
+
id: contextDocIdSchema,
|
|
2508
|
+
startMs: z
|
|
2509
|
+
.number()
|
|
2510
|
+
.int()
|
|
2511
|
+
.min(0)
|
|
2512
|
+
.optional()
|
|
2513
|
+
.describe("Start of the span to read, in milliseconds into the video."),
|
|
2514
|
+
endMs: z
|
|
2515
|
+
.number()
|
|
2516
|
+
.int()
|
|
2517
|
+
.min(0)
|
|
2518
|
+
.optional()
|
|
2519
|
+
.describe("End of the span to read, in milliseconds. Omit for 'to the end'."),
|
|
2520
|
+
}, async ({ id, startMs, endMs }) => {
|
|
2521
|
+
if (startMs !== undefined && endMs !== undefined && endMs <= startMs) {
|
|
2522
|
+
return fail("endMs must be greater than startMs");
|
|
2523
|
+
}
|
|
2524
|
+
try {
|
|
2525
|
+
const markdown = await apiText(`/api/v1/context-documents/${encodeURIComponent(id.trim())}/recording.md`);
|
|
2526
|
+
const sliced = sliceArecMarkdown(markdown, { startMs, endMs }, MAX_MARKDOWN_CHARS);
|
|
2527
|
+
return {
|
|
2528
|
+
content: [
|
|
2529
|
+
{
|
|
2530
|
+
type: "text",
|
|
2531
|
+
text: sliced.markdown +
|
|
2532
|
+
(sliced.sectionsTotal > sliced.sectionsReturned
|
|
2533
|
+
? `\n\n[Showing ${sliced.sectionsReturned} of ${sliced.sectionsTotal} transcript sections for the requested range.]\n`
|
|
2534
|
+
: ""),
|
|
2535
|
+
},
|
|
2536
|
+
],
|
|
2537
|
+
};
|
|
2538
|
+
}
|
|
2539
|
+
catch (e) {
|
|
2540
|
+
return fail(e.message);
|
|
2541
|
+
}
|
|
2542
|
+
});
|
|
2369
2543
|
async function main() {
|
|
2370
2544
|
const transport = new StdioServerTransport();
|
|
2371
2545
|
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipy/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"mcpName": "online.clipy/mcp",
|
|
5
5
|
"description": "Model Context Protocol (MCP) server for Clipy — give Claude, Cursor, and other AI agents read access to your screen recordings' transcripts, AI summaries, and key moments with frames.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc",
|
|
34
34
|
"prepublishOnly": "npm run build",
|
|
35
|
-
"start": "node dist/index.js"
|
|
35
|
+
"start": "node dist/index.js",
|
|
36
|
+
"test": "npm run build && node scripts/arec-range.test.mjs"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@modelcontextprotocol/sdk": "^1.12.0",
|