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