posterly-mcp-server 0.44.0 → 0.45.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.
Files changed (236) hide show
  1. package/README.md +310 -111
  2. package/dist/index.js +190 -894
  3. package/dist/lib/alias-transport.d.ts +84 -0
  4. package/dist/lib/alias-transport.js +193 -0
  5. package/dist/lib/api-client.d.ts +18 -0
  6. package/dist/lib/api-client.js +55 -0
  7. package/dist/lib/preview-token-core.d.ts +62 -0
  8. package/dist/lib/preview-token-core.js +131 -0
  9. package/dist/lib/preview-token.d.ts +23 -0
  10. package/dist/lib/preview-token.js +44 -0
  11. package/dist/lib/tool-registry.d.ts +246 -0
  12. package/dist/lib/tool-registry.js +394 -0
  13. package/dist/lib/tool-runtime.d.ts +68 -0
  14. package/dist/lib/tool-runtime.js +85 -0
  15. package/dist/lib/version.d.ts +1 -1
  16. package/dist/lib/version.js +1 -1
  17. package/dist/tools/audit-google-business-profile.js +1 -1
  18. package/dist/tools/connect-account.d.ts +4 -4
  19. package/dist/tools/connect-account.js +2 -2
  20. package/dist/tools/create-connect-session.d.ts +2 -2
  21. package/dist/tools/create-connect-session.js +2 -2
  22. package/dist/tools/create-post.d.ts +30 -7
  23. package/dist/tools/create-post.js +75 -9
  24. package/dist/tools/create-posts-batch.d.ts +4 -4
  25. package/dist/tools/create-posts-batch.js +14 -2
  26. package/dist/tools/create-webhook.d.ts +2 -2
  27. package/dist/tools/delete-post.d.ts +34 -10
  28. package/dist/tools/delete-post.js +52 -16
  29. package/dist/tools/generate-captions.d.ts +2 -2
  30. package/dist/tools/generate-image.d.ts +4 -4
  31. package/dist/tools/generate-image.js +2 -2
  32. package/dist/tools/generate-video.d.ts +6 -6
  33. package/dist/tools/generate-video.js +1 -1
  34. package/dist/tools/get-agent-signup-info.js +2 -2
  35. package/dist/tools/get-post.d.ts +16 -1
  36. package/dist/tools/get-post.js +35 -19
  37. package/dist/tools/list-accounts.d.ts +49 -3
  38. package/dist/tools/list-accounts.js +148 -33
  39. package/dist/tools/list-analytics.d.ts +111 -0
  40. package/dist/tools/list-analytics.js +393 -0
  41. package/dist/tools/list-brands.d.ts +38 -3
  42. package/dist/tools/list-brands.js +138 -20
  43. package/dist/tools/list-comments.d.ts +29 -9
  44. package/dist/tools/list-comments.js +75 -34
  45. package/dist/tools/list-conversations.d.ts +32 -9
  46. package/dist/tools/list-conversations.js +63 -27
  47. package/dist/tools/list-google-business-media.js +1 -1
  48. package/dist/tools/list-google-business-reviews.d.ts +32 -9
  49. package/dist/tools/list-google-business-reviews.js +77 -52
  50. package/dist/tools/list-jobs.d.ts +60 -0
  51. package/dist/tools/list-jobs.js +81 -0
  52. package/dist/tools/list-platforms.d.ts +62 -3
  53. package/dist/tools/list-platforms.js +118 -9
  54. package/dist/tools/list-posts.d.ts +2 -2
  55. package/dist/tools/manage-comment.d.ts +102 -0
  56. package/dist/tools/manage-comment.js +125 -0
  57. package/dist/tools/manage-conversation.d.ts +79 -0
  58. package/dist/tools/manage-conversation.js +75 -0
  59. package/dist/tools/manage-google-business-media.d.ts +103 -0
  60. package/dist/tools/manage-google-business-media.js +126 -0
  61. package/dist/tools/manage-google-business-review.d.ts +146 -0
  62. package/dist/tools/manage-google-business-review.js +115 -0
  63. package/dist/tools/manage-oauth-client.d.ts +121 -0
  64. package/dist/tools/manage-oauth-client.js +94 -0
  65. package/dist/tools/manage-webhook.d.ts +99 -0
  66. package/dist/tools/manage-webhook.js +87 -0
  67. package/dist/tools/start-signup.d.ts +2 -2
  68. package/dist/tools/submit-agent-feedback.d.ts +4 -4
  69. package/dist/tools/trigger-platform-helper.d.ts +2 -2
  70. package/dist/tools/update-post.d.ts +62 -11
  71. package/dist/tools/update-post.js +79 -26
  72. package/dist/tools/upload-media.d.ts +32 -9
  73. package/dist/tools/upload-media.js +54 -18
  74. package/dist/tools/validate-post.d.ts +4 -4
  75. package/dist/tools/validate-post.js +2 -2
  76. package/dist/tools/whoami.d.ts +15 -2
  77. package/dist/tools/whoami.js +221 -25
  78. package/package.json +5 -3
  79. package/scripts/test-alias-transport.mjs +368 -0
  80. package/scripts/test-client-header-sanitization.mjs +78 -0
  81. package/scripts/test-payload-builders.mjs +143 -20
  82. package/scripts/test-tool-annotations.mjs +38 -17
  83. package/server.json +9 -2
  84. package/src/index.ts +227 -1443
  85. package/src/lib/alias-transport.ts +233 -0
  86. package/src/lib/api-client.ts +65 -0
  87. package/src/lib/preview-token-core.ts +157 -0
  88. package/src/lib/preview-token.ts +54 -0
  89. package/src/lib/tool-registry.ts +538 -0
  90. package/src/lib/tool-runtime.ts +117 -0
  91. package/src/lib/version.ts +1 -1
  92. package/src/tools/audit-google-business-profile.ts +1 -1
  93. package/src/tools/connect-account.ts +2 -2
  94. package/src/tools/create-connect-session.ts +2 -2
  95. package/src/tools/create-post.ts +87 -12
  96. package/src/tools/create-posts-batch.ts +13 -2
  97. package/src/tools/delete-post.ts +60 -19
  98. package/src/tools/generate-image.ts +2 -2
  99. package/src/tools/generate-video.ts +1 -1
  100. package/src/tools/get-agent-signup-info.ts +2 -2
  101. package/src/tools/get-post.ts +35 -21
  102. package/src/tools/list-accounts.ts +187 -39
  103. package/src/tools/list-analytics.ts +444 -0
  104. package/src/tools/list-brands.ts +162 -26
  105. package/src/tools/list-comments.ts +86 -43
  106. package/src/tools/list-conversations.ts +81 -39
  107. package/src/tools/list-google-business-media.ts +1 -1
  108. package/src/tools/list-google-business-reviews.ts +93 -64
  109. package/src/tools/list-jobs.ts +91 -0
  110. package/src/tools/list-platforms.ts +135 -11
  111. package/src/tools/manage-comment.ts +142 -0
  112. package/src/tools/manage-conversation.ts +89 -0
  113. package/src/tools/manage-google-business-media.ts +147 -0
  114. package/src/tools/manage-google-business-review.ts +139 -0
  115. package/src/tools/manage-oauth-client.ts +116 -0
  116. package/src/tools/manage-webhook.ts +103 -0
  117. package/src/tools/update-post.ts +106 -39
  118. package/src/tools/upload-media.ts +76 -28
  119. package/src/tools/validate-post.ts +2 -1
  120. package/src/tools/whoami.ts +253 -30
  121. package/tool-annotations.json +76 -149
  122. package/tool-registry.json +2085 -0
  123. package/dist/tools/add-google-business-media.d.ts +0 -42
  124. package/dist/tools/add-google-business-media.js +0 -34
  125. package/dist/tools/create-oauth-client.d.ts +0 -40
  126. package/dist/tools/create-oauth-client.js +0 -20
  127. package/dist/tools/delete-comment.d.ts +0 -24
  128. package/dist/tools/delete-comment.js +0 -22
  129. package/dist/tools/delete-google-business-media.d.ts +0 -32
  130. package/dist/tools/delete-google-business-media.js +0 -17
  131. package/dist/tools/delete-google-business-review-reply.d.ts +0 -32
  132. package/dist/tools/delete-google-business-review-reply.js +0 -17
  133. package/dist/tools/delete-oauth-client.d.ts +0 -20
  134. package/dist/tools/delete-oauth-client.js +0 -13
  135. package/dist/tools/delete-post-group.d.ts +0 -20
  136. package/dist/tools/delete-post-group.js +0 -13
  137. package/dist/tools/delete-webhook.d.ts +0 -20
  138. package/dist/tools/delete-webhook.js +0 -13
  139. package/dist/tools/get-account-analytics.d.ts +0 -31
  140. package/dist/tools/get-account-analytics.js +0 -152
  141. package/dist/tools/get-brand-profile.d.ts +0 -16
  142. package/dist/tools/get-brand-profile.js +0 -73
  143. package/dist/tools/get-brand.d.ts +0 -16
  144. package/dist/tools/get-brand.js +0 -26
  145. package/dist/tools/get-comment.d.ts +0 -20
  146. package/dist/tools/get-comment.js +0 -36
  147. package/dist/tools/get-connect-link.d.ts +0 -28
  148. package/dist/tools/get-connect-link.js +0 -51
  149. package/dist/tools/get-connect-session.d.ts +0 -20
  150. package/dist/tools/get-connect-session.js +0 -54
  151. package/dist/tools/get-conversation.d.ts +0 -24
  152. package/dist/tools/get-conversation.js +0 -31
  153. package/dist/tools/get-google-business-review-link.d.ts +0 -24
  154. package/dist/tools/get-google-business-review-link.js +0 -19
  155. package/dist/tools/get-image-job.d.ts +0 -24
  156. package/dist/tools/get-image-job.js +0 -31
  157. package/dist/tools/get-learned-voice.d.ts +0 -16
  158. package/dist/tools/get-learned-voice.js +0 -22
  159. package/dist/tools/get-mcp-status.d.ts +0 -8
  160. package/dist/tools/get-mcp-status.js +0 -182
  161. package/dist/tools/get-performance-profile.d.ts +0 -16
  162. package/dist/tools/get-performance-profile.js +0 -39
  163. package/dist/tools/get-platform-schema.d.ts +0 -24
  164. package/dist/tools/get-platform-schema.js +0 -48
  165. package/dist/tools/get-post-analytics.d.ts +0 -39
  166. package/dist/tools/get-post-analytics.js +0 -222
  167. package/dist/tools/get-post-insights.d.ts +0 -28
  168. package/dist/tools/get-post-insights.js +0 -39
  169. package/dist/tools/get-post-missing.d.ts +0 -16
  170. package/dist/tools/get-post-missing.js +0 -12
  171. package/dist/tools/get-video-job.d.ts +0 -24
  172. package/dist/tools/get-video-job.js +0 -31
  173. package/dist/tools/list-brand-accounts.d.ts +0 -16
  174. package/dist/tools/list-brand-accounts.js +0 -24
  175. package/dist/tools/reply-google-business-review.d.ts +0 -36
  176. package/dist/tools/reply-google-business-review.js +0 -18
  177. package/dist/tools/reply-to-comment.d.ts +0 -32
  178. package/dist/tools/reply-to-comment.js +0 -17
  179. package/dist/tools/send-message.d.ts +0 -28
  180. package/dist/tools/send-message.js +0 -16
  181. package/dist/tools/suggest-google-business-review-reply.d.ts +0 -48
  182. package/dist/tools/suggest-google-business-review-reply.js +0 -27
  183. package/dist/tools/sync-inbox.d.ts +0 -24
  184. package/dist/tools/sync-inbox.js +0 -18
  185. package/dist/tools/test-webhook.d.ts +0 -20
  186. package/dist/tools/test-webhook.js +0 -14
  187. package/dist/tools/update-comment.d.ts +0 -28
  188. package/dist/tools/update-comment.js +0 -21
  189. package/dist/tools/update-oauth-client.d.ts +0 -44
  190. package/dist/tools/update-oauth-client.js +0 -21
  191. package/dist/tools/update-post-release-id.d.ts +0 -28
  192. package/dist/tools/update-post-release-id.js +0 -18
  193. package/dist/tools/update-post-status.d.ts +0 -28
  194. package/dist/tools/update-post-status.js +0 -23
  195. package/dist/tools/update-webhook.d.ts +0 -40
  196. package/dist/tools/update-webhook.js +0 -21
  197. package/dist/tools/upload-media-from-url.d.ts +0 -24
  198. package/dist/tools/upload-media-from-url.js +0 -26
  199. package/src/tools/add-google-business-media.ts +0 -50
  200. package/src/tools/create-oauth-client.ts +0 -36
  201. package/src/tools/delete-comment.ts +0 -29
  202. package/src/tools/delete-google-business-media.ts +0 -30
  203. package/src/tools/delete-google-business-review-reply.ts +0 -30
  204. package/src/tools/delete-oauth-client.ts +0 -23
  205. package/src/tools/delete-post-group.ts +0 -17
  206. package/src/tools/delete-webhook.ts +0 -17
  207. package/src/tools/get-account-analytics.ts +0 -171
  208. package/src/tools/get-brand-profile.ts +0 -86
  209. package/src/tools/get-brand.ts +0 -34
  210. package/src/tools/get-comment.ts +0 -47
  211. package/src/tools/get-connect-link.ts +0 -61
  212. package/src/tools/get-connect-session.ts +0 -63
  213. package/src/tools/get-conversation.ts +0 -44
  214. package/src/tools/get-google-business-review-link.ts +0 -30
  215. package/src/tools/get-image-job.ts +0 -36
  216. package/src/tools/get-learned-voice.ts +0 -31
  217. package/src/tools/get-mcp-status.ts +0 -212
  218. package/src/tools/get-performance-profile.ts +0 -47
  219. package/src/tools/get-platform-schema.ts +0 -56
  220. package/src/tools/get-post-analytics.ts +0 -243
  221. package/src/tools/get-post-insights.ts +0 -60
  222. package/src/tools/get-post-missing.ts +0 -16
  223. package/src/tools/get-video-job.ts +0 -36
  224. package/src/tools/list-brand-accounts.ts +0 -36
  225. package/src/tools/reply-google-business-review.ts +0 -32
  226. package/src/tools/reply-to-comment.ts +0 -30
  227. package/src/tools/send-message.ts +0 -28
  228. package/src/tools/suggest-google-business-review-reply.ts +0 -44
  229. package/src/tools/sync-inbox.ts +0 -28
  230. package/src/tools/test-webhook.ts +0 -18
  231. package/src/tools/update-comment.ts +0 -31
  232. package/src/tools/update-oauth-client.ts +0 -38
  233. package/src/tools/update-post-release-id.ts +0 -25
  234. package/src/tools/update-post-status.ts +0 -31
  235. package/src/tools/update-webhook.ts +0 -36
  236. package/src/tools/upload-media-from-url.ts +0 -33
@@ -31,7 +31,7 @@ const PLATFORM_CREDENTIAL_FIELDS: Record<string, string[]> = {
31
31
  export const connectAccountTool = {
32
32
  name: 'connect_account',
33
33
  description:
34
- 'Connect a credential-based social account (telegram, bluesky, discord, wordpress, devto, hashnode, lemmy) directly, without a browser session. Call get_connect_link first to discover the exact credential fields the platform needs. Prefer scoped secrets: app passwords (Bluesky, WordPress), bot tokens (Telegram), webhook URLs (Discord), and API tokens (Dev.to, Hashnode) over primary passwords. Warn the user that any credential they share passes through this conversation. For OAuth platforms (Instagram, X, LinkedIn, ...) use create_connect_session instead.',
34
+ 'Connect a credential-based social account (telegram, bluesky, discord, wordpress, devto, hashnode, lemmy) directly, without a browser session. Call list_platforms with view=connect_link first to discover the exact credential fields the platform needs. Prefer scoped secrets: app passwords (Bluesky, WordPress), bot tokens (Telegram), webhook URLs (Discord), and API tokens (Dev.to, Hashnode) over primary passwords. Warn the user that any credential they share passes through this conversation. For OAuth platforms (Instagram, X, LinkedIn, ...) use create_connect_session instead.',
35
35
  inputSchema: z.object({
36
36
  platform: z
37
37
  .enum(CREDENTIAL_PLATFORMS)
@@ -70,7 +70,7 @@ export const connectAccountTool = {
70
70
 
71
71
  const missing = allowedFields.filter((field) => !(field in credentials));
72
72
  if (missing.length > 0) {
73
- return `Missing credential field(s) for ${input.platform}: ${missing.join(', ')}. Call get_connect_link with platform=${input.platform} to see field descriptions.`;
73
+ return `Missing credential field(s) for ${input.platform}: ${missing.join(', ')}. Call list_platforms with view=connect_link and target=${input.platform} to see field descriptions.`;
74
74
  }
75
75
 
76
76
  const result = await client.connectAccountCredentials({
@@ -6,7 +6,7 @@ import { CONNECT_INPUTS } from '../generated/platform-manifest.js';
6
6
  export const createConnectSessionTool = {
7
7
  name: 'create_connect_session',
8
8
  description:
9
- 'Create a short-lived posterly dashboard handoff session for connecting a social account. Send the secure connection URL to the user, then poll get_connect_session to narrate progress. Do not ask for social media passwords or OAuth codes; posterly handles those browser steps.',
9
+ 'Create a short-lived posterly dashboard handoff session for connecting a social account. Send the secure connection URL to the user, then poll list_accounts with view=connect_session to narrate progress. Do not ask for social media passwords or OAuth codes; posterly handles those browser steps.',
10
10
  inputSchema: z.object({
11
11
  platform: z
12
12
  .enum(CONNECT_INPUTS)
@@ -49,7 +49,7 @@ function formatConnectSession(session: ConnectSession, includeRaw: boolean): str
49
49
  `Expires: ${formatLocalDateTime(session.expires_at)}`,
50
50
  `Dashboard connect page: ${DASHBOARD_CONNECT_URL}`,
51
51
  '',
52
- 'Next step for the AI agent: send the secure connection URL to the user, explain that posterly will handle the browser OAuth step, then poll get_connect_session until the account is connected or the session ends.',
52
+ 'Next step for the AI agent: send the secure connection URL to the user, explain that posterly will handle the browser OAuth step, then poll list_accounts with view=connect_session until the account is connected or the session ends.',
53
53
  includeRaw ? `\nRaw connect session:\n${JSON.stringify(session, null, 2)}` : '',
54
54
  ].filter(Boolean).join('\n');
55
55
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import type { PosterlyClient } from '../lib/api-client.js';
2
+ import type { PosterlyClient, Account } from '../lib/api-client.js';
3
3
  import { dashboardUrlForPost, formatLocalDateTime } from '../lib/format.js';
4
4
  import { SUPPORTED_PLATFORM_INPUTS, SUPPORTED_PLATFORM_IDS } from '../generated/platform-manifest.js';
5
5
 
@@ -156,7 +156,7 @@ export const createPostPayloadInputSchema = z.object({
156
156
  .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.'),
157
157
  instagram_settings: instagramSettingsSchema
158
158
  .optional()
159
- .describe('Instagram-specific settings. If “tag” is ambiguous, distinguish caption @mentions (put @username in caption), native media tags (user_tags), and co-author invitations (collaborators). Native media tags work with eligible direct or Meta-linked accounts; collaborators require an eligible Meta-linked account. Call get_platform_schema(account_id) first.'),
159
+ .describe('Instagram-specific settings. If “tag” is ambiguous, distinguish caption @mentions (put @username in caption), native media tags (user_tags), and co-author invitations (collaborators). Native media tags work with eligible direct or Meta-linked accounts; collaborators require an eligible Meta-linked account. Call list_platforms with view=schema and account_id first.'),
160
160
  platform_settings: platformSettingsSchema
161
161
  .optional()
162
162
  .describe('Platform-specific settings for the selected account. Use this for non-Instagram settings and prefer it over raw metadata.'),
@@ -173,7 +173,61 @@ export const createPostInputSchema = createPostPayloadInputSchema.extend({
173
173
  export type CreatePostInput = z.infer<typeof createPostInputSchema>;
174
174
  export type CreatePostPayloadInput = z.infer<typeof createPostPayloadInputSchema>;
175
175
 
176
- export function buildCreatePostPayload(input: CreatePostPayloadInput | CreatePostInput): Parameters<PosterlyClient['createPost']>[0] {
176
+ export type AccountPlatformLookup =
177
+ | { found: true; platform: string | null }
178
+ | { found: false; detail: string };
179
+
180
+ export type AccountPlatformResolver = (accountId: string, workspaceId?: string) => Promise<AccountPlatformLookup>;
181
+
182
+ /**
183
+ * Builds a resolver that answers "what platform is this account_id on?" via
184
+ * client.listAccounts() (there is no GET /accounts/:id), for thread_posts
185
+ * calls that gave account_id without platform. Caches one in-flight lookup
186
+ * per workspace_id (including the unscoped list, keyed ''), so
187
+ * create_posts_batch never issues more than one accounts request per
188
+ * distinct workspace_id even though every item in the batch calls this
189
+ * independently: the cache is populated synchronously (before the first
190
+ * await) on the first call for a given workspace_id, so concurrent
191
+ * Promise.all callers for the same workspace_id share the one in-flight
192
+ * request. A failed lookup (non-2xx, missing accounts:read, network error)
193
+ * is cached too, so it is reported once per workspace_id rather than
194
+ * surfacing a fresh error per item.
195
+ */
196
+ export function createAccountPlatformResolver(client: PosterlyClient): AccountPlatformResolver {
197
+ const cache = new Map<string, Promise<{ ok: true; platforms: Map<string, string> } | { ok: false; detail: string }>>();
198
+ const lookupForWorkspace = (workspaceKey: string) => {
199
+ let pending = cache.get(workspaceKey);
200
+ if (!pending) {
201
+ pending = (async () => {
202
+ try {
203
+ const accounts: Account[] = await client.listAccounts(workspaceKey ? { workspace_id: workspaceKey } : undefined);
204
+ const platforms = new Map<string, string>();
205
+ for (const account of accounts) {
206
+ if (account && typeof account.platform === 'string' && account.id !== undefined && account.id !== null) {
207
+ platforms.set(String(account.id), account.platform);
208
+ }
209
+ }
210
+ return { ok: true as const, platforms };
211
+ } catch (error: any) {
212
+ return { ok: false as const, detail: error?.message || 'accounts lookup failed' };
213
+ }
214
+ })();
215
+ cache.set(workspaceKey, pending);
216
+ }
217
+ return pending;
218
+ };
219
+ return async (accountId, workspaceId) => {
220
+ const workspaceKey = workspaceId || '';
221
+ const lookup = await lookupForWorkspace(workspaceKey);
222
+ if (!lookup.ok) return { found: false, detail: lookup.detail };
223
+ return { found: true, platform: lookup.platforms.get(String(accountId)) ?? null };
224
+ };
225
+ }
226
+
227
+ export async function buildCreatePostPayload(
228
+ input: CreatePostPayloadInput | CreatePostInput,
229
+ resolvePlatform: AccountPlatformResolver,
230
+ ): Promise<Parameters<PosterlyClient['createPost']>[0]> {
177
231
  const { confirm: _confirm, thread_posts, caption, post_type, instagram_settings, platform_settings, ...rest } = input as CreatePostInput & CreatePostPayloadInput;
178
232
 
179
233
  if (thread_posts && thread_posts.length > 0) {
@@ -181,12 +235,33 @@ export function buildCreatePostPayload(input: CreatePostPayloadInput | CreatePos
181
235
  throw new Error('thread_posts must contain at least 2 entries');
182
236
  }
183
237
  const platformHint = (input.platform || '').toLowerCase();
184
- const isTwitter = platformHint === 'twitter' || platformHint === 'x';
185
- const isThreads = platformHint === 'threads';
186
- if (!isTwitter && !isThreads && !input.account_id) {
187
- throw new Error(
188
- 'thread_posts requires `platform` to be "twitter" or "threads", or pass `account_id` for an X/Threads account.',
189
- );
238
+ let isTwitter = platformHint === 'twitter' || platformHint === 'x';
239
+ let isThreads = platformHint === 'threads';
240
+ if (!isTwitter && !isThreads) {
241
+ if (!input.account_id) {
242
+ throw new Error(
243
+ 'thread_posts requires `platform` to be "twitter" or "threads", or pass `account_id` for an X/Threads account.',
244
+ );
245
+ }
246
+ // No platform hint: never guess X. Resolve the account's real platform
247
+ // first, so a Threads account_id builds a threads_thread, not an
248
+ // x_thread that the server then rejects.
249
+ const lookup = await resolvePlatform(input.account_id, input.workspace_id);
250
+ if (!lookup.found) {
251
+ throw new Error(
252
+ `thread_posts could not resolve account_id's platform (${lookup.detail}). Pass \`platform\` explicitly.`,
253
+ );
254
+ } else if (lookup.platform === 'threads') {
255
+ isThreads = true;
256
+ } else if (lookup.platform === 'twitter') {
257
+ isTwitter = true;
258
+ } else {
259
+ throw new Error(
260
+ lookup.platform
261
+ ? `thread_posts requires an X/Twitter or Threads account; account_id resolved to platform "${lookup.platform}".`
262
+ : 'thread_posts requires `platform` to be "twitter" or "threads", or an `account_id` that exists in list_accounts. Pass `platform` explicitly.',
263
+ );
264
+ }
190
265
  }
191
266
  const arrayKey = isThreads ? 'threads_thread_posts' : 'x_thread_tweets';
192
267
  const totalKey = isThreads ? 'threads_thread_total' : 'x_thread_total';
@@ -237,9 +312,9 @@ export const createPostTool = {
237
312
  '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' +
238
313
  'AFTER CALLING: Tell the user the post was created, include the posterly dashboard link returned by the tool, and offer the next natural action. Do not narrate raw HTTP, curl, or API plumbing.\n\n' +
239
314
  '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' +
240
- 'MEDIA URLS: Posterly storage URLs are used as-is. Third-party HTTP(S) media URLs are copied into posterly storage before the post is saved, so API-created posts do not later fail on expired signed URLs. Short-lived signed URLs must still be live when this tool runs. You can also call `upload_media_from_url` first if you want to upload once and reuse the returned posterly URL across posts.\n\n' +
315
+ 'MEDIA URLS: Posterly storage URLs are used as-is. Third-party HTTP(S) media URLs are copied into posterly storage before the post is saved, so API-created posts do not later fail on expired signed URLs. Short-lived signed URLs must still be live when this tool runs. You can also call `upload_media` with `url` first if you want to upload once and reuse the returned posterly URL across posts.\n\n' +
241
316
  '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' +
242
- 'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `get_platform_schema` with the account ID first. `instagram_settings` remains as a backwards-compatible alias.\n\n' +
317
+ 'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `list_platforms` with `view: "schema"` and the account ID first. `instagram_settings` remains as a backwards-compatible alias.\n\n' +
243
318
  'TIKTOK MEDIA: TikTok supports a single video or a photo slideshow of 1 to 35 images, never multiple videos. Image media auto-detects as a slideshow, so you usually do not set post_type or media_type for photos and every image is posted. Pass `platform_settings.media_type: "PHOTO"` to force a slideshow explicitly.',
244
319
  inputSchema: createPostInputSchema,
245
320
 
@@ -250,7 +325,7 @@ export const createPostTool = {
250
325
  if (input.confirm !== true) {
251
326
  throw new Error('Refusing to create post without confirm=true after explicit user confirmation.');
252
327
  }
253
- const payload = buildCreatePostPayload(input);
328
+ const payload = await buildCreatePostPayload(input, createAccountPlatformResolver(client));
254
329
  const { thread_posts, instagram_settings, platform_settings } = input;
255
330
 
256
331
  const result = await client.createPost(payload);
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { PosterlyClient } from '../lib/api-client.js';
3
3
  import { dashboardUrlForPostList, formatLocalDateTime } from '../lib/format.js';
4
- import { buildCreatePostPayload, createPostPayloadInputSchema, type CreatePostPayloadInput } from './create-post.js';
4
+ import { buildCreatePostPayload, createAccountPlatformResolver, createPostPayloadInputSchema, type CreatePostPayloadInput } from './create-post.js';
5
5
 
6
6
  export const createPostsBatchTool = {
7
7
  name: 'create_posts_batch',
@@ -26,7 +26,18 @@ export const createPostsBatchTool = {
26
26
  if (input.confirm !== true) {
27
27
  throw new Error('Refusing to create batch posts without confirm=true after explicit user confirmation.');
28
28
  }
29
- const payloads = input.posts.map((post) => buildCreatePostPayload(post));
29
+ // One resolver shared across the whole batch: createAccountPlatformResolver
30
+ // caches its accounts lookup per workspace_id, so N items that all need
31
+ // thread_posts platform resolution for the same workspace still cost one
32
+ // listAccounts() call, not N.
33
+ const resolvePlatform = createAccountPlatformResolver(client);
34
+ const payloads = await Promise.all(input.posts.map(async (post, index) => {
35
+ try {
36
+ return await buildCreatePostPayload(post, resolvePlatform);
37
+ } catch (error: any) {
38
+ throw new Error(`Item ${index}: ${error?.message || 'invalid post input'}`);
39
+ }
40
+ }));
30
41
  const result = await client.createPostsBatch({ posts: payloads });
31
42
 
32
43
  const createdPosts = result.posts.map((item) => item.post);
@@ -1,31 +1,72 @@
1
1
  import { z } from 'zod';
2
2
  import type { PosterlyClient } from '../lib/api-client.js';
3
- import { dashboardUrlForPosts } from '../lib/format.js';
3
+ import { code, dashboardUrlForPosts } from '../lib/format.js';
4
+ import { previewThenConfirm, validateArgs, type ToolContext } from '../lib/tool-runtime.js';
5
+
6
+ type DeletePostInput = {
7
+ post_id?: number;
8
+ group_id?: string;
9
+ confirm?: boolean;
10
+ preview_id?: string;
11
+ };
4
12
 
5
13
  export const deletePostTool = {
6
14
  name: 'delete_post',
7
15
  description:
8
- 'Delete a scheduled or draft post. DESTRUCTIVE and IRREVERSIBLE - the post and its caption cannot be recovered. Cannot delete published or currently publishing posts.\n\n' +
9
- 'REQUIRED BEFORE CALLING: Fetch the post with `get_post` first and show the user what will be deleted (caption, account, scheduled time). Get explicit confirmation ("yes delete it", "remove it") before calling. Never delete multiple posts in a single batch without listing each one and confirming the full list.',
16
+ 'Delete posts. DESTRUCTIVE and IRREVERSIBLE: deleted posts and captions cannot be recovered, and published or currently publishing posts are never deleted. post_id: delete one scheduled or draft post; fetch it with `get_post` first, show the user what will be deleted (caption, account, scheduled time), and pass confirm=true only after explicit confirmation ("yes delete it", "remove it"). group_id: delete every draft, scheduled, failed, or paused post matching a caller-defined group_id, post_group_id, api_group_id, or release_id; preview then confirm: call without confirm to get a preview and preview_id, show it, then call again with confirm=true and that preview_id. Never delete several posts one by one without listing each and confirming the full list.',
10
17
  inputSchema: z.object({
11
- post_id: z.number().describe('The post ID to delete'),
12
- confirm: z.literal(true).describe('Must be true after explicit user confirmation of the post deletion.'),
18
+ post_id: z.number().optional().describe('Delete this one post.'),
19
+ group_id: z.string().min(1).max(160).optional().describe('Delete every unpublished post in this group or release instead.'),
20
+ confirm: z
21
+ .boolean()
22
+ .optional()
23
+ .describe('post_id: true after explicit user confirmation of the deletion. group_id: leave out to get a preview; true only with the preview_id after the user approved it.'),
24
+ preview_id: z.string().optional().describe('group_id: the preview_id from the preview call. Required with confirm: true.'),
13
25
  }),
26
+ /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
27
+ legacySchemas: {
28
+ delete_post_group: z.object({
29
+ group_id: z.string().min(1).max(160),
30
+ confirm: z.literal(true),
31
+ }),
32
+ },
14
33
 
15
- async execute(
16
- client: PosterlyClient,
17
- input: { post_id: number; confirm: true },
18
- ) {
19
- if (input.confirm !== true) {
20
- throw new Error('Refusing to delete post without confirm=true after explicit user confirmation.');
34
+ async execute(client: PosterlyClient, input: DeletePostInput, ctx: ToolContext) {
35
+ const { mode, args } = validateArgs(ctx, 'delete_post', input);
36
+ if (mode === 'group') {
37
+ return previewThenConfirm({
38
+ tool: 'delete_post',
39
+ action: 'group',
40
+ args,
41
+ nonce: false,
42
+ legacyRefusal: 'Refusing to delete post group without confirm=true after explicit user confirmation.',
43
+ ctx,
44
+ // GET /api/v1/posts has no group filter, so the preview says in plain
45
+ // words which posts match instead of listing them.
46
+ describe: async () => [
47
+ `Deletes every draft, scheduled, failed, or paused post whose group_id, post_group_id, api_group_id, or release_id is ${code(args.group_id)}. Published posts are never deleted. This cannot be undone.`,
48
+ 'To see the posts first, call list_posts and check each post\'s group or release ID.',
49
+ ].join('\n\n'),
50
+ run: async () => {
51
+ const result = await client.deletePostGroup(args.group_id);
52
+ return JSON.stringify(result, null, 2);
53
+ },
54
+ });
21
55
  }
22
- const result = await client.deletePost(input.post_id);
23
- return [
24
- `Post #${result.id} deleted successfully.`,
25
- 'It has been removed from the posterly queue.',
26
- `View queue in posterly: ${dashboardUrlForPosts()}`,
27
- '',
28
- 'Next step for the AI agent: tell the user the post is gone and offer to create, reschedule, or review the next post.',
29
- ].join('\n');
56
+ return deleteOne(client, args as { post_id: number; confirm?: boolean });
30
57
  },
31
58
  };
59
+
60
+ async function deleteOne(client: PosterlyClient, input: { post_id: number; confirm?: boolean }): Promise<string> {
61
+ if (input.confirm !== true) {
62
+ throw new Error('Refusing to delete post without confirm=true after explicit user confirmation.');
63
+ }
64
+ const result = await client.deletePost(input.post_id);
65
+ return [
66
+ `Post #${result.id} deleted successfully.`,
67
+ 'It has been removed from the posterly queue.',
68
+ `View queue in posterly: ${dashboardUrlForPosts()}`,
69
+ '',
70
+ 'Next step for the AI agent: tell the user the post is gone and offer to create, reschedule, or review the next post.',
71
+ ].join('\n');
72
+ }
@@ -5,7 +5,7 @@ import { mdKeyValue, mdTitle } from '../lib/format.js';
5
5
  export const generateImageTool = {
6
6
  name: 'generate_image',
7
7
  description:
8
- 'Queue an AI image job via posterly using Nano Banana (Gemini) or Grok Imagine Image 2.0 (xAI). Returns job_id. Poll get_image_job until status is completed, then pass urls to create_post as media_url / media_urls. Gemini thinking high does not change the credit price.\n\n' +
8
+ 'Queue an AI image job via posterly using Nano Banana (Gemini) or Grok Imagine Image 2.0 (xAI). Returns job_id. Poll list_jobs with type=image until status is completed, then pass urls to create_post as media_url / media_urls. Gemini thinking high does not change the credit price.\n\n' +
9
9
  'COSTS CREDITS. Every call consumes part of the user\'s monthly AI image quota (or purchased credits once the quota is exhausted). Do NOT call speculatively - always describe the image you\'re about to generate (subject, style, aspect ratio, quality/thinking, resolution) to the user and get confirmation before calling.\n\n' +
10
10
  'If the user is over their plan limit and has no credits, this tool returns a 402 with upgrade info. Surface that message verbatim - do not retry.\n\n' +
11
11
  'Common aspect ratios by platform:\n' +
@@ -100,7 +100,7 @@ export const generateImageTool = {
100
100
  ['Credits used', result.credits_used],
101
101
  ['Billed from', result.usage?.billed_from],
102
102
  ]),
103
- result.message || 'Poll get_image_job with this job_id until status is completed, then pass urls to create_post.',
103
+ result.message || 'Poll list_jobs with type=image and this job_id until status is completed, then pass urls to create_post.',
104
104
  ].filter(Boolean).join('\n\n');
105
105
  },
106
106
  };
@@ -4,7 +4,7 @@ import type { PosterlyClient } from '../lib/api-client.js';
4
4
  export const generateVideoTool = {
5
5
  name: 'generate_video',
6
6
  description:
7
- 'Queue an AI video generation job with Google Veo 3.1 or xAI Grok Imagine Video 1.5. COSTS CREDITS: confirm provider, prompt, duration, resolution, aspect ratio, audio choice, and credit cost with the user before calling. Grok supports 1–15 seconds and 480p–1080p; reference-to-video is capped at 720p. Poll get_video_job for status and final video_url.',
7
+ 'Queue an AI video generation job with Google Veo 3.1 or xAI Grok Imagine Video 1.5. COSTS CREDITS: confirm provider, prompt, duration, resolution, aspect ratio, audio choice, and credit cost with the user before calling. Grok supports 1 to 15 seconds and 480p to 1080p; reference-to-video is capped at 720p. Poll list_jobs with type=video for status and final video_url.',
8
8
  inputSchema: z.object({
9
9
  provider: z.enum(['google', 'xai']).default('google').optional(),
10
10
  prompt: z.string().min(5).max(4000),
@@ -18,14 +18,14 @@ export const getAgentSignupInfoTool = {
18
18
  authState,
19
19
  '',
20
20
  'Pre-auth tools:',
21
- '- get_mcp_status: checks the installed server version, latest npm version, MCP endpoint health, API auth health, and whether POSTERLY_API_KEY is configured.',
21
+ '- whoami with view=status: checks the installed server version, latest npm version, MCP endpoint health, API auth health, and whether POSTERLY_API_KEY is configured.',
22
22
  '- start_signup: starts paid signup and returns a signup poll URL, a browser Checkout fallback, and, when enabled, a prepaid PaymentIntent for a Link virtual card (credential_type: card).',
23
23
  '- get_signup_session: polls payment, password, and agent-access status.',
24
24
  '',
25
25
  'After posterly access is installed, onboard the user IN THIS chat (do not send them to /onboarding-v2):',
26
26
  '- whoami: confirm the paid account and read onboarding.next_step.',
27
27
  '- About you: confirm name and IANA timezone.',
28
- '- create_connect_session / get_connect_session: first social account in the browser.',
28
+ '- create_connect_session, then list_accounts with view=connect_session: first social account in the browser.',
29
29
  '- Brand voice: ask how they want to sound, then use that on captions.',
30
30
  '- create_post: first scheduled post after validate_post and explicit confirm.',
31
31
  '',
@@ -1,35 +1,49 @@
1
1
  import { z } from 'zod';
2
2
  import type { PosterlyClient } from '../lib/api-client.js';
3
3
  import { dashboardUrlForPost, formatLocalDateTime } from '../lib/format.js';
4
+ import { validateArgs, type ToolContext } from '../lib/tool-runtime.js';
4
5
 
5
6
  export const getPostTool = {
6
7
  name: 'get_post',
7
8
  description:
8
- 'Get details of a specific post by ID. Returns caption, status, scheduled time, media, and platform info.',
9
+ 'One post by ID. view=post (default): caption, status, scheduled time, media, and platform info. view=missing: whether the post is missing required content, media, account, platform settings, or metadata before it can publish; use it to repair failed or imported posts.',
9
10
  inputSchema: z.object({
10
11
  post_id: z.number().describe('The post ID to look up'),
12
+ view: z.enum(['post', 'missing']).optional().describe('post (default) or missing.'),
11
13
  }),
14
+ /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
15
+ legacySchemas: {
16
+ get_post_missing: z.object({ post_id: z.number().int().positive() }),
17
+ },
12
18
 
13
- async execute(
14
- client: PosterlyClient,
15
- input: { post_id: number },
16
- ) {
17
- const result = await client.getPost(input.post_id);
18
- const p = result.post as Record<string, any>;
19
+ async execute(client: PosterlyClient, input: { post_id: number; view?: 'post' | 'missing' }, ctx: ToolContext) {
20
+ const { mode, args } = validateArgs(ctx, 'get_post', input);
21
+ if (mode === 'missing') return postMissing(client, args as { post_id: number });
22
+ return post(client, args as { post_id: number });
23
+ },
24
+ };
19
25
 
20
- const lines = [
21
- `Post #${p.id}`,
22
- `• Status: ${p.status}`,
23
- `• Caption: ${p.content || '(empty)'}`,
24
- `• Type: ${p.post_type || 'unknown'}`,
25
- `• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`,
26
- `• View in posterly: ${dashboardUrlForPost({ id: p.id, scheduled_at: p.scheduled_at })}`,
27
- ];
26
+ async function post(client: PosterlyClient, input: { post_id: number }): Promise<string> {
27
+ const result = await client.getPost(input.post_id);
28
+ const p = result.post as Record<string, any>;
28
29
 
29
- if (p.platform_post_url) lines.push(`• Published URL: ${p.platform_post_url}`);
30
- if (p.media_url) lines.push(`• Media: ${p.media_url}`);
31
- if (p.media_urls?.length) lines.push(`• Media (${p.media_urls.length}): ${p.media_urls.join(', ')}`);
30
+ const lines = [
31
+ `Post #${p.id}`,
32
+ `• Status: ${p.status}`,
33
+ `• Caption: ${p.content || '(empty)'}`,
34
+ `• Type: ${p.post_type || 'unknown'}`,
35
+ `• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`,
36
+ `• View in posterly: ${dashboardUrlForPost({ id: p.id, scheduled_at: p.scheduled_at })}`,
37
+ ];
32
38
 
33
- return lines.join('\n');
34
- },
35
- };
39
+ if (p.platform_post_url) lines.push(`• Published URL: ${p.platform_post_url}`);
40
+ if (p.media_url) lines.push(`• Media: ${p.media_url}`);
41
+ if (p.media_urls?.length) lines.push(`• Media (${p.media_urls.length}): ${p.media_urls.join(', ')}`);
42
+
43
+ return lines.join('\n');
44
+ }
45
+
46
+ async function postMissing(client: PosterlyClient, input: { post_id: number }): Promise<string> {
47
+ const result = await client.getPostMissing(input.post_id);
48
+ return JSON.stringify(result, null, 2);
49
+ }