@raywake/mcp 0.1.0 → 1.0.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/dist/tasks.js ADDED
@@ -0,0 +1,111 @@
1
+ import { ProtocolError, ProtocolErrorCode } from '@modelcontextprotocol/server';
2
+ import { z } from 'zod';
3
+ import { RaywakeError } from './client.js';
4
+ import { errorResult } from './tool-result.js';
5
+ const TASKS_EXTENSION = 'io.modelcontextprotocol/tasks';
6
+ const CLIENT_CAPABILITIES_META_KEY = 'io.modelcontextprotocol/clientCapabilities';
7
+ const failed = new Set(['failed', 'needs_review', 'submission_unknown', 'needs_reconciliation']);
8
+ const CANCEL_MESSAGE = 'Cancellation was acknowledged cooperatively, but the Raywake job could not be stopped; it may still finish and be billed as quoted.';
9
+ // Generations usually run for minutes; a slow poll keeps tasks/get traffic low.
10
+ const POLL_INTERVAL_MS = 10_000;
11
+ const taskIdSchema = z.object({ taskId: z.string().min(1).max(128) });
12
+ function iso(value) {
13
+ const date = typeof value === 'string' || typeof value === 'number' ? new Date(value) : new Date();
14
+ return Number.isNaN(date.getTime()) ? new Date().toISOString() : date.toISOString();
15
+ }
16
+ function statusOf(rawStatus) {
17
+ if (rawStatus === 'succeeded')
18
+ return 'completed';
19
+ if (failed.has(rawStatus))
20
+ return 'failed';
21
+ return 'working';
22
+ }
23
+ function toolResult(data) {
24
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], structuredContent: data };
25
+ }
26
+ // Schema v2 DetailedTask: flat task fields; completed carries the original tools/call result, failed a JSON-RPC error object.
27
+ function detailedTask(job, cancelAcknowledged) {
28
+ const rawStatus = String(job.status ?? 'queued');
29
+ const status = statusOf(rawStatus);
30
+ const base = {
31
+ taskId: String(job.job_id), status,
32
+ createdAt: iso(job.created_at ?? job.createdAt), lastUpdatedAt: iso(job.updated_at ?? job.updatedAt),
33
+ ttlMs: null, pollIntervalMs: POLL_INTERVAL_MS,
34
+ };
35
+ if (cancelAcknowledged)
36
+ base.statusMessage = CANCEL_MESSAGE;
37
+ if (status === 'completed')
38
+ return { ...base, result: toolResult(job) };
39
+ if (status === 'failed') {
40
+ const message = `Raywake job ended as ${rawStatus}.`;
41
+ return { ...base, statusMessage: String(base.statusMessage ?? message), error: { code: -32000, message, data: job } };
42
+ }
43
+ return base;
44
+ }
45
+ function hasTasksExtension(ctx) {
46
+ const envelope = ctx?.mcpReq?.envelope;
47
+ const capabilities = envelope?.[CLIENT_CAPABILITIES_META_KEY];
48
+ return capabilities?.extensions !== undefined && typeof capabilities.extensions === 'object' && TASKS_EXTENSION in capabilities.extensions;
49
+ }
50
+ function isUnknownTask(error) {
51
+ return error instanceof RaywakeError && error.details.http_status === 404;
52
+ }
53
+ export function installTasks(server, client) {
54
+ const mcp = server;
55
+ const cancelAcknowledged = new Set();
56
+ server.server.registerCapabilities({ extensions: { [TASKS_EXTENSION]: {} } });
57
+ server.server.setRequestHandler('tools/call', async (request, ctx) => {
58
+ const tool = mcp._registeredTools[request.params.name];
59
+ if (!tool)
60
+ return mcp.createToolError(`Tool ${request.params.name} not found`);
61
+ try {
62
+ const args = await mcp.validateToolInput(tool, request.params.arguments, request.params.name);
63
+ if (request.params.name === 'generate' && hasTasksExtension(ctx)) {
64
+ const typed = args;
65
+ // The paid POST is the durable creation: the job exists on Raywake before the task result is sent.
66
+ const { job, key } = await client.startGeneration(typed.model, typed.input, typed.quote_id, typed.idempotency_key, Date.now() + 45_000, ctx.mcpReq.signal);
67
+ return {
68
+ resultType: 'task', ...detailedTask(job, false),
69
+ content: [{ type: 'text', text: `Raywake generation task ${job.job_id} created. Poll it with tasks/get; the job continues on Raywake even if this connection closes.` }],
70
+ _meta: { raywake: { idempotency_key: key } },
71
+ };
72
+ }
73
+ const result = await mcp.executeToolHandler(tool, args, ctx);
74
+ if (result.resultType === 'input_required')
75
+ return result;
76
+ await mcp.validateToolOutput(tool, result, request.params.name);
77
+ return server.server.projectCallToolResult(result, tool.outputSchemaJson);
78
+ }
79
+ catch (error) {
80
+ if (error instanceof RaywakeError)
81
+ return errorResult(error);
82
+ return mcp.createToolError(error instanceof Error ? error.message : String(error));
83
+ }
84
+ });
85
+ server.server.setRequestHandler('tasks/get', { params: taskIdSchema }, async (params) => {
86
+ try {
87
+ const job = await client.getJob(params.taskId, 0);
88
+ return detailedTask(job, cancelAcknowledged.has(params.taskId));
89
+ }
90
+ catch (error) {
91
+ if (isUnknownTask(error))
92
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Unknown taskId: ${params.taskId}`);
93
+ throw error;
94
+ }
95
+ });
96
+ server.server.setRequestHandler('tasks/cancel', { params: taskIdSchema }, async (params) => {
97
+ try {
98
+ await client.getJob(params.taskId, 0);
99
+ }
100
+ catch (error) {
101
+ if (isUnknownTask(error))
102
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Unknown taskId: ${params.taskId}`);
103
+ throw error;
104
+ }
105
+ // Cooperative only: Raywake generations cannot be stopped once submitted. The empty ack is
106
+ // schema v2's CancelTaskResult; the honest message rides on later tasks/get responses.
107
+ cancelAcknowledged.add(params.taskId);
108
+ return {};
109
+ });
110
+ }
111
+ //# sourceMappingURL=tasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tasks.js","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAuC,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,eAAe,GAAG,+BAA+B,CAAC;AACxD,MAAM,4BAA4B,GAAG,4CAA4C,CAAC;AAClF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,oBAAoB,EAAE,sBAAsB,CAAC,CAAC,CAAC;AACjG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M,CAAC,MAAM,CAAC,CAAU,CAAC;QAC3E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,aAAa,CAAC,KAAK,CAAC;gBAAE,MAAM,IAAI,aAAa,CAAC,iBAAiB,CAAC,aAAa,EAAE,mBAAmB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YACvH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;IACF,MAAM,CAAC,MAAc,CAAC,iBAAiB,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,MAAW,EAAE,EAAE;QACvG,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,aAAa,CAAC,KAAK,CAAC;gBAAE,MAAM,IAAI,aAAa,CAAC,iBAAiB,CAAC,aAAa,EAAE,mBAAmB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YACvH,MAAM,KAAK,CAAC;QACd,CAAC;QACD,2FAA2F;QAC3F,uFAAuF;QACvF,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,EAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type JsonObject } from './client.js';
2
+ export type ToolErrorResult = {
3
+ content: {
4
+ type: 'text';
5
+ text: string;
6
+ }[];
7
+ structuredContent: JsonObject;
8
+ isError: true;
9
+ };
10
+ export declare function errorResult(error: unknown): ToolErrorResult;
@@ -0,0 +1,6 @@
1
+ import { RaywakeError } from './client.js';
2
+ export function errorResult(error) {
3
+ const data = error instanceof RaywakeError ? { error: error.message, ...error.details } : { error: 'Raywake tool failed. Check the inputs and try again.' };
4
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], structuredContent: data, isError: true };
5
+ }
6
+ //# sourceMappingURL=tool-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result.js","sourceRoot":"","sources":["../src/tool-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmB,MAAM,aAAa,CAAC;AAM5D,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,IAAI,GAAG,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,sDAAsD,EAAE,CAAC;IAC5J,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACtH,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { type Stats } from 'node:fs';
2
+ import { type FileHandle } from 'node:fs/promises';
3
+ export declare const UPLOAD_LIMITS: {
4
+ readonly 'image/jpeg': number;
5
+ readonly 'image/png': number;
6
+ readonly 'image/webp': number;
7
+ readonly 'video/mp4': number;
8
+ readonly 'video/quicktime': number;
9
+ readonly 'video/webm': number;
10
+ readonly 'audio/mpeg': number;
11
+ readonly 'audio/wav': number;
12
+ };
13
+ export type UploadType = keyof typeof UPLOAD_LIMITS;
14
+ export declare const LIMITS_TEXT = "JPEG/PNG/WebP up to 25 MB, MP4/MOV up to 200 MB, WebM up to 100 MB, MP3/WAV up to 50 MB";
15
+ export declare const ROOTS_ENV = "RAYWAKE_UPLOAD_ROOTS";
16
+ export declare class UploadError extends Error {
17
+ readonly code: string;
18
+ constructor(code: string, message: string);
19
+ }
20
+ /** Content type from the file's own first bytes; the extension only breaks MOV/MP4 ties. */
21
+ export declare function detectType(head: Buffer, extension?: string): UploadType | undefined;
22
+ export interface PathPolicy {
23
+ /** Replaces the default roots (home folder and working folder) when set. */
24
+ roots?: string[];
25
+ home?: string;
26
+ cwd?: string;
27
+ }
28
+ /** Parse RAYWAKE_UPLOAD_ROOTS: absolute folders separated by the platform path delimiter. */
29
+ export declare function parseRoots(value: string | undefined, home?: string): string[] | undefined;
30
+ export interface CheckedFile {
31
+ realPath: string;
32
+ name: string;
33
+ extension: string;
34
+ stats: Stats;
35
+ }
36
+ /** Resolve and vet a path without opening the file. */
37
+ export declare function checkPath(raw: string, policy?: PathPolicy): Promise<CheckedFile>;
38
+ export declare function unsupported(): UploadError;
39
+ export declare function tooLarge(type: UploadType, size: number): UploadError;
40
+ export interface OpenedFile extends CheckedFile {
41
+ handle: FileHandle;
42
+ contentType: UploadType;
43
+ size: number;
44
+ }
45
+ /** Open the vetted file, confirm it is the same file, and identify it from its first bytes. */
46
+ export declare function openMedia(raw: string, policy?: PathPolicy): Promise<OpenedFile>;
47
+ export declare function localHost(hostname: string): boolean;
48
+ /** Stream exactly `size` bytes of the file to a presigned PUT URL. Resolves with the HTTP status. */
49
+ export declare function putFile(url: URL, file: OpenedFile, options?: {
50
+ idleMs?: number;
51
+ signal?: AbortSignal;
52
+ }): Promise<number>;
package/dist/upload.js ADDED
@@ -0,0 +1,240 @@
1
+ import { constants } from 'node:fs';
2
+ import { open, realpath, stat } from 'node:fs/promises';
3
+ import { request as httpRequest } from 'node:http';
4
+ import { request as httpsRequest } from 'node:https';
5
+ import { homedir } from 'node:os';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ const MB = 1024 * 1024;
9
+ // Mirrors the gateway's upload allowlist; the gateway stays authoritative.
10
+ export const UPLOAD_LIMITS = {
11
+ 'image/jpeg': 25 * MB, 'image/png': 25 * MB, 'image/webp': 25 * MB,
12
+ 'video/mp4': 200 * MB, 'video/quicktime': 200 * MB, 'video/webm': 100 * MB,
13
+ 'audio/mpeg': 50 * MB, 'audio/wav': 50 * MB,
14
+ };
15
+ export const LIMITS_TEXT = 'JPEG/PNG/WebP up to 25 MB, MP4/MOV up to 200 MB, WebM up to 100 MB, MP3/WAV up to 50 MB';
16
+ export const ROOTS_ENV = 'RAYWAKE_UPLOAD_ROOTS';
17
+ // A file is opened only when its name already says it is an accepted media type.
18
+ const EXTENSIONS = {
19
+ '.jpg': ['image/jpeg'], '.jpeg': ['image/jpeg'], '.jpe': ['image/jpeg'], '.jfif': ['image/jpeg'],
20
+ '.png': ['image/png'], '.webp': ['image/webp'],
21
+ '.mp4': ['video/mp4', 'video/quicktime'], '.m4v': ['video/mp4', 'video/quicktime'],
22
+ '.mov': ['video/quicktime', 'video/mp4'], '.qt': ['video/quicktime', 'video/mp4'],
23
+ '.webm': ['video/webm'], '.mp3': ['audio/mpeg'], '.wav': ['audio/wav'],
24
+ };
25
+ export class UploadError extends Error {
26
+ code;
27
+ constructor(code, message) {
28
+ super(message);
29
+ this.code = code;
30
+ this.name = 'UploadError';
31
+ }
32
+ }
33
+ const ascii = (bytes, start, end) => bytes.subarray(start, end).toString('latin1');
34
+ // ISO media brands that are not a video the gateway accepts (audio-only MP4, HEIF/AVIF stills).
35
+ const NOT_VIDEO_BRANDS = new Set(['M4A ', 'M4B ', 'M4P ', 'F4A ', 'F4B ', 'heic', 'heix', 'hevc', 'hevx', 'heim', 'heis', 'mif1', 'msf1', 'avif', 'avis', 'crx ', 'jp2 ', 'jpx ']);
36
+ const QUICKTIME_ATOMS = new Set(['moov', 'mdat', 'wide', 'free', 'skip', 'pnot']);
37
+ /** Content type from the file's own first bytes; the extension only breaks MOV/MP4 ties. */
38
+ export function detectType(head, extension = '') {
39
+ if (head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff)
40
+ return 'image/jpeg';
41
+ if (head.length >= 8 && head.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])))
42
+ return 'image/png';
43
+ if (head.length >= 12 && ascii(head, 0, 4) === 'RIFF') {
44
+ if (ascii(head, 8, 12) === 'WEBP')
45
+ return 'image/webp';
46
+ if (ascii(head, 8, 12) === 'WAVE')
47
+ return 'audio/wav';
48
+ return undefined;
49
+ }
50
+ if (head.length >= 4 && head.readUInt32BE(0) === 0x1a45dfa3) {
51
+ // EBML: WebM declares DocType "webm"; other Matroska files are not accepted.
52
+ return ascii(head, 4, Math.min(head.length, 64)).includes('webm') ? 'video/webm' : undefined;
53
+ }
54
+ if (head.length >= 12 && ascii(head, 4, 8) === 'ftyp') {
55
+ const brand = ascii(head, 8, 12);
56
+ if (brand === 'qt ')
57
+ return 'video/quicktime';
58
+ if (NOT_VIDEO_BRANDS.has(brand))
59
+ return undefined;
60
+ return 'video/mp4';
61
+ }
62
+ if (head.length >= 8 && QUICKTIME_ATOMS.has(ascii(head, 4, 8)) && ['.mov', '.qt'].includes(extension))
63
+ return 'video/quicktime';
64
+ if (head.length >= 3 && ascii(head, 0, 3) === 'ID3')
65
+ return 'audio/mpeg';
66
+ // MPEG audio frame sync with a defined layer (excludes ADTS AAC, whose layer bits are 00).
67
+ if (head.length >= 2 && head[0] === 0xff && (head[1] & 0xe0) === 0xe0 && (head[1] & 0x06) !== 0 && (head[1] & 0x18) !== 0x08)
68
+ return 'audio/mpeg';
69
+ return undefined;
70
+ }
71
+ /** Parse RAYWAKE_UPLOAD_ROOTS: absolute folders separated by the platform path delimiter. */
72
+ export function parseRoots(value, home = homedir()) {
73
+ if (value === undefined || !value.trim())
74
+ return undefined;
75
+ return value.split(path.delimiter).map(entry => entry.trim()).filter(Boolean)
76
+ .map(entry => expandHome(entry, home)).filter(entry => path.isAbsolute(entry)).map(entry => path.resolve(entry));
77
+ }
78
+ function expandHome(value, home) {
79
+ if (value === '~')
80
+ return home;
81
+ if (value.startsWith('~/') || value.startsWith('~\\'))
82
+ return path.join(home, value.slice(2));
83
+ return value;
84
+ }
85
+ function within(root, target) {
86
+ const relative = path.relative(root, target);
87
+ if (relative === '')
88
+ return '';
89
+ if (relative.startsWith('..') || path.isAbsolute(relative))
90
+ return undefined;
91
+ return relative;
92
+ }
93
+ function defaultRoots(home, cwd) {
94
+ const roots = [home];
95
+ // A client may start the server in "/" or another folder above home; that must not open the whole disk.
96
+ if (path.parse(cwd).root !== cwd && within(cwd, home) === undefined)
97
+ roots.push(cwd);
98
+ return roots;
99
+ }
100
+ async function realRoots(roots) {
101
+ const resolved = await Promise.all(roots.map(root => realpath(root).catch(() => undefined)));
102
+ return [...new Set([...roots, ...resolved.filter((root) => !!root)])];
103
+ }
104
+ /** Inside at least one root, and inside no hidden folder as seen from any root that contains it. */
105
+ function allowed(target, roots) {
106
+ const relatives = roots.map(root => within(root, target)).filter((relative) => relative !== undefined);
107
+ return relatives.length > 0 && !relatives.some(relative => relative.split(/[\\/]/).some(segment => segment.startsWith('.')));
108
+ }
109
+ function notAllowed(rootsText) {
110
+ return new UploadError('path_not_allowed', `This file is not in a folder Raywake may read (${rootsText}). Hidden and settings folders such as .ssh or .config are never read. Ask the user to move the file into an allowed folder, or to set ${ROOTS_ENV} in the MCP server configuration.`);
111
+ }
112
+ /** Resolve and vet a path without opening the file. */
113
+ export async function checkPath(raw, policy = {}) {
114
+ const home = path.resolve(policy.home ?? homedir());
115
+ const cwd = path.resolve(policy.cwd ?? process.cwd());
116
+ let value = raw.trim();
117
+ if (/^file:\/\//i.test(value)) {
118
+ try {
119
+ value = fileURLToPath(value);
120
+ }
121
+ catch {
122
+ throw new UploadError('not_found', 'This file:// address is not a valid local path. Pass the file path instead.');
123
+ }
124
+ }
125
+ else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value) || /^data:/i.test(value)) {
126
+ throw new UploadError('not_a_local_file', 'upload_file takes a path to a file on this computer, not a link or data URI.');
127
+ }
128
+ if (!value || value.includes('\0'))
129
+ throw new UploadError('not_found', 'Pass the path of one file on this computer.');
130
+ const target = path.resolve(cwd, expandHome(value, home));
131
+ const configured = policy.roots !== undefined;
132
+ const roots = await realRoots(configured ? policy.roots : defaultRoots(home, cwd));
133
+ const rootsText = configured ? `${ROOTS_ENV}: ${policy.roots.join(path.delimiter) || 'none'}` : 'the home folder and the working folder';
134
+ const extension = path.extname(target).toLowerCase();
135
+ if (!EXTENSIONS[extension])
136
+ throw unsupported();
137
+ // Refuse before touching the disk, so paths outside the roots are not even probed for existence.
138
+ if (!allowed(target, roots))
139
+ throw notAllowed(rootsText);
140
+ let realPath;
141
+ try {
142
+ realPath = await realpath(target);
143
+ }
144
+ catch (error) {
145
+ const code = error.code;
146
+ if (code === 'EACCES' || code === 'EPERM')
147
+ throw new UploadError('not_readable', 'This file cannot be read: permission denied.');
148
+ throw new UploadError('not_found', 'File not found. Check the exact path, including the folder and extension.');
149
+ }
150
+ // Symlinks are judged by where they lead.
151
+ if (!allowed(realPath, roots))
152
+ throw notAllowed(rootsText);
153
+ const realExtension = path.extname(realPath).toLowerCase();
154
+ if (!EXTENSIONS[realExtension])
155
+ throw unsupported();
156
+ const stats = await stat(realPath).catch(() => { throw new UploadError('not_found', 'File not found.'); });
157
+ if (!stats.isFile())
158
+ throw new UploadError('not_a_file', 'This path is not a regular file. Pass one image, video or audio file.');
159
+ return { realPath, name: path.basename(target), extension: realExtension, stats };
160
+ }
161
+ export function unsupported() {
162
+ return new UploadError('unsupported_type', `Unsupported file type. Accepted: ${LIMITS_TEXT}. Do not convert or re-encode the user's file without asking them.`);
163
+ }
164
+ export function tooLarge(type, size) {
165
+ const limit = UPLOAD_LIMITS[type] / MB;
166
+ return new UploadError('too_large', `This file is too large: ${(size / MB).toFixed(1)} MB, and ${type} files can be at most ${limit} MB. Do not shrink, trim or re-encode the user's file without asking them.`);
167
+ }
168
+ /** Open the vetted file, confirm it is the same file, and identify it from its first bytes. */
169
+ export async function openMedia(raw, policy = {}) {
170
+ const checked = await checkPath(raw, policy);
171
+ const size = checked.stats.size;
172
+ if (size < 1)
173
+ throw new UploadError('empty_file', 'This file is empty.');
174
+ // Reject on size before reading anything when no accepted type could hold it.
175
+ const candidates = EXTENSIONS[checked.extension];
176
+ if (size > Math.max(...Object.values(UPLOAD_LIMITS)))
177
+ throw tooLarge(candidates[0], size);
178
+ let handle;
179
+ try {
180
+ handle = await open(checked.realPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
181
+ }
182
+ catch {
183
+ throw new UploadError('not_readable', 'This file cannot be opened for reading.');
184
+ }
185
+ try {
186
+ const opened = await handle.stat();
187
+ if (!opened.isFile() || opened.ino !== checked.stats.ino || opened.dev !== checked.stats.dev || opened.size !== size) {
188
+ throw new UploadError('file_changed', 'The file changed while it was being checked. Try again once it is saved.');
189
+ }
190
+ const head = Buffer.alloc(Math.min(64, size));
191
+ await handle.read(head, 0, head.length, 0);
192
+ const contentType = detectType(head, checked.extension);
193
+ if (!contentType)
194
+ throw unsupported();
195
+ if (size > UPLOAD_LIMITS[contentType])
196
+ throw tooLarge(contentType, size);
197
+ return { ...checked, handle, contentType, size };
198
+ }
199
+ catch (error) {
200
+ await handle.close();
201
+ throw error;
202
+ }
203
+ }
204
+ export function localHost(hostname) {
205
+ return ['localhost', '127.0.0.1', '[::1]', '::1'].includes(hostname);
206
+ }
207
+ /** Stream exactly `size` bytes of the file to a presigned PUT URL. Resolves with the HTTP status. */
208
+ export function putFile(url, file, options = {}) {
209
+ return new Promise((resolve, reject) => {
210
+ const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
211
+ let status;
212
+ let settled = false;
213
+ const finish = (error) => {
214
+ if (settled)
215
+ return;
216
+ settled = true;
217
+ if (status !== undefined)
218
+ resolve(status);
219
+ else
220
+ reject(error ?? new Error('Upload ended without a response.'));
221
+ };
222
+ const request = send(url, {
223
+ method: 'PUT',
224
+ // Both headers are part of the signature: the bytes must be exactly this type and length.
225
+ headers: { 'Content-Type': file.contentType, 'Content-Length': String(file.size) },
226
+ signal: options.signal,
227
+ }, (response) => {
228
+ status = response.statusCode ?? 0;
229
+ response.resume();
230
+ response.on('end', () => finish());
231
+ response.on('error', error => finish(error));
232
+ });
233
+ request.setTimeout(options.idleMs ?? 60_000, () => request.destroy(new Error('Upload stalled.')));
234
+ request.on('error', error => finish(error));
235
+ const stream = file.handle.createReadStream({ start: 0, end: file.size - 1, autoClose: false, highWaterMark: 1024 * 1024 });
236
+ stream.on('error', error => request.destroy(error));
237
+ stream.pipe(request);
238
+ });
239
+ }
240
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAmB,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAwB,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACvB,2EAA2E;AAC3E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,YAAY,EAAE,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;IAClE,WAAW,EAAE,GAAG,GAAG,EAAE,EAAE,iBAAiB,EAAE,GAAG,GAAG,EAAE,EAAE,YAAY,EAAE,GAAG,GAAG,EAAE;IAC1E,YAAY,EAAE,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;CACnC,CAAC;AAEX,MAAM,CAAC,MAAM,WAAW,GAAG,yFAAyF,CAAC;AACrH,MAAM,CAAC,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAEhD,iFAAiF;AACjF,MAAM,UA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E;YAC/B,MAAM,GAAG,QAAQ,CAAC,UAAU,IAAI,CAAC,CAAC;YAClC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;YACnC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAClG,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;QAC5H,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,30 +1,65 @@
1
1
  {
2
2
  "name": "@raywake/mcp",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "500+ AI image, video and audio models in Claude, ChatGPT, Cursor and any MCP client.",
5
5
  "type": "module",
6
- "bin": { "raywake-mcp": "dist/index.js" },
6
+ "bin": {
7
+ "raywake-mcp": "dist/index.js"
8
+ },
7
9
  "main": "dist/server.js",
8
10
  "types": "dist/server.d.ts",
9
11
  "exports": {
10
- ".": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
11
- "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" }
12
+ ".": {
13
+ "types": "./dist/server.d.ts",
14
+ "import": "./dist/server.js"
15
+ },
16
+ "./client": {
17
+ "types": "./dist/client.d.ts",
18
+ "import": "./dist/client.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "skills"
24
+ ],
25
+ "engines": {
26
+ "node": ">=20"
12
27
  },
13
- "files": ["dist"],
14
- "engines": { "node": ">=20" },
15
28
  "license": "MIT",
16
29
  "author": "Raywake",
17
- "repository": { "type": "git", "url": "https://github.com/oguzhankayan/raywake-mcp.git" },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/oguzhankayan/raywake-mcp.git"
33
+ },
18
34
  "homepage": "https://raywake.si",
19
35
  "mcpName": "si.raywake/mcp",
20
- "keywords": ["raywake", "mcp", "ai", "image", "video", "audio"],
21
- "publishConfig": { "access": "public" },
36
+ "keywords": [
37
+ "raywake",
38
+ "mcp",
39
+ "ai",
40
+ "image",
41
+ "video",
42
+ "audio"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
22
47
  "scripts": {
23
- "build": "tsc && node scripts/make-executable.mjs",
48
+ "build": "node scripts/build-skills.mjs && tsc && node scripts/make-executable.mjs",
24
49
  "test": "npm run build && vitest run",
25
50
  "smoke": "node scripts/smoke.mjs",
26
51
  "prepack": "npm run build"
27
52
  },
28
- "dependencies": { "@modelcontextprotocol/sdk": "^1.30.0", "zod": "^3.25.76" },
29
- "devDependencies": { "@types/node": "^22.0.0", "typescript": "^5.9.3", "vitest": "^4.1.11" }
53
+ "dependencies": {
54
+ "@modelcontextprotocol/server": "2.4.0",
55
+ "zod": "^4.6.7"
56
+ },
57
+ "devDependencies": {
58
+ "@modelcontextprotocol/client": "2.4.0",
59
+ "@modelcontextprotocol/codemod": "^2.4.0",
60
+ "@modelcontextprotocol/sdk": "^1.32.2",
61
+ "@types/node": "^22.0.0",
62
+ "typescript": "^5.9.3",
63
+ "vitest": "^4.1.11"
64
+ }
30
65
  }
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: raywake-create
3
+ description: End-to-end Raywake generation workflow: choose a real model, read its schema, quote the exact input, obtain user approval, generate once, and follow the job.
4
+ ---
5
+
6
+ # Create with Raywake
7
+
8
+ Use this workflow for any image, video, audio, music, voice-over, or 3D generation request.
9
+
10
+ 1. Choose the job type with the user, then search with `search_models`. Use `query`, `category`, `modality`, and pagination; never invent a model ID.
11
+ 2. Call `get_model` for the exact candidate and preserve its input schema exactly: required fields, field names, types, enums, defaults, and media URL fields.
12
+ 3. Prepare inputs. Local files must go through `upload_file`; earlier uploads or website-added files can be found with `list_media`.
13
+ 4. Call `quote` with the complete exact model input. A quote is free and time-limited.
14
+ 5. Show the user the exact USD price, expiry, model, important inputs, and whether the amount is a usage-based maximum reservation. The user must approve that exact quote in chat before generation.
15
+ 6. Only after approval, call `generate` once with the same model, same input, and the `quote_id`. Save the returned `idempotency_key` even if the call errors.
16
+ 7. Continue with `get_job` using the `job_id`. Never start a replacement paid generation because a response was lost; retry only with the same `idempotency_key` and exact request.
17
+
18
+ If a quote expires, quote the same model and input again, show the new exact USD price, and get approval again. If balance is insufficient, say so plainly; the user adds balance at raywake.si themselves. Do not open, link, or offer a payment page.
19
+
20
+ Review states are terminal. Do not resubmit `needs_review`, `submission_unknown`, or `needs_reconciliation` jobs as new paid work.
@@ -0,0 +1,16 @@
1
+ ---
2
+ name: raywake-inputs
3
+ description: Prepare user-owned local media as Raywake model inputs safely with upload_file and list_media, respecting allowed folders, file limits, and URL-only model inputs.
4
+ ---
5
+
6
+ # Prepare media inputs
7
+
8
+ For a file on the user's computer, call `upload_file` with its path. Put the returned `url` unchanged into the model input field that `get_model` defines for image, video, or audio input. Then quote.
9
+
10
+ `upload_file` reads only files in the user's home folder or working folder, or folders explicitly configured with `RAYWAKE_UPLOAD_ROOTS`. Hidden and settings folders are never read. Accepted files are JPEG/PNG/WebP up to 25 MB, MP4/MOV up to 200 MB, WebM up to 100 MB, and MP3/WAV up to 50 MB.
11
+
12
+ Never upload customer files to third-party hosts. Never shrink, trim, convert, re-encode, or embed a file as base64 or a data URI to avoid uploading. Never pass a local path, data URI, or base64 content as a model input.
13
+
14
+ Use `list_media` to reuse an earlier upload or a file the user added on the Raywake website, and to get a fresh link when an older link expired. A public HTTPS link supplied by the user can be used directly when the model schema asks for a URL.
15
+
16
+ If `upload_file` refuses a file, tell the user the exact reason and ask for an allowed copy or location. Do not work around the refusal.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: raywake-model-picker
3
+ description: Choose the right Raywake model for product shots, ads and social video, voice-over or music, 3D assets, and editing existing images or videos without inventing models or prices.
4
+ ---
5
+
6
+ # Pick a Raywake model
7
+
8
+ Never invent models, capabilities, input fields, or prices. Use `search_models` filters and featured or highly relevant catalog results, then verify the exact candidate with `get_model`. Prices come only from `quote` for the exact input; catalog starting prices are indicative.
9
+
10
+ ## Match the job
11
+
12
+ - Product shots: search image models for product photography, studio, lifestyle, background, or catalog language. If the user has a product photo, prefer an image-editing or image-reference model whose schema accepts an image URL.
13
+ - Ads and social video: search video models for text-to-video, image-to-video, vertical or horizontal aspect, duration, motion, camera, product, or UGC-style language. Check duration and aspect-ratio fields before quoting.
14
+ - Voice-over or music: search audio or speech models. Match language, voice, duration, lyrics, instrumental/vocal, and output-format fields in `get_model`.
15
+ - 3D: search 3D, mesh, object, or model-generation terms. Check whether input is text, one image, or multiple views.
16
+ - Editing an existing image or video: first prepare the source with `upload_file` or reuse one from `list_media`, then choose an edit, restyle, inpaint, upscale, extend, reframe, or video-edit model whose schema accepts that media URL.
17
+
18
+ When several models fit, compare only facts returned by the catalog and schemas: modality, inputs, limits, duration, resolution, output count, and starting price. Present a short recommendation and ask which tradeoff the user prefers if the choice is material.
19
+
20
+ Do not name infrastructure or upstream model providers. Do not write fixed prices into the conversation as if they were final: the exact payable amount is the approved quote.