@mindstone/mcp-server-runway 0.3.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/LICENSE +97 -0
- package/README.md +119 -0
- package/dist/auth.d.ts +21 -0
- package/dist/auth.js +29 -0
- package/dist/bridge.d.ts +16 -0
- package/dist/bridge.js +43 -0
- package/dist/client.d.ts +82 -0
- package/dist/client.js +562 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +30 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +20 -0
- package/dist/tools/account.d.ts +3 -0
- package/dist/tools/account.js +71 -0
- package/dist/tools/audio.d.ts +3 -0
- package/dist/tools/audio.js +138 -0
- package/dist/tools/configure.d.ts +3 -0
- package/dist/tools/configure.js +46 -0
- package/dist/tools/image.d.ts +3 -0
- package/dist/tools/image.js +52 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/tasks.d.ts +3 -0
- package/dist/tools/tasks.js +370 -0
- package/dist/tools/video.d.ts +3 -0
- package/dist/tools/video.js +168 -0
- package/dist/tools/voices.d.ts +3 -0
- package/dist/tools/voices.js +85 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.js +123 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +42 -0
- package/package.json +54 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { runwayFetch, runwayRawFetch, validateDownloadUrl, assertDownloadPathInRoot } from '../client.js';
|
|
3
|
+
import { RunwayError } from '../types.js';
|
|
4
|
+
import { withErrorHandling } from '../utils.js';
|
|
5
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
6
|
+
export function registerTaskTools(server) {
|
|
7
|
+
// ── Check Task ────────────────────────────────────────────────────────
|
|
8
|
+
server.registerTool('check_runway_task', {
|
|
9
|
+
description: 'Check the status of any Runway generation task. ' +
|
|
10
|
+
'STATUS VALUES: PENDING → THROTTLED → RUNNING → SUCCEEDED (output URLs) or FAILED. ' +
|
|
11
|
+
'TIP: Use wait_for_runway_task for automatic polling.',
|
|
12
|
+
inputSchema: z.object({
|
|
13
|
+
task_id: z.string().describe('Task ID from any generate_* tool.'),
|
|
14
|
+
}),
|
|
15
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
|
|
16
|
+
}, withErrorHandling(async (args) => {
|
|
17
|
+
const result = await runwayFetch(`/tasks/${args.task_id}`);
|
|
18
|
+
const response = {
|
|
19
|
+
ok: true, task_id: result.id, status: result.status, created_at: result.createdAt,
|
|
20
|
+
};
|
|
21
|
+
if (result.status === 'PENDING' || result.status === 'THROTTLED') {
|
|
22
|
+
response.message = `Task ${result.status.toLowerCase()}. Poll again in 15 seconds.`;
|
|
23
|
+
}
|
|
24
|
+
else if (result.status === 'RUNNING') {
|
|
25
|
+
response.message = 'Generation in progress. Poll again in 20 seconds.';
|
|
26
|
+
}
|
|
27
|
+
else if (result.status === 'SUCCEEDED' && result.output?.length) {
|
|
28
|
+
response.output = result.output;
|
|
29
|
+
response.message = 'Generation complete! Output URLs are ready.';
|
|
30
|
+
}
|
|
31
|
+
else if (result.status === 'FAILED') {
|
|
32
|
+
response.ok = false;
|
|
33
|
+
response.error = result.failure || 'Generation failed.';
|
|
34
|
+
response.failure_code = result.failureCode;
|
|
35
|
+
}
|
|
36
|
+
return JSON.stringify(response);
|
|
37
|
+
}));
|
|
38
|
+
// ── Wait for Task ─────────────────────────────────────────────────────
|
|
39
|
+
server.registerTool('wait_for_runway_task', {
|
|
40
|
+
description: 'Submit a task ID and wait for it to complete. Polls automatically. ' +
|
|
41
|
+
'Returns the final task result including output URLs when successful.',
|
|
42
|
+
inputSchema: z.object({
|
|
43
|
+
task_id: z.string().describe('Task ID from any generate_* tool.'),
|
|
44
|
+
poll_interval: z.number().optional().describe('Seconds between polls. Default: 15. Min: 5.'),
|
|
45
|
+
timeout: z.number().optional().describe('Max seconds to wait. Default: 300 (5 min). Max: 600.'),
|
|
46
|
+
}),
|
|
47
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
|
|
48
|
+
}, withErrorHandling(async (args) => {
|
|
49
|
+
const pollInterval = Math.max(5, args.poll_interval || 15) * 1000;
|
|
50
|
+
const timeout = Math.min(600, Math.max(30, args.timeout || 300)) * 1000;
|
|
51
|
+
const taskId = args.task_id;
|
|
52
|
+
const startTime = Date.now();
|
|
53
|
+
const maxTransientErrors = 3;
|
|
54
|
+
let transientErrors = 0;
|
|
55
|
+
while (Date.now() - startTime < timeout) {
|
|
56
|
+
let result;
|
|
57
|
+
try {
|
|
58
|
+
result = await runwayFetch(`/tasks/${taskId}`);
|
|
59
|
+
transientErrors = 0;
|
|
60
|
+
}
|
|
61
|
+
catch (pollErr) {
|
|
62
|
+
transientErrors++;
|
|
63
|
+
if (transientErrors >= maxTransientErrors)
|
|
64
|
+
throw pollErr;
|
|
65
|
+
await sleep(pollInterval);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (result.status === 'SUCCEEDED') {
|
|
69
|
+
return JSON.stringify({
|
|
70
|
+
ok: true, task_id: result.id, status: 'SUCCEEDED',
|
|
71
|
+
output: result.output, created_at: result.createdAt,
|
|
72
|
+
elapsed_seconds: Math.round((Date.now() - startTime) / 1000),
|
|
73
|
+
message: 'Generation complete! Output URLs are ready. Use download_runway_output to save locally.',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (result.status === 'FAILED') {
|
|
77
|
+
return JSON.stringify({
|
|
78
|
+
ok: false, task_id: result.id, status: 'FAILED',
|
|
79
|
+
error: result.failure || 'Generation failed.', failure_code: result.failureCode,
|
|
80
|
+
elapsed_seconds: Math.round((Date.now() - startTime) / 1000),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
await sleep(pollInterval);
|
|
84
|
+
}
|
|
85
|
+
return JSON.stringify({
|
|
86
|
+
ok: false, task_id: taskId, status: 'TIMEOUT',
|
|
87
|
+
error: `Task did not complete within ${timeout / 1000}s. It may still be running — check with check_runway_task.`,
|
|
88
|
+
elapsed_seconds: Math.round((Date.now() - startTime) / 1000),
|
|
89
|
+
});
|
|
90
|
+
}));
|
|
91
|
+
// ── Cancel/Delete Task ────────────────────────────────────────────────
|
|
92
|
+
server.registerTool('cancel_runway_task', {
|
|
93
|
+
description: 'Cancel a pending/running task or delete a completed task. Saves credits if cancelled before completion.',
|
|
94
|
+
inputSchema: z.object({
|
|
95
|
+
task_id: z.string().describe('Task ID to cancel or delete.'),
|
|
96
|
+
}),
|
|
97
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
98
|
+
}, withErrorHandling(async (args) => {
|
|
99
|
+
const cancelRes = await runwayRawFetch(`/tasks/${args.task_id}`, { method: 'DELETE' });
|
|
100
|
+
if (!cancelRes.ok && cancelRes.status !== 204) {
|
|
101
|
+
throw new RunwayError(`Failed to cancel task (HTTP ${cancelRes.status})`, `HTTP_${cancelRes.status}`, 'Check the task ID and try again.');
|
|
102
|
+
}
|
|
103
|
+
return JSON.stringify({ ok: true, message: `Task ${args.task_id} cancelled/deleted.` });
|
|
104
|
+
}));
|
|
105
|
+
// ── Download Output ───────────────────────────────────────────────────
|
|
106
|
+
server.registerTool('download_runway_output', {
|
|
107
|
+
description: 'Download a Runway output (video, image, audio) to a local file. ' +
|
|
108
|
+
'Use after a task succeeds to save the output locally. ' +
|
|
109
|
+
'output_path MUST live inside RUNWAY_DOWNLOAD_ROOT (default ~/Downloads/runway-mcp). ' +
|
|
110
|
+
'Sensitive paths (~/.ssh, ~/.aws, /etc, ~/.bashrc, ~/.zshrc) are refused even when the root would otherwise permit them. ' +
|
|
111
|
+
'By default, refuses to overwrite an existing file (atomic flags: "wx") — pass overwrite: true to clobber.',
|
|
112
|
+
inputSchema: z.object({
|
|
113
|
+
url: z.string().describe('Output URL from a completed task.'),
|
|
114
|
+
output_path: z.string().describe('Local file path to save to. Must be inside RUNWAY_DOWNLOAD_ROOT (default ~/Downloads/runway-mcp). Parent directory must exist.'),
|
|
115
|
+
overwrite: z.boolean().optional().describe('If true, replace an existing file at output_path. Defaults to false (refuses to clobber).'),
|
|
116
|
+
}),
|
|
117
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
118
|
+
}, withErrorHandling(async (args) => {
|
|
119
|
+
const url = args.url;
|
|
120
|
+
const outputPath = args.output_path;
|
|
121
|
+
const overwrite = args.overwrite === true;
|
|
122
|
+
// Validate URL (SSRF prevention — blocks private/reserved hosts)
|
|
123
|
+
const urlError = validateDownloadUrl(url);
|
|
124
|
+
if (urlError) {
|
|
125
|
+
return JSON.stringify({ ok: false, error: urlError });
|
|
126
|
+
}
|
|
127
|
+
// Sandbox the output path BEFORE any network call. This catches:
|
|
128
|
+
// - paths outside RUNWAY_DOWNLOAD_ROOT,
|
|
129
|
+
// - `..` traversal,
|
|
130
|
+
// - symlink-escape on the parent directory,
|
|
131
|
+
// - sensitive deny-list (~/.ssh, ~/.aws, /etc, ~/.bashrc, ~/.zshrc)
|
|
132
|
+
// even when the configured root would otherwise allow it.
|
|
133
|
+
const fs = await import('fs');
|
|
134
|
+
let safe;
|
|
135
|
+
try {
|
|
136
|
+
safe = assertDownloadPathInRoot(outputPath);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (err instanceof RunwayError) {
|
|
140
|
+
return JSON.stringify({
|
|
141
|
+
ok: false,
|
|
142
|
+
error: err.message,
|
|
143
|
+
code: err.code,
|
|
144
|
+
resolution: err.resolution,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
// Open the output file synchronously with `wx` (or `w` if overwrite)
|
|
150
|
+
// so the EEXIST refusal is atomic with the open. createWriteStream
|
|
151
|
+
// with `flags: 'wx'` would also work, but doing this synchronously
|
|
152
|
+
// gives us a clean refusal BEFORE we issue any network request.
|
|
153
|
+
const writeFlag = overwrite ? 'w' : 'wx';
|
|
154
|
+
let fd;
|
|
155
|
+
try {
|
|
156
|
+
fd = fs.openSync(safe.resolved, writeFlag);
|
|
157
|
+
}
|
|
158
|
+
catch (openErr) {
|
|
159
|
+
const e = openErr;
|
|
160
|
+
if (e && e.code === 'EEXIST') {
|
|
161
|
+
return JSON.stringify({
|
|
162
|
+
ok: false,
|
|
163
|
+
error: `Output file already exists: ${outputPath}. Pass overwrite: true to clobber.`,
|
|
164
|
+
code: 'EEXIST',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return JSON.stringify({
|
|
168
|
+
ok: false,
|
|
169
|
+
error: `Could not open output_path for writing: ${e?.message || String(openErr)}`,
|
|
170
|
+
code: e?.code || 'OPEN_FAILED',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// SSRF-via-redirect defence:
|
|
174
|
+
// * Pass `redirect: 'manual'` so the runtime never silently follows a
|
|
175
|
+
// 3xx hop (a public HTTPS host could otherwise redirect to
|
|
176
|
+
// `https://169.254.169.254/...` or `https://127.0.0.1/...` and
|
|
177
|
+
// exfiltrate internal data).
|
|
178
|
+
// * On a 3xx, re-validate the `Location` header against the same
|
|
179
|
+
// private-IP / non-HTTPS allow-list (`validateDownloadUrl`) before
|
|
180
|
+
// issuing the next fetch.
|
|
181
|
+
// * Cap the redirect chain depth to MAX_REDIRECTS.
|
|
182
|
+
const MAX_REDIRECTS = 5;
|
|
183
|
+
// Track ownership of the just-opened fd. The fd is "released" once
|
|
184
|
+
// we hand it off to `fs.createWriteStream({ fd })` — after that point
|
|
185
|
+
// the stream owns it and will close it on `end`/`destroy`. Until
|
|
186
|
+
// then, ANY thrown exception (network failure on `fetch`, abort on
|
|
187
|
+
// the body iterator, etc.) must close the fd and unlink the freshly
|
|
188
|
+
// created (wx-flagged) file so the caller's failure is atomic.
|
|
189
|
+
let fdReleased = false;
|
|
190
|
+
let bytesWritten = 0;
|
|
191
|
+
try {
|
|
192
|
+
let response;
|
|
193
|
+
let currentUrl = url;
|
|
194
|
+
let redirectCount = 0;
|
|
195
|
+
let redirectError = null;
|
|
196
|
+
// eslint-disable-next-line no-constant-condition
|
|
197
|
+
while (true) {
|
|
198
|
+
response = await fetch(currentUrl, { redirect: 'manual' });
|
|
199
|
+
if (response.status >= 300 && response.status < 400) {
|
|
200
|
+
// Drain the redirect body so the connection isn't held open.
|
|
201
|
+
try {
|
|
202
|
+
await response.body?.cancel();
|
|
203
|
+
}
|
|
204
|
+
catch { /* best-effort */ }
|
|
205
|
+
redirectCount++;
|
|
206
|
+
if (redirectCount > MAX_REDIRECTS) {
|
|
207
|
+
redirectError = `Refused to follow redirect: too many redirects (>${MAX_REDIRECTS}).`;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
const location = response.headers.get('location');
|
|
211
|
+
if (!location) {
|
|
212
|
+
redirectError = 'Redirect response missing Location header.';
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
let nextUrl;
|
|
216
|
+
try {
|
|
217
|
+
nextUrl = new URL(location, currentUrl).toString();
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
redirectError = `Refused to follow redirect: invalid Location header (${location}).`;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
// Re-apply the same SSRF allow-list to every redirect target.
|
|
224
|
+
const validationError = validateDownloadUrl(nextUrl);
|
|
225
|
+
if (validationError) {
|
|
226
|
+
redirectError = `Refused to follow redirect to ${nextUrl}: ${validationError}`;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
currentUrl = nextUrl;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
if (redirectError) {
|
|
235
|
+
try {
|
|
236
|
+
fs.closeSync(fd);
|
|
237
|
+
}
|
|
238
|
+
catch { /* empty */ }
|
|
239
|
+
fdReleased = true;
|
|
240
|
+
try {
|
|
241
|
+
fs.unlinkSync(safe.resolved);
|
|
242
|
+
}
|
|
243
|
+
catch { /* cleanup best-effort */ }
|
|
244
|
+
return JSON.stringify({ ok: false, error: redirectError });
|
|
245
|
+
}
|
|
246
|
+
if (!response.ok) {
|
|
247
|
+
try {
|
|
248
|
+
fs.closeSync(fd);
|
|
249
|
+
}
|
|
250
|
+
catch { /* empty */ }
|
|
251
|
+
fdReleased = true;
|
|
252
|
+
try {
|
|
253
|
+
fs.unlinkSync(safe.resolved);
|
|
254
|
+
}
|
|
255
|
+
catch { /* cleanup best-effort */ }
|
|
256
|
+
return JSON.stringify({ ok: false, error: `Download failed (HTTP ${response.status}). The URL may have expired.` });
|
|
257
|
+
}
|
|
258
|
+
if (!response.body) {
|
|
259
|
+
try {
|
|
260
|
+
fs.closeSync(fd);
|
|
261
|
+
}
|
|
262
|
+
catch { /* empty */ }
|
|
263
|
+
fdReleased = true;
|
|
264
|
+
try {
|
|
265
|
+
fs.unlinkSync(safe.resolved);
|
|
266
|
+
}
|
|
267
|
+
catch { /* cleanup best-effort */ }
|
|
268
|
+
return JSON.stringify({ ok: false, error: 'No response body received.' });
|
|
269
|
+
}
|
|
270
|
+
// Hand the open fd to a write stream (avoids re-opening with default
|
|
271
|
+
// `w` and so preserves the wx semantics of our pre-check).
|
|
272
|
+
const fileHandle = fs.createWriteStream(safe.resolved, { fd });
|
|
273
|
+
fdReleased = true; // fd ownership transferred to the stream
|
|
274
|
+
try {
|
|
275
|
+
for await (const chunk of response.body) {
|
|
276
|
+
fileHandle.write(chunk);
|
|
277
|
+
bytesWritten += chunk.length;
|
|
278
|
+
}
|
|
279
|
+
fileHandle.end();
|
|
280
|
+
await new Promise((resolve, reject) => {
|
|
281
|
+
fileHandle.on('finish', resolve);
|
|
282
|
+
fileHandle.on('error', reject);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
catch (streamErr) {
|
|
286
|
+
fileHandle.destroy();
|
|
287
|
+
try {
|
|
288
|
+
fs.unlinkSync(safe.resolved);
|
|
289
|
+
}
|
|
290
|
+
catch { /* cleanup best-effort */ }
|
|
291
|
+
throw streamErr;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
// Resource hygiene: if anything between `fs.openSync` and the
|
|
296
|
+
// `createWriteStream` hand-off threw (e.g. `fetch` rejecting with
|
|
297
|
+
// a network error), close the fd we own and unlink the freshly
|
|
298
|
+
// created file so the failure is atomic.
|
|
299
|
+
if (!fdReleased) {
|
|
300
|
+
try {
|
|
301
|
+
fs.closeSync(fd);
|
|
302
|
+
}
|
|
303
|
+
catch { /* empty */ }
|
|
304
|
+
try {
|
|
305
|
+
fs.unlinkSync(safe.resolved);
|
|
306
|
+
}
|
|
307
|
+
catch { /* cleanup best-effort */ }
|
|
308
|
+
}
|
|
309
|
+
throw err;
|
|
310
|
+
}
|
|
311
|
+
const sizeMB = (bytesWritten / 1_048_576).toFixed(1);
|
|
312
|
+
// Use the user-supplied (lexical) path in the user-facing response so
|
|
313
|
+
// the path the LLM/user sees matches the path they passed. The actual
|
|
314
|
+
// open/write happens against `safe.resolved` (the realpath-canonical
|
|
315
|
+
// target), which is what enforced the sandbox.
|
|
316
|
+
return JSON.stringify({
|
|
317
|
+
ok: true, path: outputPath, size_mb: sizeMB,
|
|
318
|
+
message: `Downloaded ${sizeMB}MB to ${outputPath}`,
|
|
319
|
+
});
|
|
320
|
+
}));
|
|
321
|
+
// ── Upload Media ──────────────────────────────────────────────────────
|
|
322
|
+
server.registerTool('upload_media', {
|
|
323
|
+
description: 'Upload a local file to Runway\'s ephemeral storage, returning a runway:// URI. ' +
|
|
324
|
+
'Supports files up to 200MB. URI valid for 24 hours.',
|
|
325
|
+
inputSchema: z.object({
|
|
326
|
+
file_path: z.string().describe('Absolute path to the local file to upload.'),
|
|
327
|
+
}),
|
|
328
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
329
|
+
}, withErrorHandling(async (args) => {
|
|
330
|
+
const fs = await import('fs');
|
|
331
|
+
const filePath = args.file_path;
|
|
332
|
+
// Defence-in-depth: defer to uploadEphemeral, which performs the
|
|
333
|
+
// RUNWAY_ALLOWED_ROOT sandbox check (via assertPathInAllowedRoot)
|
|
334
|
+
// BEFORE any file read or upstream API call. The pre-existing
|
|
335
|
+
// existsSync / size guards remain so non-sandbox failures keep
|
|
336
|
+
// their familiar shapes (e.g. "File not found" for inside-the-root
|
|
337
|
+
// missing paths). To avoid the size / not-found guards firing
|
|
338
|
+
// BEFORE the sandbox check (which would mask a sandbox violation),
|
|
339
|
+
// run the sandbox check first via uploadEphemeral's internals.
|
|
340
|
+
const { assertPathInAllowedRoot, uploadEphemeral } = await import('../client.js');
|
|
341
|
+
let safePath;
|
|
342
|
+
try {
|
|
343
|
+
safePath = assertPathInAllowedRoot(filePath);
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'PATH_OUTSIDE_ALLOWED_ROOT') {
|
|
347
|
+
const e = err;
|
|
348
|
+
return JSON.stringify({ ok: false, error: e.message, code: e.code, resolution: e.resolution });
|
|
349
|
+
}
|
|
350
|
+
throw err;
|
|
351
|
+
}
|
|
352
|
+
if (!fs.existsSync(safePath)) {
|
|
353
|
+
return JSON.stringify({ ok: false, error: `File not found: ${filePath}` });
|
|
354
|
+
}
|
|
355
|
+
const stats = fs.statSync(safePath);
|
|
356
|
+
if (stats.size > 200 * 1_048_576) {
|
|
357
|
+
return JSON.stringify({ ok: false, error: 'File exceeds 200MB limit.' });
|
|
358
|
+
}
|
|
359
|
+
if (stats.size < 512) {
|
|
360
|
+
return JSON.stringify({ ok: false, error: 'File must be at least 512 bytes.' });
|
|
361
|
+
}
|
|
362
|
+
const uri = await uploadEphemeral(safePath);
|
|
363
|
+
const sizeMB = (stats.size / 1_048_576).toFixed(1);
|
|
364
|
+
return JSON.stringify({
|
|
365
|
+
ok: true, runway_uri: uri, size_mb: sizeMB,
|
|
366
|
+
message: `Uploaded ${sizeMB}MB. URI valid for 24 hours. Use this URI in any generation tool: ${uri}`,
|
|
367
|
+
});
|
|
368
|
+
}));
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { runwayFetch, resolveMediaInput, costEstimate, addContentModeration } from '../client.js';
|
|
3
|
+
import { withErrorHandling } from '../utils.js';
|
|
4
|
+
export function registerVideoTools(server) {
|
|
5
|
+
// ── Image-to-Video ────────────────────────────────────────────────────
|
|
6
|
+
server.registerTool('generate_video_from_image', {
|
|
7
|
+
description: 'Animate a still image into a video. Supports first-frame (and optionally last-frame) keyframe control. ' +
|
|
8
|
+
'MODELS: gen4.5 (flagship), gen4_turbo (fast/cheap), gen3a_turbo (legacy), veo3.1 (best quality + audio), veo3.1_fast, veo3. ' +
|
|
9
|
+
'WORKFLOW: Returns task_id → poll with check_runway_task or use wait_for_runway_task.',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
prompt_image: z.string().describe('First frame image. HTTPS URL, Runway URI, or local file path.'),
|
|
12
|
+
last_frame_image: z.string().optional().describe('Optional last frame image for transition.'),
|
|
13
|
+
prompt_text: z.string().optional().describe('Describe the desired motion.'),
|
|
14
|
+
model: z.enum(['gen4.5', 'gen4_turbo', 'gen3a_turbo', 'veo3.1', 'veo3.1_fast', 'veo3']).optional().describe('Default: gen4_turbo.'),
|
|
15
|
+
ratio: z.enum(['1280:720', '720:1280', '960:960', '1104:832', '832:1104', '1584:672']).optional().describe('Output resolution. Default: 1280:720.'),
|
|
16
|
+
duration: z.number().optional().describe('Seconds. gen4: 2-10 (default 5). veo: 4,6,8 (default 8).'),
|
|
17
|
+
audio: z.boolean().optional().describe('Generate audio (veo models only). Default: true.'),
|
|
18
|
+
content_moderation: z.enum(['auto', 'low']).optional().describe('Public figure threshold.'),
|
|
19
|
+
seed: z.number().int().optional().describe('Random seed (0-4294967295) for reproducibility.'),
|
|
20
|
+
}),
|
|
21
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
22
|
+
}, withErrorHandling(async (args) => {
|
|
23
|
+
const model = args.model || 'gen4_turbo';
|
|
24
|
+
const isRunwayModel = ['gen4.5', 'gen4_turbo', 'gen3a_turbo'].includes(model);
|
|
25
|
+
const ratio = args.ratio || '1280:720';
|
|
26
|
+
const duration = args.duration || (isRunwayModel ? 5 : 8);
|
|
27
|
+
const audio = args.audio;
|
|
28
|
+
const seed = args.seed;
|
|
29
|
+
const firstImage = await resolveMediaInput(args.prompt_image, 'image');
|
|
30
|
+
let promptImage;
|
|
31
|
+
if (args.last_frame_image) {
|
|
32
|
+
const lastImage = await resolveMediaInput(args.last_frame_image, 'image');
|
|
33
|
+
promptImage = [
|
|
34
|
+
{ uri: firstImage, position: 'first' },
|
|
35
|
+
{ uri: lastImage, position: 'last' },
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
promptImage = firstImage;
|
|
40
|
+
}
|
|
41
|
+
const body = { model, promptImage, ratio, duration };
|
|
42
|
+
if (args.prompt_text)
|
|
43
|
+
body.promptText = args.prompt_text;
|
|
44
|
+
if (audio !== undefined && !isRunwayModel)
|
|
45
|
+
body.audio = audio;
|
|
46
|
+
if (seed !== undefined)
|
|
47
|
+
body.seed = seed;
|
|
48
|
+
addContentModeration(body, args.content_moderation);
|
|
49
|
+
const result = await runwayFetch('/image_to_video', { method: 'POST', body: JSON.stringify(body) });
|
|
50
|
+
const est = costEstimate(model, duration, audio);
|
|
51
|
+
return JSON.stringify({
|
|
52
|
+
ok: true, task_id: result.id, status: 'PENDING', model, duration,
|
|
53
|
+
estimated_credits: est.credits, estimated_cost: est.usd,
|
|
54
|
+
keyframes: args.last_frame_image ? 'first+last' : 'first',
|
|
55
|
+
message: `Image-to-video started (${model}, ${duration}s). Poll with check_runway_task("${result.id}") every 30s, or use wait_for_runway_task.`,
|
|
56
|
+
});
|
|
57
|
+
}));
|
|
58
|
+
// ── Text-to-Video ─────────────────────────────────────────────────────
|
|
59
|
+
server.registerTool('generate_video_from_text', {
|
|
60
|
+
description: 'Create a video entirely from a text description. ' +
|
|
61
|
+
'MODELS: gen4.5 (flagship), veo3.1 (best + audio), veo3.1_fast, veo3. ' +
|
|
62
|
+
'WORKFLOW: Returns task_id → poll or use wait_for_runway_task.',
|
|
63
|
+
inputSchema: z.object({
|
|
64
|
+
prompt_text: z.string().describe('Detailed video description. Max 1000 chars.'),
|
|
65
|
+
model: z.enum(['gen4.5', 'veo3.1', 'veo3.1_fast', 'veo3']).optional().describe('Default: gen4.5.'),
|
|
66
|
+
ratio: z.enum(['1280:720', '720:1280']).optional().describe('Output resolution. Default: 1280:720.'),
|
|
67
|
+
duration: z.number().optional().describe('Seconds. gen4.5: 2-10 (default 5). veo: 4,6,8 (default 8).'),
|
|
68
|
+
audio: z.boolean().optional().describe('Generate audio (veo models only). Default: true.'),
|
|
69
|
+
content_moderation: z.enum(['auto', 'low']).optional().describe('Public figure threshold.'),
|
|
70
|
+
seed: z.number().int().optional().describe('Random seed (0-4294967295).'),
|
|
71
|
+
}),
|
|
72
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
73
|
+
}, withErrorHandling(async (args) => {
|
|
74
|
+
const model = args.model || 'gen4.5';
|
|
75
|
+
const isGen45 = model === 'gen4.5';
|
|
76
|
+
const ratio = args.ratio || '1280:720';
|
|
77
|
+
const duration = args.duration || (isGen45 ? 5 : 8);
|
|
78
|
+
const audio = args.audio !== false;
|
|
79
|
+
const seed = args.seed;
|
|
80
|
+
const body = { model, promptText: args.prompt_text, ratio, duration };
|
|
81
|
+
if (!isGen45)
|
|
82
|
+
body.audio = audio;
|
|
83
|
+
if (seed !== undefined)
|
|
84
|
+
body.seed = seed;
|
|
85
|
+
addContentModeration(body, args.content_moderation);
|
|
86
|
+
const result = await runwayFetch('/text_to_video', { method: 'POST', body: JSON.stringify(body) });
|
|
87
|
+
const est = costEstimate(model, duration, audio);
|
|
88
|
+
return JSON.stringify({
|
|
89
|
+
ok: true, task_id: result.id, status: 'PENDING', model, duration, audio,
|
|
90
|
+
estimated_credits: est.credits, estimated_cost: est.usd,
|
|
91
|
+
message: `Text-to-video started (${model}, ${duration}s, audio=${audio}). Poll with check_runway_task("${result.id}") every 30s, or use wait_for_runway_task.`,
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
// ── Video-to-Video ────────────────────────────────────────────────────
|
|
95
|
+
server.registerTool('generate_video_from_video', {
|
|
96
|
+
description: 'Re-style or transform an existing video using Gen-4 Aleph. ' +
|
|
97
|
+
'MODEL: gen4_aleph (only option). 15 credits/sec. ' +
|
|
98
|
+
'WORKFLOW: Returns task_id → poll or use wait_for_runway_task.',
|
|
99
|
+
inputSchema: z.object({
|
|
100
|
+
video: z.string().describe('Source video. HTTPS URL, Runway URI, or local file path.'),
|
|
101
|
+
prompt_text: z.string().describe('Describe the transformation.'),
|
|
102
|
+
reference_image: z.string().optional().describe('Optional style reference image.'),
|
|
103
|
+
content_moderation: z.enum(['auto', 'low']).optional().describe('Public figure threshold.'),
|
|
104
|
+
seed: z.number().int().optional().describe('Random seed (0-4294967295).'),
|
|
105
|
+
}),
|
|
106
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
107
|
+
}, withErrorHandling(async (args) => {
|
|
108
|
+
const videoUri = await resolveMediaInput(args.video, 'video');
|
|
109
|
+
const seed = args.seed;
|
|
110
|
+
const body = { model: 'gen4_aleph', videoUri, promptText: args.prompt_text };
|
|
111
|
+
if (seed !== undefined)
|
|
112
|
+
body.seed = seed;
|
|
113
|
+
if (args.reference_image) {
|
|
114
|
+
body.references = [{ type: 'image', uri: await resolveMediaInput(args.reference_image, 'image') }];
|
|
115
|
+
}
|
|
116
|
+
addContentModeration(body, args.content_moderation);
|
|
117
|
+
const result = await runwayFetch('/video_to_video', { method: 'POST', body: JSON.stringify(body) });
|
|
118
|
+
return JSON.stringify({
|
|
119
|
+
ok: true, task_id: result.id, status: 'PENDING', model: 'gen4_aleph',
|
|
120
|
+
cost_rate: '15 credits/sec ($0.15/sec)',
|
|
121
|
+
message: `Video-to-video started (gen4_aleph). Poll with check_runway_task("${result.id}") every 30s, or use wait_for_runway_task.`,
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
// ── Character Performance ─────────────────────────────────────────────
|
|
125
|
+
server.registerTool('character_performance', {
|
|
126
|
+
description: 'Animate a character with facial expressions and body movements from a reference performance video (Act-Two). ' +
|
|
127
|
+
'MODEL: act_two. 5 credits/sec. Output duration matches reference video length. ' +
|
|
128
|
+
'WORKFLOW: Returns task_id → poll or use wait_for_runway_task.',
|
|
129
|
+
inputSchema: z.object({
|
|
130
|
+
character: z.string().describe('Character to animate. HTTPS URL or local file path.'),
|
|
131
|
+
reference_video: z.string().describe('Performance video (3-30s). HTTPS URL or local file.'),
|
|
132
|
+
character_type: z.enum(['image', 'video']).optional().describe('Whether character input is image or video. Default: image.'),
|
|
133
|
+
body_control: z.boolean().optional().describe('Enable body movement control. Default: false.'),
|
|
134
|
+
expression_intensity: z.number().int().optional().describe('Expression intensity 1-5. Default: 3.'),
|
|
135
|
+
ratio: z.enum(['1280:720', '720:1280', '960:960', '1104:832', '832:1104', '1584:672']).optional().describe('Output resolution.'),
|
|
136
|
+
content_moderation: z.enum(['auto', 'low']).optional().describe('Public figure threshold.'),
|
|
137
|
+
seed: z.number().int().optional().describe('Random seed (0-4294967295).'),
|
|
138
|
+
}),
|
|
139
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
140
|
+
}, withErrorHandling(async (args) => {
|
|
141
|
+
const charType = args.character_type || 'image';
|
|
142
|
+
const charCategory = charType === 'video' ? 'video' : 'image';
|
|
143
|
+
const characterUri = await resolveMediaInput(args.character, charCategory);
|
|
144
|
+
const referenceUri = await resolveMediaInput(args.reference_video, 'video');
|
|
145
|
+
const seed = args.seed;
|
|
146
|
+
const body = {
|
|
147
|
+
model: 'act_two',
|
|
148
|
+
character: { type: charType, uri: characterUri },
|
|
149
|
+
reference: { type: 'video', uri: referenceUri },
|
|
150
|
+
};
|
|
151
|
+
if (args.body_control !== undefined)
|
|
152
|
+
body.bodyControl = args.body_control;
|
|
153
|
+
if (args.expression_intensity !== undefined)
|
|
154
|
+
body.expressionIntensity = args.expression_intensity;
|
|
155
|
+
if (args.ratio)
|
|
156
|
+
body.ratio = args.ratio;
|
|
157
|
+
if (seed !== undefined)
|
|
158
|
+
body.seed = seed;
|
|
159
|
+
addContentModeration(body, args.content_moderation);
|
|
160
|
+
const result = await runwayFetch('/character_performance', { method: 'POST', body: JSON.stringify(body) });
|
|
161
|
+
return JSON.stringify({
|
|
162
|
+
ok: true, task_id: result.id, status: 'PENDING', model: 'act_two',
|
|
163
|
+
cost_rate: '5 credits/sec ($0.05/sec)',
|
|
164
|
+
message: `Character performance started (act_two). Poll with check_runway_task("${result.id}") every 30s, or use wait_for_runway_task.`,
|
|
165
|
+
});
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=video.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { runwayFetch, runwayRawFetch } from '../client.js';
|
|
3
|
+
import { RunwayError } from '../types.js';
|
|
4
|
+
import { withErrorHandling } from '../utils.js';
|
|
5
|
+
export function registerVoiceTools(server) {
|
|
6
|
+
// ── List Custom Voices ────────────────────────────────────────────────
|
|
7
|
+
server.registerTool('list_custom_voices', {
|
|
8
|
+
description: 'List all custom voices you\'ve created. Returns voice IDs, names, descriptions, and status. ' +
|
|
9
|
+
'Use the voice ID with generate_speech.',
|
|
10
|
+
inputSchema: z.object({}),
|
|
11
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
|
|
12
|
+
}, withErrorHandling(async () => {
|
|
13
|
+
const result = await runwayFetch('/voices');
|
|
14
|
+
const voices = result.data.map(v => ({
|
|
15
|
+
id: v.id, name: v.name, description: v.description || '', status: v.status, created: v.createdAt,
|
|
16
|
+
}));
|
|
17
|
+
return JSON.stringify({
|
|
18
|
+
ok: true, voices, count: voices.length, has_more: result.hasMore,
|
|
19
|
+
message: voices.length === 0
|
|
20
|
+
? 'No custom voices yet. Create one with create_custom_voice.'
|
|
21
|
+
: `Found ${voices.length} custom voice(s).`,
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
// ── Create Custom Voice ───────────────────────────────────────────────
|
|
25
|
+
server.registerTool('create_custom_voice', {
|
|
26
|
+
description: 'Create a custom voice from a text description of desired voice characteristics. ' +
|
|
27
|
+
'MODELS: eleven_multilingual_ttv_v2 (default), eleven_ttv_v3 (newer). ' +
|
|
28
|
+
'Check status with list_custom_voices. Once READY, use its ID with generate_speech.',
|
|
29
|
+
inputSchema: z.object({
|
|
30
|
+
name: z.string().describe('Name for the voice. Max 100 characters.'),
|
|
31
|
+
prompt: z.string().describe('Text description of desired voice. Min 20, max 1000 characters.'),
|
|
32
|
+
model: z.enum(['eleven_multilingual_ttv_v2', 'eleven_ttv_v3']).optional().describe('Voice design model. Default: eleven_multilingual_ttv_v2.'),
|
|
33
|
+
description: z.string().optional().describe('Optional description for your reference. Max 512 characters.'),
|
|
34
|
+
}),
|
|
35
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
36
|
+
}, withErrorHandling(async (args) => {
|
|
37
|
+
const model = args.model || 'eleven_multilingual_ttv_v2';
|
|
38
|
+
const body = {
|
|
39
|
+
name: args.name,
|
|
40
|
+
from: { type: 'text', prompt: args.prompt, model },
|
|
41
|
+
};
|
|
42
|
+
if (args.description)
|
|
43
|
+
body.description = args.description;
|
|
44
|
+
const result = await runwayFetch('/voices', { method: 'POST', body: JSON.stringify(body) });
|
|
45
|
+
return JSON.stringify({
|
|
46
|
+
ok: true, voice_id: result.id,
|
|
47
|
+
message: `Custom voice "${args.name}" created (ID: ${result.id}). It may take a few seconds to process. Check status with list_custom_voices.`,
|
|
48
|
+
});
|
|
49
|
+
}));
|
|
50
|
+
// ── Preview Voice ─────────────────────────────────────────────────────
|
|
51
|
+
server.registerTool('preview_voice', {
|
|
52
|
+
description: 'Generate a short audio preview of a voice from a text description, without creating it. ' +
|
|
53
|
+
'Use to audition voice characteristics before committing with create_custom_voice.',
|
|
54
|
+
inputSchema: z.object({
|
|
55
|
+
prompt: z.string().describe('Text description of desired voice. Min 20, max 1000 characters.'),
|
|
56
|
+
model: z.enum(['eleven_multilingual_ttv_v2', 'eleven_ttv_v3']).optional().describe('Voice design model. Default: eleven_multilingual_ttv_v2.'),
|
|
57
|
+
}),
|
|
58
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
|
|
59
|
+
}, withErrorHandling(async (args) => {
|
|
60
|
+
const model = args.model || 'eleven_multilingual_ttv_v2';
|
|
61
|
+
const result = await runwayFetch('/voices/preview', {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
body: JSON.stringify({ prompt: args.prompt, model }),
|
|
64
|
+
});
|
|
65
|
+
return JSON.stringify({
|
|
66
|
+
ok: true, preview_url: result.url, duration_seconds: result.durationSecs,
|
|
67
|
+
message: `Voice preview generated (${result.durationSecs}s). Listen at: ${result.url}`,
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
// ── Delete Custom Voice ───────────────────────────────────────────────
|
|
71
|
+
server.registerTool('delete_custom_voice', {
|
|
72
|
+
description: 'Delete a custom voice by ID. This is permanent and cannot be undone.',
|
|
73
|
+
inputSchema: z.object({
|
|
74
|
+
voice_id: z.string().describe('UUID of the voice to delete (from list_custom_voices).'),
|
|
75
|
+
}),
|
|
76
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
|
|
77
|
+
}, withErrorHandling(async (args) => {
|
|
78
|
+
const delRes = await runwayRawFetch(`/voices/${args.voice_id}`, { method: 'DELETE' });
|
|
79
|
+
if (!delRes.ok && delRes.status !== 204) {
|
|
80
|
+
throw new RunwayError(`Failed to delete voice (HTTP ${delRes.status})`, `HTTP_${delRes.status}`, 'Check the voice ID and try again.');
|
|
81
|
+
}
|
|
82
|
+
return JSON.stringify({ ok: true, message: `Voice ${args.voice_id} deleted.` });
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=voices.js.map
|