post-engineer-mcp 1.1.1 → 1.3.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 +31 -4
- package/dist/client.d.ts +53 -4
- package/dist/client.js +329 -110
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +36 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +64 -65
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +14 -0
- package/dist/limits.js +15 -0
- package/dist/limits.js.map +1 -0
- package/dist/tools.d.ts +304 -11
- package/dist/tools.js +330 -221
- package/dist/tools.js.map +1 -1
- package/package.json +12 -3
package/dist/tools.js
CHANGED
|
@@ -1,159 +1,272 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { MAX_LIBRARY_IMAGES, MAX_LIBRARY_IMAGE_MB, MAX_LIBRARY_TAG_LENGTH, MAX_LIBRARY_DESCRIPTION_LENGTH, } from './client.js';
|
|
3
|
+
import { getErrorMessage } from './errors.js';
|
|
4
|
+
// Each provider in `providers` must map to a non-empty account-ID list.
|
|
5
|
+
export function missingProviderAccountIds(args) {
|
|
6
|
+
const idsByProvider = {
|
|
7
|
+
youtube: args.youtubeAccountIds,
|
|
8
|
+
instagram: args.instagramAccountIds,
|
|
9
|
+
linkedin: args.linkedinAccountIds,
|
|
10
|
+
bluesky: args.blueskyAccountIds,
|
|
11
|
+
};
|
|
12
|
+
return args.providers.filter((provider) => (idsByProvider[provider] ?? []).length === 0);
|
|
13
|
+
}
|
|
14
|
+
// Shared field definitions: path/tag/description limits appear in both the
|
|
15
|
+
// create-persona images array and add_persona_image — define once so the
|
|
16
|
+
// limits and descriptions can't drift apart.
|
|
17
|
+
const LibraryImageFields = {
|
|
18
|
+
path: z.string().min(1).describe(`Local file path to the image (JPG/JPEG, PNG, or WebP, max ${MAX_LIBRARY_IMAGE_MB}MB)`),
|
|
19
|
+
tag: z.string().max(MAX_LIBRARY_TAG_LENGTH).optional().describe('Short tag for deterministic per-video matching (e.g. casual, formal, gym)'),
|
|
20
|
+
description: z.string().max(MAX_LIBRARY_DESCRIPTION_LENGTH).optional().describe('Description of the photo for tag/keyword matching (e.g. smiling at the beach at sunset)'),
|
|
21
|
+
};
|
|
22
|
+
// Single source of truth: index.ts registers these shapes directly with the
|
|
23
|
+
// MCP server, so field definitions (and their descriptions) live here only.
|
|
24
|
+
const PersonaLibraryImageInputShape = z.object(LibraryImageFields);
|
|
25
|
+
export const CreatePersonaShape = {
|
|
26
|
+
name: z.string().min(1, 'Name is required').describe('Name of the persona'),
|
|
27
|
+
avatarUrl: z.string().url().optional().nullable().describe('Public URL to the persona avatar image (use list_faces for stock face URLs)'),
|
|
28
|
+
voiceId: z.string().default('alloy').describe('Voice ID to use (e.g. alloy, echo)'),
|
|
29
|
+
language: z.string().default('en-US').describe('Language code (e.g. pt-BR, en-US)'),
|
|
30
|
+
videoAspect: z.enum(['9:16', '16:9']).default('9:16').describe('Video aspect ratio'),
|
|
31
|
+
scriptPrompt: z.string().optional().default('').describe('System prompt instructions for video scripts'),
|
|
32
|
+
paragraphNumber: z.number().int().min(1).max(10).default(1).describe('Number of paragraphs'),
|
|
33
|
+
niche: z.string().optional().default('General').describe('Content niche topic'),
|
|
11
34
|
faceMixPercent: z.number().min(0).max(100).default(50),
|
|
12
35
|
faceQuality: z.enum(['ok', 'very_good']).default('very_good'),
|
|
36
|
+
images: z.array(PersonaLibraryImageInputShape).max(MAX_LIBRARY_IMAGES).optional().describe(`Up to ${MAX_LIBRARY_IMAGES} local image files of the same person for the persona image library. Each video deterministically picks the best-matching image by tag. Requires a non-faceless persona: avatarUrl must be set, because the server rejects library images for faceless personas.`),
|
|
37
|
+
imagePrimaryIndex: z.number().int().min(0).max(MAX_LIBRARY_IMAGES - 1).optional().describe('Index into images[] marking the primary library image (no primary is set when omitted)'),
|
|
38
|
+
};
|
|
39
|
+
export const CreatePersonaSchema = z.object(CreatePersonaShape).superRefine((value, ctx) => {
|
|
40
|
+
// Domain rule encoded at parse time (the round-4 standing rule: encode
|
|
41
|
+
// domain rules in the zod schema): library images are rejected
|
|
42
|
+
// server-side for faceless personas, so require the avatar up front.
|
|
43
|
+
// The client keeps its own check as defense in depth.
|
|
44
|
+
const hasImages = (value.images?.length ?? 0) > 0;
|
|
45
|
+
const hasAvatar = value.avatarUrl !== undefined && value.avatarUrl !== null && value.avatarUrl.length > 0;
|
|
46
|
+
if (hasImages && !hasAvatar) {
|
|
47
|
+
ctx.addIssue({
|
|
48
|
+
code: z.ZodIssueCode.custom,
|
|
49
|
+
path: ['avatarUrl'],
|
|
50
|
+
message: 'avatarUrl is required when images are provided: library images need a persona avatar (faceless personas cannot have an image library).',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
13
53
|
});
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
export const
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
export const ListPersonasShape = {};
|
|
55
|
+
export const ListPersonasSchema = z.object(ListPersonasShape);
|
|
56
|
+
export const ListVoicesShape = {};
|
|
57
|
+
export const ListVoicesSchema = z.object(ListVoicesShape);
|
|
58
|
+
export const ListFacesShape = {};
|
|
59
|
+
export const ListFacesSchema = z.object(ListFacesShape);
|
|
60
|
+
export const UpdatePersonaShape = {
|
|
61
|
+
personaId: z.string().min(1, 'personaId is required').describe('The ID of the persona to update'),
|
|
62
|
+
name: z.string().min(1).optional().describe('New name for the persona'),
|
|
63
|
+
// No .nullable(): the API has no "clear avatar" sentinel — null would be silently ignored.
|
|
64
|
+
avatarUrl: z.string().url().optional().describe('New public avatar image URL'),
|
|
65
|
+
voiceId: z.string().optional().describe('New voice ID (see list_voices)'),
|
|
66
|
+
language: z.string().optional().describe('New language code (e.g. pt-BR, en-US)'),
|
|
67
|
+
videoAspect: z.enum(['9:16', '16:9']).optional().describe('New video aspect ratio'),
|
|
68
|
+
scriptPrompt: z.string().optional().describe('New system prompt instructions for video scripts'),
|
|
69
|
+
paragraphNumber: z.number().int().min(1).max(10).optional().describe('New number of paragraphs'),
|
|
70
|
+
niche: z.string().max(300).optional().describe('New content niche topic'),
|
|
71
|
+
};
|
|
72
|
+
export const UpdatePersonaSchema = z.object(UpdatePersonaShape);
|
|
73
|
+
export const ListSocialAccountsShape = {};
|
|
74
|
+
export const ListSocialAccountsSchema = z.object(ListSocialAccountsShape);
|
|
75
|
+
export const ConnectAccountShape = {
|
|
76
|
+
provider: z.enum(['youtube', 'instagram', 'linkedin', 'bluesky']).describe('The social platform to connect'),
|
|
77
|
+
handle: z.string().min(1).optional().describe('Bluesky handle (e.g. user.bsky.social). Required only for bluesky.'),
|
|
78
|
+
appPassword: z.string().min(1).optional().describe('Bluesky app password (Settings > App passwords). Required only for bluesky. Never shared or logged.'),
|
|
79
|
+
};
|
|
80
|
+
export const ConnectAccountSchema = z.object(ConnectAccountShape);
|
|
81
|
+
export const ListSchedulesShape = {};
|
|
82
|
+
export const ListSchedulesSchema = z.object(ListSchedulesShape);
|
|
83
|
+
export const ListPostsShape = {
|
|
84
|
+
limit: z.number().int().min(1).max(500).default(20).describe('Max number of upcoming and past posts to return (each list). Default 20, max 500.'),
|
|
85
|
+
};
|
|
86
|
+
export const ListPostsSchema = z.object(ListPostsShape);
|
|
87
|
+
export const CancelScheduleShape = {
|
|
88
|
+
scheduleId: z.string().min(1, 'scheduleId is required').describe('The ID of the schedule to cancel'),
|
|
89
|
+
};
|
|
90
|
+
export const CancelScheduleSchema = z.object(CancelScheduleShape);
|
|
91
|
+
export const GetTokenBalanceShape = {};
|
|
92
|
+
export const GetTokenBalanceSchema = z.object(GetTokenBalanceShape);
|
|
93
|
+
export const GenerateVideoShape = {
|
|
94
|
+
// Omitting personaId selects the faceless flow (no persona loaded; the job
|
|
95
|
+
// runs fully faceless with face_mix_percent 0). Faceless generation then
|
|
96
|
+
// requires videoSubject plus a voice source (audioUrl or voiceId) — the
|
|
97
|
+
// web API has no stored persona to fall back to.
|
|
98
|
+
personaId: z.string().min(1, 'personaId must be a non-empty string').optional().describe('The ID of the persona to generate video with. Omit for faceless generation.'),
|
|
99
|
+
videoSubject: z.string().min(1).optional().describe('Video subject/topic. Required for faceless generation (no persona).'),
|
|
100
|
+
voiceId: z.string().min(1).optional().describe('Voice ID for faceless generation. Required when no audioUrl is given and no persona.'),
|
|
101
|
+
scriptPrompt: z.string().optional().describe('Optional specific prompt override for this video'),
|
|
102
|
+
audioUrl: z.string().url('audioUrl must be a valid URL').optional().describe('Optional public URL of custom audio for this video (overrides the persona voice)'),
|
|
103
|
+
imageId: z.string().min(1, 'imageId must be a non-empty string').optional().describe('Optional library image ID to use for this video (overrides the deterministic per-video image selection; see list_persona_images)'),
|
|
104
|
+
};
|
|
105
|
+
export const GenerateVideoSchema = z.object(GenerateVideoShape);
|
|
106
|
+
export const ListPersonaImagesShape = {
|
|
107
|
+
personaId: z.string().min(1, 'personaId is required').describe('The ID of the persona whose image library to list'),
|
|
108
|
+
};
|
|
109
|
+
export const ListPersonaImagesSchema = z.object(ListPersonaImagesShape);
|
|
110
|
+
export const AddPersonaImageShape = {
|
|
111
|
+
personaId: z.string().min(1, 'personaId is required').describe('The ID of the persona to add the image to'),
|
|
112
|
+
...LibraryImageFields,
|
|
113
|
+
// Swap-only, symmetric with update_persona_image: isPrimary:false on a new
|
|
114
|
+
// image is meaningless (it is never primary unless marked), so the schema
|
|
115
|
+
// accepts only true and surfaces the constraint at parse time instead of
|
|
116
|
+
// silently dropping the flag.
|
|
117
|
+
isPrimary: z
|
|
118
|
+
.literal(true)
|
|
119
|
+
.optional()
|
|
120
|
+
.describe('Set true to mark this image as the primary library image (false is rejected — a new image is not primary unless marked)'),
|
|
121
|
+
};
|
|
122
|
+
export const AddPersonaImageSchema = z.object(AddPersonaImageShape);
|
|
123
|
+
export const UpdatePersonaImageShape = {
|
|
124
|
+
id: z.string().min(1, 'id is required').describe('The library image ID to update'),
|
|
125
|
+
// Reuse the shared field definitions so tag/description limits can't drift
|
|
126
|
+
// from the create path; PATCH supports clearing via empty string, which the
|
|
127
|
+
// create schema's .min(1) path field doesn't need. Whitespace-only values
|
|
128
|
+
// trim to '' client-side and therefore clear too (server convention:
|
|
129
|
+
// undefined = keep, '' = clear) — the descriptions say so explicitly.
|
|
130
|
+
tag: LibraryImageFields.tag.describe('New tag (empty or whitespace-only clears the stored value; omit to keep it)'),
|
|
131
|
+
description: LibraryImageFields.description.describe('New description (empty or whitespace-only clears the stored value; omit to keep it)'),
|
|
132
|
+
// Swap-only: the server rejects isPrimary:false, so the schema accepts only
|
|
133
|
+
// true and surfaces the constraint at parse time instead of a server 400.
|
|
134
|
+
isPrimary: z
|
|
135
|
+
.literal(true)
|
|
136
|
+
.optional()
|
|
137
|
+
.describe('Set true to mark this image as the primary library image (the swap atomically demotes the old primary; false is rejected — mark another image instead)'),
|
|
138
|
+
};
|
|
139
|
+
export const UpdatePersonaImageSchema = z
|
|
140
|
+
.object(UpdatePersonaImageShape)
|
|
141
|
+
.refine((v) => v.tag !== undefined || v.description !== undefined || v.isPrimary !== undefined, { message: 'At least one of tag, description, or isPrimary is required.' });
|
|
142
|
+
export const RemovePersonaImageShape = {
|
|
143
|
+
id: z.string().min(1, 'id is required').describe('The library image ID to remove'),
|
|
144
|
+
};
|
|
145
|
+
export const RemovePersonaImageSchema = z.object(RemovePersonaImageShape);
|
|
146
|
+
export const GetVideoStatusShape = {
|
|
147
|
+
taskId: z.string().min(1, 'taskId is required').describe('The video generation task ID'),
|
|
148
|
+
};
|
|
149
|
+
export const GetVideoStatusSchema = z.object(GetVideoStatusShape);
|
|
150
|
+
export const ScheduleVideoShape = {
|
|
151
|
+
personaId: z.string().min(1, 'personaId is required').describe('The ID of the persona'),
|
|
152
|
+
providers: z
|
|
153
|
+
.array(z.enum(['youtube', 'instagram', 'linkedin', 'bluesky']))
|
|
154
|
+
.min(1, 'At least one provider required')
|
|
155
|
+
.describe('Target social platforms'),
|
|
43
156
|
youtubeAccountIds: z.array(z.string()).optional().default([]),
|
|
44
157
|
instagramAccountIds: z.array(z.string()).optional().default([]),
|
|
45
158
|
linkedinAccountIds: z.array(z.string()).optional().default([]),
|
|
46
|
-
|
|
159
|
+
blueskyAccountIds: z.array(z.string()).optional().default([]),
|
|
160
|
+
scheduledAt: z
|
|
161
|
+
.string()
|
|
162
|
+
.describe('Target ISO date time for scheduling. Must be between 24h and 30 days in the future.'),
|
|
47
163
|
daysOfWeek: z.array(z.number().int().min(0).max(6)).optional(),
|
|
48
164
|
startHour: z.number().int().min(0).max(23).optional(),
|
|
49
165
|
endHour: z.number().int().min(0).max(23).optional(),
|
|
50
166
|
postsPerDay: z.number().int().min(1).max(10).optional(),
|
|
51
167
|
timezone: z.string().optional().default('UTC'),
|
|
52
|
-
}
|
|
168
|
+
};
|
|
169
|
+
// The cross-field "each provider needs account IDs" rule cannot live in the
|
|
170
|
+
// MCP registration (the SDK only accepts raw shapes, not refined schemas), so
|
|
171
|
+
// it stays here for handler-level validation and handleScheduleVideo enforces
|
|
172
|
+
// it fail-fast before any API call.
|
|
173
|
+
export const ScheduleVideoSchema = z
|
|
174
|
+
.object(ScheduleVideoShape)
|
|
175
|
+
.refine((args) => missingProviderAccountIds(args).length === 0, (args) => ({
|
|
176
|
+
message: `Each provider requires at least one account ID — missing for: ${missingProviderAccountIds(args).join(', ')}. Discover them with list_social_accounts first.`,
|
|
177
|
+
}));
|
|
53
178
|
export async function handleCreatePersona(client, args) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
type: 'text',
|
|
60
|
-
text: `Persona created successfully: ${JSON.stringify(result, null, 2)}`,
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
return {
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
69
|
-
type: 'text',
|
|
70
|
-
text: `Error creating persona: ${error.message}`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
isError: true,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
179
|
+
// Re-parse with the refined schema: the MCP SDK parses tool args from the
|
|
180
|
+
// raw shape only, so the superRefine cross-field rule would otherwise never
|
|
181
|
+
// fire on the tool path. A parse failure becomes a loud isError via
|
|
182
|
+
// handleLibraryCall, before any file is read.
|
|
183
|
+
return handleLibraryCall(() => client.createPersona(CreatePersonaSchema.parse(args)), 'creating persona', 'Persona created successfully');
|
|
76
184
|
}
|
|
77
185
|
export async function handleListPersonas(client) {
|
|
78
|
-
|
|
79
|
-
const result = await client.listPersonas();
|
|
80
|
-
return {
|
|
81
|
-
content: [
|
|
82
|
-
{
|
|
83
|
-
type: 'text',
|
|
84
|
-
text: JSON.stringify(result, null, 2),
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
return {
|
|
91
|
-
content: [
|
|
92
|
-
{
|
|
93
|
-
type: 'text',
|
|
94
|
-
text: `Error listing personas: ${error.message}`,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
isError: true,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
186
|
+
return handleLibraryCall(() => client.listPersonas(), 'listing personas');
|
|
100
187
|
}
|
|
101
188
|
export async function handleListVoices(client) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
type: 'text',
|
|
108
|
-
text: JSON.stringify(result, null, 2),
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
return {
|
|
115
|
-
content: [
|
|
116
|
-
{
|
|
117
|
-
type: 'text',
|
|
118
|
-
text: `Error listing voices: ${error.message}`,
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
isError: true,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
189
|
+
return handleLibraryCall(() => client.listVoices(), 'listing voices');
|
|
190
|
+
}
|
|
191
|
+
export async function handleListFaces(client) {
|
|
192
|
+
return handleLibraryCall(() => client.listFaces(), 'listing faces');
|
|
124
193
|
}
|
|
125
194
|
export async function handleUpdatePersona(client, args) {
|
|
126
|
-
|
|
127
|
-
const result = await client.updatePersona(args);
|
|
128
|
-
return {
|
|
129
|
-
content: [
|
|
130
|
-
{
|
|
131
|
-
type: 'text',
|
|
132
|
-
text: `Persona updated successfully: ${JSON.stringify(result, null, 2)}`,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
return {
|
|
139
|
-
content: [
|
|
140
|
-
{
|
|
141
|
-
type: 'text',
|
|
142
|
-
text: `Error updating persona: ${error.message}`,
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
isError: true,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
195
|
+
return handleLibraryCall(() => client.updatePersona(args), 'updating persona', 'Persona updated successfully');
|
|
148
196
|
}
|
|
149
197
|
export async function handleListSocialAccounts(client) {
|
|
198
|
+
return handleLibraryCall(() => client.listSocialAccounts(), 'listing social accounts');
|
|
199
|
+
}
|
|
200
|
+
export async function handleConnectAccount(client, args) {
|
|
201
|
+
if (args.provider === 'bluesky') {
|
|
202
|
+
if (!args.handle || !args.appPassword) {
|
|
203
|
+
return {
|
|
204
|
+
content: [
|
|
205
|
+
{
|
|
206
|
+
type: 'text',
|
|
207
|
+
text: 'Error: Bluesky requires both handle and appPassword.',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
isError: true,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const result = await client.connectBlueskyAccount(args.handle, args.appPassword);
|
|
215
|
+
return {
|
|
216
|
+
content: [
|
|
217
|
+
{
|
|
218
|
+
type: 'text',
|
|
219
|
+
text: `Bluesky account connected successfully: ${JSON.stringify(result, null, 2)}`,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
return {
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: 'text',
|
|
229
|
+
text: `Error connecting Bluesky account: ${getErrorMessage(error)}`,
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
isError: true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
150
236
|
try {
|
|
151
|
-
const
|
|
237
|
+
const parsed = z.object({ auth_url: z.string().url() }).safeParse(await client.getOAuthConnectUrl(args.provider));
|
|
238
|
+
if (!parsed.success) {
|
|
239
|
+
return {
|
|
240
|
+
content: [
|
|
241
|
+
{
|
|
242
|
+
type: 'text',
|
|
243
|
+
text: 'Error: the connect endpoint did not return an auth_url.',
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
isError: true,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const result = parsed.data;
|
|
250
|
+
// Never echo a non-https URL as a "open in your browser" authorization
|
|
251
|
+
// link: z.string().url() accepts any scheme, including javascript:.
|
|
252
|
+
if (new URL(result.auth_url).protocol !== 'https:') {
|
|
253
|
+
return {
|
|
254
|
+
content: [
|
|
255
|
+
{
|
|
256
|
+
type: 'text',
|
|
257
|
+
text: 'Error: the connect endpoint returned a non-https auth_url.',
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
isError: true,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
152
263
|
return {
|
|
153
264
|
content: [
|
|
154
265
|
{
|
|
155
266
|
type: 'text',
|
|
156
|
-
text:
|
|
267
|
+
text: `To connect your ${args.provider} account, open this URL in your browser and authorize Post Engineer:\n\n` +
|
|
268
|
+
`${result.auth_url}\n\n` +
|
|
269
|
+
`Once you authorize, the account is connected automatically. Verify with list_social_accounts.`,
|
|
157
270
|
},
|
|
158
271
|
],
|
|
159
272
|
};
|
|
@@ -163,7 +276,7 @@ export async function handleListSocialAccounts(client) {
|
|
|
163
276
|
content: [
|
|
164
277
|
{
|
|
165
278
|
type: 'text',
|
|
166
|
-
text: `Error
|
|
279
|
+
text: `Error getting OAuth connect URL: ${getErrorMessage(error)}`,
|
|
167
280
|
},
|
|
168
281
|
],
|
|
169
282
|
isError: true,
|
|
@@ -171,87 +284,61 @@ export async function handleListSocialAccounts(client) {
|
|
|
171
284
|
}
|
|
172
285
|
}
|
|
173
286
|
export async function handleListSchedules(client) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
{
|
|
179
|
-
type: 'text',
|
|
180
|
-
text: JSON.stringify(result, null, 2),
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
return {
|
|
187
|
-
content: [
|
|
188
|
-
{
|
|
189
|
-
type: 'text',
|
|
190
|
-
text: `Error listing schedules: ${error.message}`,
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
isError: true,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
287
|
+
return handleLibraryCall(() => client.listSchedules(), 'listing schedules');
|
|
288
|
+
}
|
|
289
|
+
export async function handleListPosts(client, args) {
|
|
290
|
+
return handleLibraryCall(() => client.listPosts(args.limit), 'listing posts');
|
|
196
291
|
}
|
|
197
292
|
export async function handleCancelSchedule(client, args) {
|
|
198
|
-
|
|
199
|
-
const result = await client.cancelSchedule(args.scheduleId);
|
|
200
|
-
return {
|
|
201
|
-
content: [
|
|
202
|
-
{
|
|
203
|
-
type: 'text',
|
|
204
|
-
text: `Schedule cancelled successfully: ${JSON.stringify(result, null, 2)}`,
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
return {
|
|
211
|
-
content: [
|
|
212
|
-
{
|
|
213
|
-
type: 'text',
|
|
214
|
-
text: `Error cancelling schedule: ${error.message}`,
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
isError: true,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
293
|
+
return handleLibraryCall(() => client.cancelSchedule(args.scheduleId), 'cancelling schedule', 'Schedule cancelled successfully');
|
|
220
294
|
}
|
|
221
295
|
export async function handleGetTokenBalance(client) {
|
|
222
|
-
|
|
223
|
-
const result = await client.getTokenBalance();
|
|
224
|
-
return {
|
|
225
|
-
content: [
|
|
226
|
-
{
|
|
227
|
-
type: 'text',
|
|
228
|
-
text: JSON.stringify(result, null, 2),
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
return {
|
|
235
|
-
content: [
|
|
236
|
-
{
|
|
237
|
-
type: 'text',
|
|
238
|
-
text: `Error getting token balance: ${error.message}`,
|
|
239
|
-
},
|
|
240
|
-
],
|
|
241
|
-
isError: true,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
296
|
+
return handleLibraryCall(() => client.getTokenBalance(), 'getting token balance');
|
|
244
297
|
}
|
|
245
298
|
export async function handleGenerateVideo(client, args) {
|
|
299
|
+
// Faceless flow (no personaId): the web API has no stored persona to fall
|
|
300
|
+
// back to, so the subject and a voice source must come with the request.
|
|
301
|
+
// Fail fast here instead of surfacing the API 400.
|
|
302
|
+
const faceless = args.personaId === undefined || args.personaId === null;
|
|
303
|
+
if (faceless) {
|
|
304
|
+
if (!args.videoSubject || args.videoSubject.trim().length === 0) {
|
|
305
|
+
return {
|
|
306
|
+
content: [
|
|
307
|
+
{
|
|
308
|
+
type: 'text',
|
|
309
|
+
text: 'Error: faceless generation requires videoSubject (no persona to take the topic from).',
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
isError: true,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (!args.audioUrl && !args.voiceId) {
|
|
316
|
+
return {
|
|
317
|
+
content: [
|
|
318
|
+
{
|
|
319
|
+
type: 'text',
|
|
320
|
+
text: 'Error: faceless generation requires a voice source — audioUrl or voiceId (no persona voice to fall back to).',
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
isError: true,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return handleLibraryCall(() => client.generateVideoJob(args), 'generating video', 'Video generation task started');
|
|
328
|
+
}
|
|
329
|
+
/** Shared wrapper for the persona-image handlers: same try/catch + text
|
|
330
|
+
* response shape, differing only in the client call and the message verbs.
|
|
331
|
+
* Older handlers (handleConnectAccount, handleScheduleVideo) keep inline
|
|
332
|
+
* try/catch because they pre-validate args before the client call — the
|
|
333
|
+
* wrapper only covers the call itself. */
|
|
334
|
+
async function handleLibraryCall(clientCall, errorVerb, successPrefix) {
|
|
246
335
|
try {
|
|
247
|
-
const result = await
|
|
336
|
+
const result = await clientCall();
|
|
337
|
+
const text = successPrefix
|
|
338
|
+
? `${successPrefix}: ${JSON.stringify(result, null, 2)}`
|
|
339
|
+
: JSON.stringify(result, null, 2);
|
|
248
340
|
return {
|
|
249
|
-
content: [
|
|
250
|
-
{
|
|
251
|
-
type: 'text',
|
|
252
|
-
text: `Video generation task started: ${JSON.stringify(result, null, 2)}`,
|
|
253
|
-
},
|
|
254
|
-
],
|
|
341
|
+
content: [{ type: 'text', text }],
|
|
255
342
|
};
|
|
256
343
|
}
|
|
257
344
|
catch (error) {
|
|
@@ -259,38 +346,60 @@ export async function handleGenerateVideo(client, args) {
|
|
|
259
346
|
content: [
|
|
260
347
|
{
|
|
261
348
|
type: 'text',
|
|
262
|
-
text: `Error
|
|
349
|
+
text: `Error ${errorVerb}: ${getErrorMessage(error)}`,
|
|
263
350
|
},
|
|
264
351
|
],
|
|
265
352
|
isError: true,
|
|
266
353
|
};
|
|
267
354
|
}
|
|
268
355
|
}
|
|
356
|
+
export async function handleListPersonaImages(client, args) {
|
|
357
|
+
return handleLibraryCall(() => client.listPersonaImages(args.personaId), 'listing persona images');
|
|
358
|
+
}
|
|
359
|
+
export async function handleAddPersonaImage(client, args) {
|
|
360
|
+
return handleLibraryCall(() => client.addPersonaImage(args.personaId, {
|
|
361
|
+
path: args.path,
|
|
362
|
+
tag: args.tag,
|
|
363
|
+
description: args.description,
|
|
364
|
+
isPrimary: args.isPrimary,
|
|
365
|
+
}), 'adding persona image', 'Persona image added successfully');
|
|
366
|
+
}
|
|
367
|
+
export async function handleUpdatePersonaImage(client, args) {
|
|
368
|
+
return handleLibraryCall(() => {
|
|
369
|
+
// Re-parse with the refined schema: the MCP SDK parses tool args
|
|
370
|
+
// from the raw shape only, so the "at least one of
|
|
371
|
+
// tag/description/isPrimary" refine would otherwise never fire on
|
|
372
|
+
// the tool path. Parsing inside the closure turns the failure into
|
|
373
|
+
// a loud isError, before any client call.
|
|
374
|
+
// (Same reason handleCreatePersona re-parses.)
|
|
375
|
+
const parsed = UpdatePersonaImageSchema.parse(args);
|
|
376
|
+
return client.updatePersonaImage({
|
|
377
|
+
id: parsed.id,
|
|
378
|
+
tag: parsed.tag,
|
|
379
|
+
description: parsed.description,
|
|
380
|
+
isPrimary: parsed.isPrimary,
|
|
381
|
+
});
|
|
382
|
+
}, 'updating persona image', 'Persona image updated successfully');
|
|
383
|
+
}
|
|
384
|
+
export async function handleRemovePersonaImage(client, args) {
|
|
385
|
+
return handleLibraryCall(() => client.deletePersonaImage(args.id), 'removing persona image', 'Persona image removed successfully');
|
|
386
|
+
}
|
|
269
387
|
export async function handleGetVideoStatus(client, args) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
type: 'text',
|
|
276
|
-
text: JSON.stringify(result, null, 2),
|
|
277
|
-
},
|
|
278
|
-
],
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
388
|
+
return handleLibraryCall(() => client.getVideoStatus(args.taskId), 'fetching video status');
|
|
389
|
+
}
|
|
390
|
+
export async function handleScheduleVideo(client, args) {
|
|
391
|
+
const missing = missingProviderAccountIds(args);
|
|
392
|
+
if (missing.length > 0) {
|
|
282
393
|
return {
|
|
283
394
|
content: [
|
|
284
395
|
{
|
|
285
396
|
type: 'text',
|
|
286
|
-
text: `Error
|
|
397
|
+
text: `Error: each provider requires at least one account ID — missing for: ${missing.join(', ')}. Discover them with list_social_accounts first.`,
|
|
287
398
|
},
|
|
288
399
|
],
|
|
289
400
|
isError: true,
|
|
290
401
|
};
|
|
291
402
|
}
|
|
292
|
-
}
|
|
293
|
-
export async function handleScheduleVideo(client, args) {
|
|
294
403
|
try {
|
|
295
404
|
const result = await client.createSchedule(args);
|
|
296
405
|
return {
|
|
@@ -307,7 +416,7 @@ export async function handleScheduleVideo(client, args) {
|
|
|
307
416
|
content: [
|
|
308
417
|
{
|
|
309
418
|
type: 'text',
|
|
310
|
-
text: `Error scheduling video: ${error
|
|
419
|
+
text: `Error scheduling video: ${getErrorMessage(error)}`,
|
|
311
420
|
},
|
|
312
421
|
],
|
|
313
422
|
isError: true,
|