posterly-mcp-server 0.52.2 → 0.53.2

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.
@@ -48,7 +48,7 @@ export function formatSignedUploadBatch(batch, requested) {
48
48
  }
49
49
  export const createSignedUploadTool = {
50
50
  name: 'create_signed_upload',
51
- description: 'Create signed upload URLs for larger images, videos or PDFs, 1 to 20 files per call. Accepts JPEG, PNG, GIF, WebP, MP4, MOV, WebM, and PDF up to 50MB (a PDF is for LinkedIn document posts); HEIC is not accepted. For one file pass filename, content_type and size. For several pass files: [{filename, content_type, size}] (up to 20) and get one slot per file, with any file that fails reported in place. PUT the raw bytes of each file to its upload_url (object storage) with the returned headers, then pass public_url to create_post / create_posts_batch. For a PDF, create the post with post_type document, media_url set to that public_url and a document_title in settings (LinkedIn only). Pinning is available per request with pin_content_type: true, which locks each slot to the content_type you declare (a PUT with any other Content-Type then fails with 403). posterly may turn it on by default in the future, so always send the Content-Type header returned with the slot. Slots expire in 15 minutes.',
51
+ description: 'Create signed upload URLs for larger images, videos or PDFs, 1 to 20 files per call. Accepts JPEG, PNG, GIF, WebP, MP4, MOV, WebM, and PDF up to 50MB (a PDF is for LinkedIn document posts); HEIC is not accepted. For one file pass filename, content_type and size. For several pass files: [{filename, content_type, size}] and get one slot per file, with any file that fails reported in place. PUT the raw bytes of each file to its upload_url (object storage) with the returned headers, then pass public_url to create_post / create_posts_batch. For a PDF, create the post with post_type document, media_url set to that public_url and a document_title in settings (LinkedIn only). Pinning is available per request with pin_content_type: true, which locks each slot to the content_type you declare (a PUT with any other Content-Type then fails with 403). posterly may turn it on by default in the future, so always send the Content-Type header returned with the slot. Slots expire in 15 minutes.',
52
52
  inputSchema: z.object({
53
53
  filename: z.string().optional().describe('Single file: filename with extension, e.g. launch-video.mp4. Omit when using files.'),
54
54
  content_type: z.string().optional().describe('Single file: MIME type, e.g. video/mp4. Omit when using files.'),
@@ -58,11 +58,11 @@ export const createSignedUploadTool = {
58
58
  .min(1)
59
59
  .max(20)
60
60
  .optional()
61
- .describe('Batch: 1 to 20 files, each with filename, content_type and size. Use instead of the single-file fields.'),
61
+ .describe('Batch: 1 to 20 {filename, content_type, size}. Use instead of the single-file fields.'),
62
62
  pin_content_type: z
63
63
  .boolean()
64
64
  .optional()
65
- .describe('Optional. true locks each slot to the declared content_type so a PUT with any other Content-Type fails with 403. Send the returned Content-Type header exactly.'),
65
+ .describe('Optional. true locks each slot to the declared content_type; a PUT with any other Content-Type fails with 403.'),
66
66
  workspace_id: z.string().optional().describe('Optional. The workspace this acts in and whose plan pays (from whoami). Needed only when your connection can act in several workspaces.'),
67
67
  }),
68
68
  async execute(client, input) {
@@ -3,7 +3,7 @@ import { code, dashboardUrlForPosts } from '../lib/format.js';
3
3
  import { previewThenConfirm, validateArgs } from '../lib/tool-runtime.js';
4
4
  export const deletePostTool = {
5
5
  name: 'delete_post',
6
- description: 'Delete posts. DESTRUCTIVE and IRREVERSIBLE: deleted posts and captions cannot be recovered. post_id: delete one 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"). A post that is currently publishing is never deleted. A published post is taken down only when the user also explicitly confirms the live removal and you pass confirm_published=true. Choose delete_mode=posterly to remove only the posterly record and leave the live post up, or delete_mode=platform with confirm_published=true to take down the live post too. Live deletion supports eligible connected platforms with saved post IDs and deletion permissions; refusals keep the record. Threads requires threads_delete. YouTube requires youtube.force-ssl or equivalent, upload alone is insufficient. A published post with no live URL and no platform id is removed from posterly only. 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. A group delete never removes published posts. 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.',
6
+ description: 'Delete posts. DESTRUCTIVE and IRREVERSIBLE: deleted posts and captions cannot be recovered. post_id: delete one 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"). A post that is currently publishing is never deleted. A published post is taken down only when the user also explicitly confirms the live removal: delete_mode=platform with confirm_published=true takes the live post down too; delete_mode=posterly removes only the posterly record and leaves it up. Live deletion supports eligible connected platforms with saved post IDs and deletion permissions; refusals keep the record. Threads requires threads_delete. YouTube requires youtube.force-ssl or equivalent, upload alone is insufficient. A published post with no live URL and no platform id is removed from posterly only. 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. A group delete never removes published posts. 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.',
7
7
  inputSchema: z.object({
8
8
  post_id: z.number().optional().describe('Delete this one post.'),
9
9
  group_id: z.string().min(1).max(160).optional().describe('Delete every unpublished post in this group or release instead. Never deletes published posts.'),
@@ -11,7 +11,7 @@ export const deletePostTool = {
11
11
  confirm_published: z
12
12
  .boolean()
13
13
  .optional()
14
- .describe('With post_id only. True only after the user explicitly confirms taking a live post down. Required with delete_mode=platform. Use delete_mode=posterly to leave the live post up.'),
14
+ .describe('With post_id only. True only after the user explicitly confirms taking a live post down. Required with delete_mode=platform.'),
15
15
  confirm: z
16
16
  .boolean()
17
17
  .optional()
@@ -3,15 +3,15 @@ import { mdKeyValue, mdSection, mdTitle } from '../lib/format.js';
3
3
  const TIER_VALUES = ['starter', 'pro', 'power_user', 'agency'];
4
4
  function formatDowngraded(result) {
5
5
  return [
6
- mdTitle('Subscription downgrade scheduled'),
6
+ mdTitle('Subscription downgraded'),
7
7
  mdSection('Details', mdKeyValue([
8
- ['New tier at next renewal', result.tier],
8
+ ['New tier (limits apply now, lower price from the next renewal)', result.tier],
9
9
  ])),
10
10
  ].join('\n\n');
11
11
  }
12
12
  export const downgradeSubscriptionTool = {
13
13
  name: 'downgrade_subscription',
14
- description: "Downgrade the authenticated user's posterly subscription one tier (or to an explicit lower `tier`) at the next renewal with no proration. Billing action; requires the billing:write scope. Only call after the user explicitly confirms.",
14
+ description: "Move the subscription down one tier (or to an explicit lower `tier`) now: the lower limits and credits apply right away, the lower price starts at the next renewal, and the rest of the current period is not refunded. Strictly downward only. Requires billing:write. Only call after the user explicitly confirms.",
15
15
  inputSchema: z.object({
16
16
  tier: z.enum(TIER_VALUES).optional().describe('Optional explicit target tier. Omit to drop one tier automatically.'),
17
17
  confirm: z.literal(true).describe('Must be true after the user explicitly confirms the downgrade.'),
@@ -1,7 +1,55 @@
1
1
  import { z } from 'zod';
2
- import { formatDateTime, mdKeyValue, mdSection, mdTitle } from '../lib/format.js';
3
- function formatSubscription(result) {
2
+ import { formatDateTime, mdBullets, mdKeyValue, mdSection, mdTitle } from '../lib/format.js';
3
+ import { formatExtraAccountsPaymentPending, intervalWord, usdFromCents } from './manage-extra-account.js';
4
+ function formatConnectedAccounts(accounts) {
5
+ if (!accounts || typeof accounts.limit !== 'number' || !Number.isFinite(accounts.limit))
6
+ return null;
7
+ const used = typeof accounts.used === 'number' && Number.isFinite(accounts.used)
8
+ ? Math.max(0, Math.floor(accounts.used))
9
+ : 0;
10
+ if (accounts.limit < 0)
11
+ return `${used} of unlimited`;
12
+ return `${used} of ${accounts.limit}`;
13
+ }
14
+ /** The Agency extra-accounts block (owner only). Same wording as the hosted endpoint. */
15
+ function formatExtraAccountsSection(state, directoryProfile = false) {
16
+ const word = intervalWord(state.interval);
17
+ const price = state.price_per_account_cents === null || state.price_per_account_cents === undefined
18
+ ? 'n/a'
19
+ : `${usdFromCents(state.price_per_account_cents)} per extra account per ${word}`;
20
+ const rows = [
21
+ ['Included with Agency', state.included_accounts],
22
+ ['Granted by posterly', state.admin_granted_accounts],
23
+ ['Paid extra accounts', state.paid_extra_accounts],
24
+ ['Account limit', state.account_limit],
25
+ ['Connected accounts in use', state.accounts_in_use],
26
+ ];
27
+ if (!directoryProfile)
28
+ rows.push(['Price', price]);
29
+ rows.push(['Current extra accounts cost', state.recurring_cents === null || state.recurring_cents === undefined ? 'n/a' : `${usdFromCents(state.recurring_cents)} per ${word}`]);
30
+ if (!directoryProfile) {
31
+ rows.push(['Minimum purchase', `${state.min_purchase} accounts at a time, no maximum`]);
32
+ rows.push(['Lowest total you can set now', state.min_paid_extra_accounts]);
33
+ }
34
+ rows.push(['On a trial', state.trialing ? 'yes, no charge until the trial ends' : 'no']);
35
+ if (!directoryProfile) {
36
+ rows.push(['Can change now', state.eligible
37
+ ? 'yes, with manage_extra_account'
38
+ : `no (${state.code || 'not eligible'}). ${state.reason || 'Extra accounts are not available for this subscription right now.'}`]);
39
+ }
40
+ return mdSection('Extra accounts', mdKeyValue(rows));
41
+ }
42
+ /**
43
+ * `directoryProfile` is the Claude directory profile: its catalog has no
44
+ * billing mutations, so the output is facts only (no tool names, no offers,
45
+ * no money steps) plus one line pointing at the billing page.
46
+ */
47
+ function formatSubscription(result, options_) {
4
48
  const sub = result.subscription;
49
+ const connectedAccounts = formatConnectedAccounts(sub.accounts);
50
+ const directoryProfile = options_?.directoryProfile === true;
51
+ const options = directoryProfile ? [] : Array.isArray(sub.upgrade_options) ? sub.upgrade_options : [];
52
+ const steps = directoryProfile ? [] : Array.isArray(sub.next_steps) ? sub.next_steps : [];
5
53
  return [
6
54
  mdTitle('posterly subscription'),
7
55
  mdSection('Details', mdKeyValue([
@@ -12,15 +60,31 @@ function formatSubscription(result) {
12
60
  ['Trial ends', sub.trial_ends_at ? formatDateTime(sub.trial_ends_at) : 'n/a'],
13
61
  ['Paused at', sub.paused_at ? formatDateTime(sub.paused_at) : 'n/a'],
14
62
  ['Pause resumes at', sub.pause_resumes_at ? formatDateTime(sub.pause_resumes_at) : 'n/a'],
63
+ ...(connectedAccounts ? [['Connected accounts', connectedAccounts]] : []),
15
64
  ])),
16
- ].join('\n\n');
65
+ sub.extra_accounts ? formatExtraAccountsSection(sub.extra_accounts, directoryProfile) : '',
66
+ sub.extra_accounts?.payment_pending ? formatExtraAccountsPaymentPending(sub.extra_accounts.payment_pending) : '',
67
+ directoryProfile
68
+ ? `Plan and billing changes are made on the billing page: ${typeof sub.billing_url === 'string' && sub.billing_url ? sub.billing_url : 'https://www.poster.ly/dashboard/account/billing'}`
69
+ : '',
70
+ options.length
71
+ ? mdSection('Plans you can move to', mdBullets(options.map((o) => `${o.name}: $${o.monthly_price}/month or $${o.yearly_price}/year, ${o.max_accounts} connected accounts, ${o.included_credits} AI credits a month`)))
72
+ : '',
73
+ steps.length
74
+ ? mdSection('Next steps', steps.map((step, index) => [
75
+ `${index + 1}. ${step.text}`,
76
+ step.tool ? ` Tool: ${step.tool}${step.params ? ` ${JSON.stringify(step.params)}` : ''}` : '',
77
+ ].filter(Boolean).join('\n')).join('\n'))
78
+ : '',
79
+ ].filter(Boolean).join('\n\n');
17
80
  }
18
81
  export const getSubscriptionTool = {
19
82
  name: 'get_subscription',
20
- description: "Get the authenticated user's posterly subscription: status, tier, cancel-at-period-end, current period end, trial end, and pause state. Read-only. Requires the billing:read scope.",
83
+ description: "Get the authenticated user's posterly subscription: status, tier, cancel-at-period-end, period end, trial end and pause state. Also reports connected accounts in use and the account limit for the workspace this caller is acting in (plan tier plus any extra slots). Call this FIRST for \"upgrade\", \"change plan\", \"add accounts\" or \"how many accounts\": it returns the plans above this user's with prices, limits and credits, the Agency extra-accounts state (owners), and the exact next steps. Read-only. Requires the billing:read scope.",
21
84
  inputSchema: z.object({}),
22
85
  async execute(client) {
23
86
  const result = await client.getSubscription();
24
- return formatSubscription(result);
87
+ // Same switch index.ts uses to drop the billing mutations from the catalog.
88
+ return formatSubscription(result, { directoryProfile: process.env.POSTERLY_DIRECTORY_PROFILE === 'claude' });
25
89
  },
26
90
  };
@@ -31,7 +31,7 @@ export const listAnalyticsTool = {
31
31
  .enum(['1h', '6h', '24h', '72h', '7d'])
32
32
  .optional()
33
33
  .describe('insights: filter to one checkpoint after publish.'),
34
- presentation: presentationSchema.describe('accounts and posts: compact bullets, Markdown table, or raw JSON for client-side chart/card rendering.'),
34
+ presentation: presentationSchema.describe('accounts and posts: compact, table, or json.'),
35
35
  }),
36
36
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
37
37
  legacySchemas: {
@@ -6,7 +6,7 @@ export const LIST_POSTS_DESCRIPTION = 'Posts in your workspaces, teammates\' too
6
6
  'view=list (default): posts filtered by status (scheduled, published, failed, draft), platform, account_id, workspace_id, brand_id, approval_status, approval_waiting_on, and a scheduled date range: scheduled_from (inclusive) and scheduled_to (a plain date includes that whole day), read in timezone (IANA, default UTC; also the zone times are shown in). Returns limit posts (default 20, max 200) starting at offset; with a date range the order defaults to oldest first (order=asc|desc). ' +
7
7
  'The output always says whether every matching post was shown. If it says more are available, call again with the offset it gives and keep paging until all are shown before drawing any conclusion about totals, gaps, or how busy a client is. ' +
8
8
  'view=counts (scheduled_from and scheduled_to required, up to 366 days): exact totals per day, status, account, and brand for the same filters (limit, offset, and order are ignored); use it for "how many" or "is this month full" questions. ' +
9
- 'approval_waiting_on=client is the same queue as approval_status=pending_client. Each post includes approval.pending_client_approval.';
9
+ 'Each post includes approval.pending_client_approval.';
10
10
  export const listPostsTool = {
11
11
  name: 'list_posts',
12
12
  description: LIST_POSTS_DESCRIPTION,
@@ -14,7 +14,7 @@ export const listPostsTool = {
14
14
  view: z
15
15
  .enum(['list', 'counts'])
16
16
  .optional()
17
- .describe('list (default): the posts themselves, one page at a time. counts: exact totals per day, status, account, and brand (needs scheduled_from and scheduled_to).'),
17
+ .describe('list (default): the posts. counts: totals (needs scheduled_from and scheduled_to).'),
18
18
  status: z
19
19
  .string()
20
20
  .optional()
@@ -54,7 +54,7 @@ export const listPostsTool = {
54
54
  .int()
55
55
  .min(0)
56
56
  .optional()
57
- .describe('How many matching posts to skip. Use the offset the previous page gives to get the next page. Ignored by view=counts.'),
57
+ .describe('Matching posts to skip; use the offset the previous page gives. Ignored by view=counts.'),
58
58
  workspace_id: z
59
59
  .string()
60
60
  .optional()
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ import type { ExtraAccountsPaymentPending, ExtraAccountsQuote, PosterlyClient } from '../lib/api-client.js';
3
+ import { type ToolContext } from '../lib/tool-runtime.js';
4
+ export declare function usdFromCents(cents: number | null | undefined): string;
5
+ export declare function intervalWord(interval: unknown): string;
6
+ /** Same wording as the hosted endpoint (lib/mcp/http-tools.ts). */
7
+ export declare function formatExtraAccountsPaymentPending(pending: ExtraAccountsPaymentPending | null | undefined): string;
8
+ export declare function formatExtraAccountsQuote(q: ExtraAccountsQuote): string;
9
+ type ManageExtraAccountInput = {
10
+ action: 'set';
11
+ extra_accounts: number;
12
+ workspace_id?: string;
13
+ expected_current_extra_accounts?: number;
14
+ expected_interval?: 'month' | 'year';
15
+ confirm?: boolean;
16
+ preview_id?: string;
17
+ };
18
+ export declare const manageExtraAccountTool: {
19
+ name: string;
20
+ description: string;
21
+ inputSchema: z.ZodObject<{
22
+ action: z.ZodEnum<["set"]>;
23
+ extra_accounts: z.ZodNumber;
24
+ workspace_id: z.ZodOptional<z.ZodString>;
25
+ expected_current_extra_accounts: z.ZodOptional<z.ZodNumber>;
26
+ expected_interval: z.ZodOptional<z.ZodEnum<["month", "year"]>>;
27
+ confirm: z.ZodOptional<z.ZodBoolean>;
28
+ preview_id: z.ZodOptional<z.ZodString>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ action: "set";
31
+ extra_accounts: number;
32
+ workspace_id?: string | undefined;
33
+ confirm?: boolean | undefined;
34
+ preview_id?: string | undefined;
35
+ expected_current_extra_accounts?: number | undefined;
36
+ expected_interval?: "month" | "year" | undefined;
37
+ }, {
38
+ action: "set";
39
+ extra_accounts: number;
40
+ workspace_id?: string | undefined;
41
+ confirm?: boolean | undefined;
42
+ preview_id?: string | undefined;
43
+ expected_current_extra_accounts?: number | undefined;
44
+ expected_interval?: "month" | "year" | undefined;
45
+ }>;
46
+ execute(client: PosterlyClient, input: ManageExtraAccountInput, ctx: ToolContext): Promise<string>;
47
+ };
48
+ export {};
@@ -0,0 +1,161 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ import { formatDateTime, mdKeyValue, mdSection, mdTitle } from '../lib/format.js';
4
+ import { previewThenConfirm, readForPreview, validateArgs } from '../lib/tool-runtime.js';
5
+ export function usdFromCents(cents) {
6
+ const n = typeof cents === 'number' && Number.isFinite(cents) ? Math.round(cents) : 0;
7
+ return `$${(n / 100).toFixed(2)}`;
8
+ }
9
+ export function intervalWord(interval) {
10
+ return interval === 'year' ? 'year' : 'month';
11
+ }
12
+ /** Same wording as the hosted endpoint (lib/mcp/http-tools.ts). */
13
+ export function formatExtraAccountsPaymentPending(pending) {
14
+ if (!pending)
15
+ return '';
16
+ return mdSection('Payment waiting', [
17
+ mdKeyValue([
18
+ ['Requested extra accounts', pending.requested_extra_accounts],
19
+ ['Amount due', pending.amount_due_cents === null || pending.amount_due_cents === undefined ? 'n/a' : usdFromCents(pending.amount_due_cents)],
20
+ ['Expires', pending.expires_at ? formatDateTime(pending.expires_at) : 'n/a'],
21
+ ['Payment link', pending.hosted_invoice_url || 'not available, finish it in Billing'],
22
+ ]),
23
+ 'Nothing has been added yet. The accounts apply automatically once this invoice is paid. Until then posterly will not accept another change.',
24
+ ].join('\n\n'));
25
+ }
26
+ export function formatExtraAccountsQuote(q) {
27
+ const word = intervalWord(q.interval);
28
+ const verb = q.kind === 'none' ? 'No change' : q.kind === 'increase' ? 'Add accounts' : q.kind === 'remove' ? 'Remove all extra accounts' : 'Lower extra accounts';
29
+ const chargeLine = q.kind === 'increase'
30
+ ? (q.trialing
31
+ ? 'Nothing is charged today because the subscription is on a trial. Billing starts when the trial ends.'
32
+ : `The saved card on file is charged ${q.charge_today || usdFromCents(q.charge_today_cents)} today (prorated for the rest of this billing period) when this is confirmed. If the card needs confirmation or declines, nothing is added and a payment link is returned instead.`)
33
+ : q.kind === 'none'
34
+ ? 'Nothing changes and nothing is charged.'
35
+ : 'Nothing is charged and nothing is refunded for the rest of this billing period. The lower limit applies right away.';
36
+ return [
37
+ mdSection(verb, mdKeyValue([
38
+ ['Extra accounts now', q.current_extra_accounts],
39
+ ['Extra accounts after', q.new_extra_accounts],
40
+ ['Account limit after', q.account_limit_after],
41
+ ['Connected accounts in use', q.accounts_in_use],
42
+ ['Charge today', q.kind === 'increase' ? (q.trialing ? '$0.00 (trial)' : q.charge_today || usdFromCents(q.charge_today_cents)) : '$0.00'],
43
+ ['New recurring cost', `${q.new_recurring || usdFromCents(q.new_recurring_cents)} per ${word} for ${q.new_extra_accounts} extra accounts (${usdFromCents(q.price_per_account_cents)} each)`],
44
+ ])),
45
+ chargeLine,
46
+ ].join('\n\n');
47
+ }
48
+ export const manageExtraAccountTool = {
49
+ name: 'manage_extra_account',
50
+ description: 'Buy, raise, lower, or remove Agency extra-account slots. MONEY: raising charges the saved card. Owner only; billing:write. action=set (extra_accounts = desired TOTAL, 0 removes all; add 20+ at a time). Call without confirm for the quote and preview_id; after the user agrees, call with confirm=true, that preview_id and the expected_ fields from the quote. 3D Secure or a decline returns a payment link; nothing is added.',
51
+ inputSchema: z.object({
52
+ action: z.enum(['set']),
53
+ extra_accounts: z.number().int().min(0),
54
+ workspace_id: z.string().optional(),
55
+ expected_current_extra_accounts: z.number().int().min(0).optional(),
56
+ expected_interval: z.enum(['month', 'year']).optional(),
57
+ confirm: z.boolean().optional(),
58
+ preview_id: z.string().optional(),
59
+ }),
60
+ async execute(client, input, ctx) {
61
+ const { args } = validateArgs(ctx, 'manage_extra_account', input);
62
+ const call = args;
63
+ const workspace = call.workspace_id ? { workspace_id: call.workspace_id } : {};
64
+ // A preview is only issued for a change posterly can actually make: price
65
+ // it first, and answer a failed quote with an error and NO preview_id. The
66
+ // quote's current total and interval are pinned into the previewed args,
67
+ // so the confirm must repeat them and the API refuses a stale quote.
68
+ let quote = null;
69
+ let previewArgs = args;
70
+ if (call.confirm !== true) {
71
+ const read = await readForPreview(() => client.quoteExtraAccounts({ extra_accounts: call.extra_accounts, ...workspace }));
72
+ if (!read.ok) {
73
+ throw new Error([
74
+ 'No preview: this change cannot be made right now.',
75
+ read.error,
76
+ 'Nothing was changed and no preview_id was issued. Tell the user why, and fix the cause first (for example disconnect accounts, finish the pending payment, or pick at least 20 more than the current total).',
77
+ ].join('\n\n'));
78
+ }
79
+ quote = read.data.quote;
80
+ previewArgs = {
81
+ ...args,
82
+ expected_current_extra_accounts: quote.current_extra_accounts,
83
+ expected_interval: quote.interval,
84
+ };
85
+ }
86
+ return previewThenConfirm({
87
+ tool: 'manage_extra_account',
88
+ action: 'set',
89
+ args: previewArgs,
90
+ nonce: true,
91
+ legacyRefusal: 'Refusing to change extra accounts without confirm=true after explicit user confirmation.',
92
+ ctx,
93
+ describe: async () => [
94
+ formatExtraAccountsQuote(quote),
95
+ quote.kind === 'none' ? '' : 'Only confirm after the user has seen the price and agreed. The change is billed to the saved card, not to anything the user types here.',
96
+ mdSection('Fields to repeat on confirm', mdKeyValue([
97
+ ['extra_accounts', quote.new_extra_accounts],
98
+ ['expected_current_extra_accounts', quote.current_extra_accounts],
99
+ ['expected_interval', quote.interval],
100
+ ])),
101
+ ].filter(Boolean).join('\n\n'),
102
+ run: async () => {
103
+ if (typeof call.expected_current_extra_accounts !== 'number' || !call.expected_interval) {
104
+ throw new Error('Confirm needs expected_current_extra_accounts and expected_interval from the preview. Get a new preview.');
105
+ }
106
+ // The same preview_id always maps to the same request_id, so a replayed
107
+ // confirm can never buy twice.
108
+ const requestId = typeof call.preview_id === 'string' && call.preview_id
109
+ ? `mcp-${createHash('sha256').update(call.preview_id).digest('hex').slice(0, 40)}`
110
+ : undefined;
111
+ const result = await client.setExtraAccounts({
112
+ extra_accounts: call.extra_accounts,
113
+ expected_current_extra_accounts: call.expected_current_extra_accounts,
114
+ expected_interval: call.expected_interval,
115
+ ...(requestId ? { request_id: requestId } : {}),
116
+ ...workspace,
117
+ });
118
+ return formatExtraAccountsResult(result);
119
+ },
120
+ });
121
+ },
122
+ };
123
+ function formatExtraAccountsResult(d) {
124
+ if (d.status === 'payment_required') {
125
+ return [
126
+ mdTitle('Payment needed: nothing was added yet'),
127
+ 'The saved card needs confirmation (3D Secure) or was declined, so posterly did not add the accounts. Send the user to the payment link. The accounts apply automatically once it is paid.',
128
+ mdKeyValue([
129
+ ['Requested extra accounts', d.requested_extra_accounts],
130
+ ['Account limit once paid', d.account_limit_after_payment],
131
+ ['Amount due', d.payment_pending?.amount_due_cents === null || d.payment_pending?.amount_due_cents === undefined ? 'n/a' : usdFromCents(d.payment_pending.amount_due_cents)],
132
+ ['Link expires', d.payment_pending?.expires_at ? formatDateTime(d.payment_pending.expires_at) : 'n/a'],
133
+ ['Payment link', d.hosted_invoice_url || 'not available, ask the user to finish it in Billing'],
134
+ ]),
135
+ 'Call get_subscription afterwards to confirm the new limit.',
136
+ ].join('\n\n');
137
+ }
138
+ if (d.status === 'unchanged') {
139
+ return [
140
+ mdTitle('No change needed'),
141
+ `The workspace already has ${d.extra_accounts} extra accounts. The account limit is ${d.account_limit}.`,
142
+ ].join('\n\n');
143
+ }
144
+ const word = intervalWord(d.interval);
145
+ const headline = d.extra_accounts === 0
146
+ ? 'Removed all extra accounts'
147
+ : d.kind === 'increase'
148
+ ? `Added ${d.extra_accounts - d.previous_extra_accounts} extra accounts`
149
+ : `Lowered extra accounts to ${d.extra_accounts}`;
150
+ return [
151
+ mdTitle(headline),
152
+ `The account limit is now ${d.account_limit}.`,
153
+ mdKeyValue([
154
+ ['Extra accounts', `${d.previous_extra_accounts} to ${d.extra_accounts}`],
155
+ ['Included with Agency', d.included_accounts],
156
+ ['Connected accounts in use', d.accounts_in_use],
157
+ ['Recurring cost', `${usdFromCents(d.recurring_cents)} per ${word} (${usdFromCents(d.price_per_account_cents)} per extra account)`],
158
+ ]),
159
+ d.kind === 'increase' ? 'The prorated amount was charged to the saved card.' : '',
160
+ ].filter(Boolean).join('\n\n');
161
+ }
@@ -11,7 +11,7 @@ export const managePublishingPauseTool = {
11
11
  workspace_id: z.string().optional().describe('Workspace ID from whoami. Defaults to your default workspace.'),
12
12
  brand_id: z.string().optional().describe('pause and resume: a brand ID from list_brands. Leave it out (never empty) for the whole workspace.'),
13
13
  post_ids: z.array(z.number().int().positive()).max(500).optional().describe('publish_missed: the missed post IDs a resume returned.'),
14
- confirm: z.boolean().optional().describe('pause: leave out to get a preview; true only after the user agreed. publish_missed: true after the user agreed. resume: not needed.'),
14
+ confirm: z.boolean().optional().describe('pause: leave out to preview. pause and publish_missed: true only after the user agreed. resume: not needed.'),
15
15
  }),
16
16
  async execute(client, input, ctx) {
17
17
  // A present but empty brand_id is refused, never read as the whole
@@ -33,7 +33,7 @@ export declare const manageWorkspaceMemberTool: {
33
33
  preview_id: z.ZodOptional<z.ZodString>;
34
34
  }, "strip", z.ZodTypeAny, {
35
35
  workspace_id: string;
36
- action: "invite" | "update" | "remove";
36
+ action: "remove" | "invite" | "update";
37
37
  confirm?: boolean | undefined;
38
38
  preview_id?: string | undefined;
39
39
  email?: string | undefined;
@@ -45,7 +45,7 @@ export declare const manageWorkspaceMemberTool: {
45
45
  api_access?: boolean | undefined;
46
46
  }, {
47
47
  workspace_id: string;
48
- action: "invite" | "update" | "remove";
48
+ action: "remove" | "invite" | "update";
49
49
  confirm?: boolean | undefined;
50
50
  preview_id?: string | undefined;
51
51
  email?: string | undefined;
@@ -94,18 +94,18 @@ export function validateManageWorkspaceMemberInput(input) {
94
94
  }
95
95
  export const manageWorkspaceMemberTool = {
96
96
  name: 'manage_workspace_member',
97
- description: 'Invite, update, or remove a workspace colleague. This SENDS EMAILS and CHANGES WHO CAN ACCESS the workspace. Needs an API key with the Manage team permission, and the caller must be a workspace owner or admin. ALWAYS preview first: call without confirm, show the returned preview summary to the user, and only call again with confirm: true plus the returned preview_id after the user explicitly approves. action=invite: email and role required (publisher, editor or viewer), optional brand_ids and resend; always sends a pending invite email, never adds anyone instantly. action=update: member_id or invite_id (from list_workspace_members) plus role and/or brand_ids; or member_id plus api_access (true or false, on its own) to turn API and AI app access on or off for that teammate, which lets them use the workspace API plan from their own keys and AI apps (off by default; you cannot change your own; only the owner can change it for an admin; turning it off stops their keys, AI app connections and webhooks for this workspace). action=remove: member_id (removes the teammate and revokes their API keys for this workspace) or invite_id (cancels a pending invite). Admin seats can only be granted in the posterly dashboard. The workspace owner is emailed about every change.',
97
+ description: 'Invite, update, or remove a workspace colleague. This SENDS EMAILS and CHANGES WHO CAN ACCESS the workspace. Needs an API key with the Manage team permission, and the caller must be a workspace owner or admin. ALWAYS preview first: call without confirm, show the preview to the user, and only call again with confirm: true plus the returned preview_id after the user explicitly approves. action=invite: email and role required (publisher, editor or viewer), optional brand_ids and resend; always sends a pending invite email, never adds anyone instantly. action=update: member_id or invite_id (from list_workspace_members) plus role and/or brand_ids; or member_id plus api_access (true or false, on its own) to turn API and AI app access on or off for that teammate, which lets them use the workspace API plan from their own keys and AI apps (off by default; you cannot change your own; only the owner can change it for an admin; turning it off stops their keys, AI app connections and webhooks for this workspace). action=remove: member_id (removes the teammate and revokes their API keys for this workspace) or invite_id (cancels a pending invite). Admin seats can only be granted in the posterly dashboard. The workspace owner is emailed about every change.',
98
98
  inputSchema: z.object({
99
99
  action: z.enum(ACTIONS).describe('invite, update, or remove.'),
100
100
  workspace_id: z.string().describe('Workspace ID (from whoami).'),
101
101
  email: z.string().optional().describe('action=invite only: the colleague email address.'),
102
- role: z.enum(ROLES).optional().describe('action=invite (required) or action=update: publisher, editor, or viewer. Admin is dashboard-only.'),
102
+ role: z.enum(ROLES).optional().describe('action=invite (required) or action=update: publisher, editor, or viewer.'),
103
103
  brand_ids: z.array(z.string()).max(100).optional().describe('action=invite or action=update: limit the seat to these brand IDs (from list_brands). Empty array means every brand. Omit on update to keep the current brands.'),
104
104
  resend: z.boolean().optional().describe('action=invite only: email an unchanged pending invite again.'),
105
105
  member_id: z.string().optional().describe('action=update or action=remove: a member ID from list_workspace_members.'),
106
106
  invite_id: z.string().optional().describe('action=update or action=remove: a pending invite ID from list_workspace_members.'),
107
- api_access: z.boolean().optional().describe('action=update with member_id only, on its own: true lets the teammate use this workspace\'s API plan from their own keys and AI apps; false turns it off.'),
108
- confirm: z.boolean().optional().describe('Leave out to get a preview. Set true only after the user explicitly approved the preview, together with preview_id.'),
107
+ api_access: z.boolean().optional().describe('action=update with member_id only, on its own: true turns API and AI app access on; false turns it off.'),
108
+ confirm: z.boolean().optional().describe('Leave out to get a preview. Set true only after the user explicitly approved it, with the preview_id.'),
109
109
  preview_id: z.string().optional().describe('The preview_id returned by the preview call. Required with confirm: true.'),
110
110
  }),
111
111
  async execute(client, input) {
@@ -80,9 +80,9 @@ declare const instagramSettingsSchema: z.ZodObject<{
80
80
  option_d?: string | undefined;
81
81
  }>>;
82
82
  }, "strip", z.ZodTypeAny, {
83
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
83
84
  type?: "none" | "poll" | "comment_prompt" | undefined;
84
85
  options?: string[] | undefined;
85
- kind?: "none" | "poll" | "comment_prompt" | undefined;
86
86
  extended_duration?: boolean | undefined;
87
87
  poll_attachment?: {
88
88
  options?: string[] | undefined;
@@ -92,9 +92,9 @@ declare const instagramSettingsSchema: z.ZodObject<{
92
92
  option_d?: string | undefined;
93
93
  } | undefined;
94
94
  }, {
95
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
95
96
  type?: "none" | "poll" | "comment_prompt" | undefined;
96
97
  options?: string[] | undefined;
97
- kind?: "none" | "poll" | "comment_prompt" | undefined;
98
98
  extended_duration?: boolean | undefined;
99
99
  poll_attachment?: {
100
100
  options?: string[] | undefined;
@@ -161,9 +161,9 @@ declare const instagramSettingsSchema: z.ZodObject<{
161
161
  option_d?: string | undefined;
162
162
  } | undefined;
163
163
  caption_addon?: {
164
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
164
165
  type?: "none" | "poll" | "comment_prompt" | undefined;
165
166
  options?: string[] | undefined;
166
- kind?: "none" | "poll" | "comment_prompt" | undefined;
167
167
  extended_duration?: boolean | undefined;
168
168
  poll_attachment?: {
169
169
  options?: string[] | undefined;
@@ -211,9 +211,9 @@ declare const instagramSettingsSchema: z.ZodObject<{
211
211
  option_d?: string | undefined;
212
212
  } | undefined;
213
213
  caption_addon?: {
214
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
214
215
  type?: "none" | "poll" | "comment_prompt" | undefined;
215
216
  options?: string[] | undefined;
216
- kind?: "none" | "poll" | "comment_prompt" | undefined;
217
217
  extended_duration?: boolean | undefined;
218
218
  poll_attachment?: {
219
219
  options?: string[] | undefined;
@@ -785,9 +785,9 @@ export declare const updatePostTool: {
785
785
  option_d?: string | undefined;
786
786
  }>>;
787
787
  }, "strip", z.ZodTypeAny, {
788
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
788
789
  type?: "none" | "poll" | "comment_prompt" | undefined;
789
790
  options?: string[] | undefined;
790
- kind?: "none" | "poll" | "comment_prompt" | undefined;
791
791
  extended_duration?: boolean | undefined;
792
792
  poll_attachment?: {
793
793
  options?: string[] | undefined;
@@ -797,9 +797,9 @@ export declare const updatePostTool: {
797
797
  option_d?: string | undefined;
798
798
  } | undefined;
799
799
  }, {
800
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
800
801
  type?: "none" | "poll" | "comment_prompt" | undefined;
801
802
  options?: string[] | undefined;
802
- kind?: "none" | "poll" | "comment_prompt" | undefined;
803
803
  extended_duration?: boolean | undefined;
804
804
  poll_attachment?: {
805
805
  options?: string[] | undefined;
@@ -866,9 +866,9 @@ export declare const updatePostTool: {
866
866
  option_d?: string | undefined;
867
867
  } | undefined;
868
868
  caption_addon?: {
869
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
869
870
  type?: "none" | "poll" | "comment_prompt" | undefined;
870
871
  options?: string[] | undefined;
871
- kind?: "none" | "poll" | "comment_prompt" | undefined;
872
872
  extended_duration?: boolean | undefined;
873
873
  poll_attachment?: {
874
874
  options?: string[] | undefined;
@@ -916,9 +916,9 @@ export declare const updatePostTool: {
916
916
  option_d?: string | undefined;
917
917
  } | undefined;
918
918
  caption_addon?: {
919
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
919
920
  type?: "none" | "poll" | "comment_prompt" | undefined;
920
921
  options?: string[] | undefined;
921
- kind?: "none" | "poll" | "comment_prompt" | undefined;
922
922
  extended_duration?: boolean | undefined;
923
923
  poll_attachment?: {
924
924
  options?: string[] | undefined;
@@ -1434,9 +1434,9 @@ export declare const updatePostTool: {
1434
1434
  option_d?: string | undefined;
1435
1435
  } | undefined;
1436
1436
  caption_addon?: {
1437
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
1437
1438
  type?: "none" | "poll" | "comment_prompt" | undefined;
1438
1439
  options?: string[] | undefined;
1439
- kind?: "none" | "poll" | "comment_prompt" | undefined;
1440
1440
  extended_duration?: boolean | undefined;
1441
1441
  poll_attachment?: {
1442
1442
  options?: string[] | undefined;
@@ -1652,9 +1652,9 @@ export declare const updatePostTool: {
1652
1652
  option_d?: string | undefined;
1653
1653
  } | undefined;
1654
1654
  caption_addon?: {
1655
+ kind?: "none" | "poll" | "comment_prompt" | undefined;
1655
1656
  type?: "none" | "poll" | "comment_prompt" | undefined;
1656
1657
  options?: string[] | undefined;
1657
- kind?: "none" | "poll" | "comment_prompt" | undefined;
1658
1658
  extended_duration?: boolean | undefined;
1659
1659
  poll_attachment?: {
1660
1660
  options?: string[] | undefined;
@@ -154,8 +154,8 @@ export const updatePostTool = {
154
154
  .string()
155
155
  .optional()
156
156
  .describe('New scheduled time (ISO 8601, e.g. 2026-03-10T09:00:00Z)'),
157
- media_url: z.string().optional().describe('New media URL. Posterly storage URLs are used as-is; third-party HTTP(S) URLs are copied into posterly storage before the post is saved. Short-lived signed URLs must still be live when this tool runs.'),
158
- media_urls: z.array(z.string()).optional().describe('New media URLs for carousel. Posterly storage URLs are used as-is; third-party HTTP(S) URLs are copied into posterly storage before the post is saved.'),
157
+ media_url: z.string().optional().describe('New media URL. Posterly storage URLs are used as-is; third-party URLs are copied into posterly storage first. Short-lived signed URLs must still be live when this tool runs.'),
158
+ media_urls: z.array(z.string()).optional().describe('New media URLs for carousel, handled like media_url.'),
159
159
  post_type: z
160
160
  .string()
161
161
  .optional()
@@ -186,7 +186,7 @@ export const updatePostTool = {
186
186
  approval_action: z
187
187
  .enum(['request', 'approve', 'request_changes', 'reject'])
188
188
  .optional()
189
- .describe('Change client approval instead of editing the post. Owner or admin only. The actor is the API key user, never a brand guest. Send on its own.'),
189
+ .describe('Change client approval instead of editing the post. Send on its own.'),
190
190
  approval_axis: z
191
191
  .enum(['asset', 'caption'])
192
192
  .optional()