posterly-mcp-server 0.8.2 → 0.8.3

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- const instagramSettingsSchema = z.object({
2
+ export const instagramSettingsSchema = z.object({
3
3
  __type: z.enum(['instagram', 'instagram-standalone']).optional(),
4
4
  post_type: z.enum(['post', 'feed', 'story', 'reel', 'carousel']).optional(),
5
5
  is_trial_reel: z.boolean().optional(),
@@ -15,7 +15,7 @@ const instagramSettingsSchema = z.object({
15
15
  reel_cover_url: z.string().optional(),
16
16
  reel_thumb_offset: z.number().nonnegative().optional(),
17
17
  });
18
- const platformSettingsSchema = z.object({
18
+ export const platformSettingsSchema = z.object({
19
19
  __type: z.string().optional(),
20
20
  post_type: z.string().optional(),
21
21
  content_type: z.string().optional(),
@@ -67,6 +67,79 @@ const platformSettingsSchema = z.object({
67
67
  // Bluesky
68
68
  langs: z.array(z.string()).optional(),
69
69
  }).passthrough();
70
+ export const createPostInputSchema = z.object({
71
+ account_id: z.string().optional().describe('Social account ID (from list_accounts)'),
72
+ username: z.string().optional().describe('Account username (alternative to account_id)'),
73
+ platform: z
74
+ .string()
75
+ .optional()
76
+ .describe('Platform name (required with username): instagram, twitter, linkedin, facebook, tiktok, threads, youtube, pinterest, google_business'),
77
+ caption: z.string().optional().describe('The post caption/text content. Ignored when `thread_posts` is provided.'),
78
+ scheduled_at: z
79
+ .string()
80
+ .optional()
81
+ .describe('ISO 8601 datetime for scheduling (e.g. 2026-03-05T09:00:00Z). Omit for immediate publish.'),
82
+ media_url: z.string().optional().describe('URL of media to attach (image or video). For threads, attaches to the lead post only.'),
83
+ media_urls: z
84
+ .array(z.string())
85
+ .optional()
86
+ .describe('Multiple media URLs for carousel posts'),
87
+ post_type: z
88
+ .string()
89
+ .optional()
90
+ .describe('Post type: text, image, video, carousel, reel, story. Auto-set to x_thread/threads_thread when `thread_posts` is provided.'),
91
+ thread_posts: z
92
+ .array(z.string())
93
+ .optional()
94
+ .describe('For X or Threads only: array of 2+ strings, one per post in the thread. The first entry leads, the rest reply in order. When set, the platform must be twitter or threads.'),
95
+ instagram_settings: instagramSettingsSchema
96
+ .optional()
97
+ .describe('Instagram-specific settings: post_type (post/feed/story/reel/carousel), collaborators, user_tags, first_comment, media_alt_texts, is_trial_reel, graduation_strategy (defaults to MANUAL), reel_cover_url, reel_thumb_offset.'),
98
+ platform_settings: platformSettingsSchema
99
+ .optional()
100
+ .describe('Platform-specific settings for the selected account. Use this for non-Instagram settings and prefer it over raw metadata.'),
101
+ workspace_id: z
102
+ .string()
103
+ .optional()
104
+ .describe('Workspace ID to assign the post to (from whoami). If omitted, uses the account\'s workspace or the caller\'s default workspace.'),
105
+ });
106
+ export function buildCreatePostPayload(input) {
107
+ const { thread_posts, caption, post_type, instagram_settings, platform_settings, ...rest } = input;
108
+ if (thread_posts && thread_posts.length > 0) {
109
+ if (thread_posts.length < 2) {
110
+ throw new Error('thread_posts must contain at least 2 entries');
111
+ }
112
+ const platformHint = (input.platform || '').toLowerCase();
113
+ const isTwitter = platformHint === 'twitter' || platformHint === 'x';
114
+ const isThreads = platformHint === 'threads';
115
+ if (!isTwitter && !isThreads && !input.account_id) {
116
+ throw new Error('thread_posts requires `platform` to be "twitter" or "threads", or pass `account_id` for an X/Threads account.');
117
+ }
118
+ const arrayKey = isThreads ? 'threads_thread_posts' : 'x_thread_tweets';
119
+ const totalKey = isThreads ? 'threads_thread_total' : 'x_thread_total';
120
+ return {
121
+ ...rest,
122
+ platform: isTwitter ? 'twitter' : isThreads ? 'threads' : input.platform,
123
+ caption: thread_posts[0],
124
+ post_type: isThreads ? 'threads_thread' : 'x_thread',
125
+ metadata: {
126
+ [arrayKey]: thread_posts,
127
+ [totalKey]: thread_posts.length,
128
+ },
129
+ };
130
+ }
131
+ if (!caption) {
132
+ throw new Error('caption is required (or pass `thread_posts` for an X/Threads thread)');
133
+ }
134
+ return {
135
+ ...rest,
136
+ caption,
137
+ post_type,
138
+ ...(platform_settings || instagram_settings
139
+ ? { settings: { ...(instagram_settings ? { __type: 'instagram', ...instagram_settings } : {}), ...(platform_settings || {}) } }
140
+ : {}),
141
+ };
142
+ }
70
143
  export const createPostTool = {
71
144
  name: 'create_post',
72
145
  description: 'Schedule or immediately publish a social media post. This is a DESTRUCTIVE WRITE that creates content on the user\'s real social accounts — once scheduled_at passes, it will be posted publicly and cannot be un-posted.\n\n' +
@@ -74,85 +147,14 @@ export const createPostTool = {
74
147
  '1. Call `whoami` at the start of any new session to confirm which workspace and user you are acting for.\n' +
75
148
  '2. Show the user a preview containing ALL of: account(s) and platform(s), final caption text, scheduled time (in the user\'s timezone), media attached (if any), and workspace name.\n' +
76
149
  '3. Get explicit confirmation from the user (e.g. "post it", "yes schedule that", "looks good") BEFORE calling this tool. Do NOT infer consent from earlier instructions like "post about X every Monday" — confirm each individual post or the entire batch.\n' +
77
- '4. If scheduling multiple posts in one turn, list every post first and confirm the batch as a whole before calling create_post repeatedly.\n\n' +
150
+ '4. If scheduling multiple posts in one turn, list every post first and confirm the batch as a whole, then prefer `create_posts_batch` so they are created in one API request.\n\n' +
78
151
  'Provide either account_id OR username+platform to identify the account. If scheduled_at is omitted, the post publishes immediately. If workspace_id is omitted, the server resolves one from the social account, falling back to the caller\'s default (personal) workspace — pass workspace_id explicitly if the user has more than one workspace.\n\n' +
79
152
  'THREADS: Pass `thread_posts` (an array of 2+ strings) to schedule a multi-post thread on X (Twitter) or Threads (Meta). The first entry is the lead post; the rest are published as replies in the same chain. X entries are capped at 280 characters each (4000 for verified, 25000 for organization accounts); Threads entries are capped at 500 characters each. When `thread_posts` is set, `caption` is ignored.\n\n' +
80
153
  'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/playlist, LinkedIn document titles/mentions/video thumbnails, TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/link/title/video cover, GBP event/offer/CTA, X reply settings/polls, Threads reply controls/text attachments, Bluesky languages/alt text, and Instagram feed/story/reel/carousel/collaborators/first comments/trial Reels. `instagram_settings` remains as a backwards-compatible alias.',
81
- inputSchema: z.object({
82
- account_id: z.string().optional().describe('Social account ID (from list_accounts)'),
83
- username: z.string().optional().describe('Account username (alternative to account_id)'),
84
- platform: z
85
- .string()
86
- .optional()
87
- .describe('Platform name (required with username): instagram, twitter, linkedin, facebook, tiktok, threads, youtube, pinterest, google_business'),
88
- caption: z.string().optional().describe('The post caption/text content. Ignored when `thread_posts` is provided.'),
89
- scheduled_at: z
90
- .string()
91
- .optional()
92
- .describe('ISO 8601 datetime for scheduling (e.g. 2026-03-05T09:00:00Z). Omit for immediate publish.'),
93
- media_url: z.string().optional().describe('URL of media to attach (image or video). For threads, attaches to the lead post only.'),
94
- media_urls: z
95
- .array(z.string())
96
- .optional()
97
- .describe('Multiple media URLs for carousel posts'),
98
- post_type: z
99
- .string()
100
- .optional()
101
- .describe('Post type: text, image, video, carousel, reel, story. Auto-set to x_thread/threads_thread when `thread_posts` is provided.'),
102
- thread_posts: z
103
- .array(z.string())
104
- .optional()
105
- .describe('For X or Threads only: array of 2+ strings, one per post in the thread. The first entry leads, the rest reply in order. When set, the platform must be twitter or threads.'),
106
- instagram_settings: instagramSettingsSchema
107
- .optional()
108
- .describe('Instagram-specific settings: post_type (post/feed/story/reel/carousel), collaborators, user_tags, first_comment, media_alt_texts, is_trial_reel, graduation_strategy, reel_cover_url, reel_thumb_offset.'),
109
- platform_settings: platformSettingsSchema
110
- .optional()
111
- .describe('Platform-specific settings for the selected account. Use this for non-Instagram settings and prefer it over raw metadata.'),
112
- workspace_id: z
113
- .string()
114
- .optional()
115
- .describe('Workspace ID to assign the post to (from whoami). If omitted, uses the account\'s workspace or the caller\'s default workspace.'),
116
- }),
154
+ inputSchema: createPostInputSchema,
117
155
  async execute(client, input) {
118
- const { thread_posts, caption, post_type, instagram_settings, platform_settings, ...rest } = input;
119
- let payload;
120
- if (thread_posts && thread_posts.length > 0) {
121
- if (thread_posts.length < 2) {
122
- throw new Error('thread_posts must contain at least 2 entries');
123
- }
124
- const platformHint = (input.platform || '').toLowerCase();
125
- const isTwitter = platformHint === 'twitter' || platformHint === 'x';
126
- const isThreads = platformHint === 'threads';
127
- if (!isTwitter && !isThreads && !input.account_id) {
128
- throw new Error('thread_posts requires `platform` to be "twitter" or "threads", or pass `account_id` for an X/Threads account.');
129
- }
130
- const arrayKey = isThreads ? 'threads_thread_posts' : 'x_thread_tweets';
131
- const totalKey = isThreads ? 'threads_thread_total' : 'x_thread_total';
132
- payload = {
133
- ...rest,
134
- platform: isTwitter ? 'twitter' : isThreads ? 'threads' : input.platform,
135
- caption: thread_posts[0],
136
- post_type: isThreads ? 'threads_thread' : 'x_thread',
137
- metadata: {
138
- [arrayKey]: thread_posts,
139
- [totalKey]: thread_posts.length,
140
- },
141
- };
142
- }
143
- else {
144
- if (!caption) {
145
- throw new Error('caption is required (or pass `thread_posts` for an X/Threads thread)');
146
- }
147
- payload = {
148
- ...rest,
149
- caption,
150
- post_type,
151
- ...(platform_settings || instagram_settings
152
- ? { settings: { ...(instagram_settings ? { __type: 'instagram', ...instagram_settings } : {}), ...(platform_settings || {}) } }
153
- : {}),
154
- };
155
- }
156
+ const payload = buildCreatePostPayload(input);
157
+ const { thread_posts, instagram_settings, platform_settings } = input;
156
158
  const result = await client.createPost(payload);
157
159
  const p = result.post;
158
160
  const ws = result.workspace;