@atray/mcp 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/index.js +37 -1
- package/src/tools.js +15 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { tools } from './tools.js';
|
|
|
10
10
|
import { api } from './api.js';
|
|
11
11
|
|
|
12
12
|
const server = new Server(
|
|
13
|
-
{ name: 'atray-mcp', version: '1.0.
|
|
13
|
+
{ name: 'atray-mcp', version: '1.0.6' },
|
|
14
14
|
{ capabilities: { tools: {} } }
|
|
15
15
|
);
|
|
16
16
|
|
|
@@ -80,6 +80,9 @@ async function callTool(name, a) {
|
|
|
80
80
|
return api.post(`/posts/${id}/regenerate-image`, body);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
case 'uploadPostImage':
|
|
84
|
+
return uploadPostImage(a);
|
|
85
|
+
|
|
83
86
|
case 'uploadPostVideo':
|
|
84
87
|
return uploadPostVideo(a);
|
|
85
88
|
|
|
@@ -98,6 +101,39 @@ async function callTool(name, a) {
|
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
const IMAGE_MIME = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
|
|
105
|
+
|
|
106
|
+
async function uploadPostImage({ id, file_path, image_url, slot_index }) {
|
|
107
|
+
if (!id) throw new Error('id (post UUID) is required');
|
|
108
|
+
if (!file_path && !image_url) throw new Error('Provide file_path (local file) or image_url (public URL)');
|
|
109
|
+
|
|
110
|
+
let buffer;
|
|
111
|
+
let filename;
|
|
112
|
+
if (file_path) {
|
|
113
|
+
buffer = await readFile(file_path);
|
|
114
|
+
filename = basename(file_path);
|
|
115
|
+
} else {
|
|
116
|
+
const res = await fetch(image_url);
|
|
117
|
+
if (!res.ok) throw new Error(`Failed to download image_url: HTTP ${res.status}`);
|
|
118
|
+
buffer = Buffer.from(await res.arrayBuffer());
|
|
119
|
+
filename = basename(new URL(image_url).pathname) || 'image.jpg';
|
|
120
|
+
if (!/\.(jpg|jpeg|png|webp)$/i.test(filename)) {
|
|
121
|
+
const ct = (res.headers.get('content-type') || '').toLowerCase();
|
|
122
|
+
const ext = Object.keys(IMAGE_MIME).find((k) => IMAGE_MIME[k] === ct.split(';')[0].trim());
|
|
123
|
+
if (ext) filename = 'image.' + ext;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const m = filename.toLowerCase().match(/\.(jpg|jpeg|png|webp)$/);
|
|
128
|
+
if (!m) throw new Error('Image must be .jpg, .jpeg, .png or .webp');
|
|
129
|
+
|
|
130
|
+
const base64 = buffer.toString('base64');
|
|
131
|
+
const ext = m[1] === 'jpg' ? 'jpeg' : m[1];
|
|
132
|
+
const body = { image: `data:image/${ext};base64,${base64}`, filename };
|
|
133
|
+
if (slot_index != null) body.slot_index = Number(slot_index);
|
|
134
|
+
return api.post(`/posts/${id}/image`, body);
|
|
135
|
+
}
|
|
136
|
+
|
|
101
137
|
const VIDEO_MIME = { mp4: 'video/mp4', mov: 'video/quicktime', webm: 'video/webm' };
|
|
102
138
|
const VIDEO_MAX_BYTES = 120 * 1024 * 1024;
|
|
103
139
|
|
package/src/tools.js
CHANGED
|
@@ -226,6 +226,21 @@ export const tools = [
|
|
|
226
226
|
},
|
|
227
227
|
},
|
|
228
228
|
|
|
229
|
+
{
|
|
230
|
+
name: 'uploadPostImage',
|
|
231
|
+
description: 'Uploads a custom image (jpg, jpeg, png or webp) as the post media, replacing the current AI-generated image. Provide either file_path (local file) or image_url (public URL to download from). For carousel posts, use slot_index (0-based) to target a specific slide; omit to replace slide 0.',
|
|
232
|
+
inputSchema: {
|
|
233
|
+
type: 'object',
|
|
234
|
+
required: ['id'],
|
|
235
|
+
properties: {
|
|
236
|
+
id: { type: 'string', description: 'Post UUID' },
|
|
237
|
+
file_path: { type: 'string', description: 'Absolute path to a local image file (jpg, jpeg, png, webp)' },
|
|
238
|
+
image_url: { type: 'string', description: 'Public URL of the image to download and upload' },
|
|
239
|
+
slot_index: { type: 'number', description: 'Carousel slide index (0-based). Required to fill slides beyond the first one.' },
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
|
|
229
244
|
{
|
|
230
245
|
name: 'uploadPostVideo',
|
|
231
246
|
description: 'Uploads a video (mp4, mov or webm; up to 120 MB) as the post media, replacing the current image/video. Provide either file_path (local file) or video_url (public URL to download from). When the post is published to Instagram, videos are posted as Reels (also shared to the feed). Scheduling works the same as image posts.',
|