posterly-mcp-server 0.54.4 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +48 -5
  2. package/dist/generated/platform-manifest.d.ts +4 -4
  3. package/dist/generated/platform-manifest.js +9 -4
  4. package/dist/index.js +15 -2
  5. package/dist/lib/alias-transport.js +4 -0
  6. package/dist/lib/api-client.d.ts +152 -0
  7. package/dist/lib/api-client.js +88 -0
  8. package/dist/lib/claude-directory-profile.js +4 -2
  9. package/dist/lib/format.d.ts +44 -0
  10. package/dist/lib/format.js +125 -5
  11. package/dist/lib/gbp-location-preview.d.ts +21 -0
  12. package/dist/lib/gbp-location-preview.js +27 -0
  13. package/dist/lib/google-business-review-name.d.ts +36 -0
  14. package/dist/lib/google-business-review-name.js +83 -0
  15. package/dist/lib/id-schema.d.ts +14 -0
  16. package/dist/lib/id-schema.js +82 -0
  17. package/dist/lib/id-text.d.ts +26 -0
  18. package/dist/lib/id-text.js +63 -0
  19. package/dist/lib/reply-window.d.ts +5 -0
  20. package/dist/lib/reply-window.js +14 -0
  21. package/dist/lib/service-area-text.d.ts +27 -0
  22. package/dist/lib/service-area-text.js +41 -0
  23. package/dist/lib/suggestion-accept-note.d.ts +10 -0
  24. package/dist/lib/suggestion-accept-note.js +17 -0
  25. package/dist/lib/tool-registry.js +19 -2
  26. package/dist/lib/version.d.ts +1 -1
  27. package/dist/lib/version.js +1 -1
  28. package/dist/tools/audit-google-business-profile.js +7 -3
  29. package/dist/tools/connect-account.d.ts +2 -2
  30. package/dist/tools/create-connect-session.d.ts +2 -2
  31. package/dist/tools/create-post.d.ts +6 -6
  32. package/dist/tools/create-posts-batch.d.ts +4 -4
  33. package/dist/tools/create-webhook.d.ts +3 -3
  34. package/dist/tools/delete-post.d.ts +4 -4
  35. package/dist/tools/dismiss-suggestion.d.ts +7 -0
  36. package/dist/tools/dismiss-suggestion.js +21 -2
  37. package/dist/tools/find-slot.js +7 -4
  38. package/dist/tools/get-post.js +56 -5
  39. package/dist/tools/list-accounts.d.ts +4 -0
  40. package/dist/tools/list-accounts.js +25 -6
  41. package/dist/tools/list-analytics.d.ts +4 -0
  42. package/dist/tools/list-analytics.js +29 -7
  43. package/dist/tools/list-comments.d.ts +10 -0
  44. package/dist/tools/list-comments.js +54 -22
  45. package/dist/tools/list-conversations.d.ts +19 -4
  46. package/dist/tools/list-conversations.js +55 -15
  47. package/dist/tools/list-google-business-locations.d.ts +27 -0
  48. package/dist/tools/list-google-business-locations.js +35 -0
  49. package/dist/tools/list-google-business-media.d.ts +8 -0
  50. package/dist/tools/list-google-business-media.js +19 -5
  51. package/dist/tools/list-google-business-reviews.js +12 -2
  52. package/dist/tools/list-google-business-service-areas.d.ts +37 -0
  53. package/dist/tools/list-google-business-service-areas.js +33 -0
  54. package/dist/tools/list-media.js +3 -2
  55. package/dist/tools/list-platforms.d.ts +10 -10
  56. package/dist/tools/list-post-suggestions.js +5 -4
  57. package/dist/tools/list-posts.d.ts +8 -2
  58. package/dist/tools/list-posts.js +12 -2
  59. package/dist/tools/list-webhooks.d.ts +18 -1
  60. package/dist/tools/list-webhooks.js +22 -3
  61. package/dist/tools/list-workspace-members.js +3 -1
  62. package/dist/tools/manage-brands.d.ts +47 -0
  63. package/dist/tools/manage-brands.js +89 -0
  64. package/dist/tools/manage-comment.js +5 -1
  65. package/dist/tools/manage-google-business-location.d.ts +123 -0
  66. package/dist/tools/manage-google-business-location.js +97 -0
  67. package/dist/tools/manage-google-business-media.js +2 -0
  68. package/dist/tools/manage-google-business-review.js +31 -5
  69. package/dist/tools/manage-google-business-service-area.d.ts +74 -0
  70. package/dist/tools/manage-google-business-service-area.js +79 -0
  71. package/dist/tools/manage-webhook.d.ts +6 -6
  72. package/dist/tools/manage-x-posting-addon.d.ts +47 -0
  73. package/dist/tools/manage-x-posting-addon.js +92 -0
  74. package/dist/tools/trigger-platform-helper.d.ts +5 -5
  75. package/dist/tools/update-post.d.ts +14 -6
  76. package/dist/tools/update-post.js +23 -2
  77. package/dist/tools/upload-media.d.ts +12 -0
  78. package/dist/tools/upload-media.js +39 -3
  79. package/dist/tools/validate-post.d.ts +4 -4
  80. package/dist/tools/webhook-events.d.ts +2 -2
  81. package/dist/tools/webhook-events.js +2 -0
  82. package/dist/tools/whoami.d.ts +4 -0
  83. package/dist/tools/whoami.js +14 -6
  84. package/package.json +1 -1
  85. package/server.json +2 -2
  86. package/tool-annotations.json +21 -2
  87. package/tool-registry.json +251 -8
@@ -40,6 +40,10 @@ function postFilterParams(params) {
40
40
  const searchParams = new URLSearchParams();
41
41
  if (params?.status)
42
42
  searchParams.set('status', params.status);
43
+ if (params?.group_id)
44
+ searchParams.set('group_id', params.group_id);
45
+ if (params?.release_id)
46
+ searchParams.set('release_id', params.release_id);
43
47
  if (params?.platform)
44
48
  searchParams.set('platform', params.platform);
45
49
  if (params?.account_id)
@@ -238,6 +242,9 @@ export class PosterlyClient {
238
242
  async whoami() {
239
243
  return this.request('GET', '/whoami');
240
244
  }
245
+ async listApiKeys() {
246
+ return this.request('GET', '/api-keys');
247
+ }
241
248
  async createApiKey(data) {
242
249
  return this.request('POST', '/api-keys', data);
243
250
  }
@@ -324,6 +331,8 @@ export class PosterlyClient {
324
331
  const searchParams = new URLSearchParams();
325
332
  if (params?.workspace_id)
326
333
  searchParams.set('workspace_id', params.workspace_id);
334
+ if (params?.connection)
335
+ searchParams.set('connection', params.connection);
327
336
  const qs = searchParams.toString();
328
337
  const data = await this.request('GET', `/accounts${qs ? `?${qs}` : ''}`);
329
338
  return data.accounts;
@@ -382,6 +391,15 @@ export class PosterlyClient {
382
391
  async getBrand(id) {
383
392
  return this.request('GET', `/brands/${encodeURIComponent(id)}`);
384
393
  }
394
+ async createBrand(data) {
395
+ return this.request('POST', '/brands', data);
396
+ }
397
+ async updateBrand(id, data) {
398
+ return this.request('PATCH', `/brands/${encodeURIComponent(id)}`, data);
399
+ }
400
+ async archiveBrand(id, data) {
401
+ return this.request('POST', `/brands/${encodeURIComponent(id)}/archive`, data);
402
+ }
385
403
  async listBrandAccounts(id) {
386
404
  const data = await this.request('GET', `/brands/${encodeURIComponent(id)}/accounts`);
387
405
  return data.accounts;
@@ -424,6 +442,15 @@ export class PosterlyClient {
424
442
  async dismissSuggestion(id) {
425
443
  return this.request('POST', `/suggestions/${encodeURIComponent(id)}/dismiss`, {});
426
444
  }
445
+ async acceptSuggestion(id) {
446
+ return this.request('POST', `/suggestions/${encodeURIComponent(id)}/accept`, {});
447
+ }
448
+ async getMediaAsset(id) {
449
+ return this.request('GET', `/media/${encodeURIComponent(id)}`);
450
+ }
451
+ async deleteMediaAsset(id) {
452
+ return this.request('DELETE', `/media/${encodeURIComponent(id)}`);
453
+ }
427
454
  async listPosts(params) {
428
455
  const searchParams = postFilterParams(params);
429
456
  if (params?.limit)
@@ -564,6 +591,8 @@ export class PosterlyClient {
564
591
  searchParams.set('from', params.from);
565
592
  if (params.to)
566
593
  searchParams.set('to', params.to);
594
+ if (params.include_extras)
595
+ searchParams.set('include', 'extras');
567
596
  return this.request('GET', `/analytics/accounts?${searchParams.toString()}`);
568
597
  }
569
598
  async getPostAnalytics(params) {
@@ -627,6 +656,29 @@ export class PosterlyClient {
627
656
  async deleteGoogleBusinessReviewReply(data) {
628
657
  return this.request('DELETE', '/google-business/reviews/reply', data);
629
658
  }
659
+ async getGoogleBusinessServiceArea(params) {
660
+ const searchParams = new URLSearchParams();
661
+ if (params.workspace_id)
662
+ searchParams.set('workspace_id', params.workspace_id);
663
+ if (params.account_id)
664
+ searchParams.set('account_id', String(params.account_id));
665
+ if (params.location_id)
666
+ searchParams.set('location_id', params.location_id);
667
+ const qs = searchParams.toString();
668
+ return this.request('GET', `/google-business/service-area${qs ? `?${qs}` : ''}`);
669
+ }
670
+ async searchGoogleBusinessServiceAreaPlaces(params) {
671
+ const searchParams = new URLSearchParams();
672
+ if (params.workspace_id)
673
+ searchParams.set('workspace_id', params.workspace_id);
674
+ searchParams.set('q', params.q);
675
+ if (params.region_code)
676
+ searchParams.set('region_code', params.region_code);
677
+ return this.request('GET', `/google-business/service-area/places?${searchParams.toString()}`);
678
+ }
679
+ async updateGoogleBusinessServiceArea(data) {
680
+ return this.request('PATCH', '/google-business/service-area', data);
681
+ }
630
682
  async listGoogleBusinessMedia(params) {
631
683
  const searchParams = new URLSearchParams();
632
684
  if (params?.workspace_id)
@@ -644,6 +696,23 @@ export class PosterlyClient {
644
696
  async deleteGoogleBusinessMedia(data) {
645
697
  return this.request('DELETE', '/google-business/media', data);
646
698
  }
699
+ async listGoogleBusinessLocation(params) {
700
+ const searchParams = new URLSearchParams();
701
+ if (params?.workspace_id)
702
+ searchParams.set('workspace_id', params.workspace_id);
703
+ if (params?.account_id)
704
+ searchParams.set('account_id', String(params.account_id));
705
+ if (params?.location_id)
706
+ searchParams.set('location_id', params.location_id);
707
+ const qs = searchParams.toString();
708
+ return this.request('GET', `/google-business/location${qs ? `?${qs}` : ''}`);
709
+ }
710
+ async updateGoogleBusinessHours(data) {
711
+ return this.request('PATCH', '/google-business/location', { ...data, attributes: undefined, regular_hours: data.regular_hours });
712
+ }
713
+ async updateGoogleBusinessAttributes(data) {
714
+ return this.request('PATCH', '/google-business/location', { ...data, regular_hours: undefined, attributes: data.attributes });
715
+ }
647
716
  async listActivity(params) {
648
717
  const searchParams = new URLSearchParams();
649
718
  if (params?.workspace_id)
@@ -681,6 +750,15 @@ export class PosterlyClient {
681
750
  const qs = searchParams.toString();
682
751
  return this.request('GET', `/webhooks${qs ? `?${qs}` : ''}`);
683
752
  }
753
+ async listWebhookDeliveries(webhookId, params) {
754
+ const searchParams = new URLSearchParams();
755
+ if (params?.limit)
756
+ searchParams.set('limit', String(params.limit));
757
+ if (params?.offset != null)
758
+ searchParams.set('offset', String(params.offset));
759
+ const qs = searchParams.toString();
760
+ return this.request('GET', `/webhooks/${encodeURIComponent(webhookId)}/deliveries${qs ? `?${qs}` : ''}`);
761
+ }
684
762
  async createWebhook(data) {
685
763
  return this.request('POST', '/webhooks', data);
686
764
  }
@@ -714,6 +792,12 @@ export class PosterlyClient {
714
792
  async triggerPlatformHelper(data) {
715
793
  return this.request('POST', '/platforms/trigger', data);
716
794
  }
795
+ async quoteXPostingAddon(data) {
796
+ return this.request('POST', '/subscription/x-posting-addon', { ...data, dry_run: true });
797
+ }
798
+ async buyXPostingAddon(data) {
799
+ return this.request('POST', '/subscription/x-posting-addon', data);
800
+ }
717
801
  async getXPostingQuota(params) {
718
802
  const searchParams = new URLSearchParams();
719
803
  if (params?.workspace_id)
@@ -827,6 +911,10 @@ export class PosterlyClient {
827
911
  searchParams.set('limit', String(params.limit));
828
912
  if (params?.offset != null)
829
913
  searchParams.set('offset', String(params.offset));
914
+ if (params?.since)
915
+ searchParams.set('since', params.since);
916
+ if (params?.until)
917
+ searchParams.set('until', params.until);
830
918
  }
831
919
  async listConversations(params) {
832
920
  const searchParams = new URLSearchParams();
@@ -38,17 +38,19 @@ const descriptions = {
38
38
  update_post: 'Edit a draft or scheduled post, change its status, assign release and group identifiers, or manage client approval using the action selector. Published posts cannot be edited.',
39
39
  delete_post: 'Delete one draft or scheduled post, or all eligible posts in a selected group using the action selector. Published posts cannot be deleted.',
40
40
  get_x_posting_quota: 'Read managed X posting usage, quota, remaining posts, URL restrictions, and existing add-on information.',
41
- upload_media: 'Upload an existing image or video to posterly storage from a file, base64 content, or a public HTTPS URL. Returns a reusable media URL and does not publish content.',
41
+ upload_media: 'Upload an existing image or video to posterly storage from a file, base64 content, or a public HTTPS URL. Returns a reusable media URL and does not publish content. Pass asset_id to delete one library file: the first request previews it and deletes nothing until that preview is confirmed. A file a post still uses is kept.',
42
42
  create_signed_upload: 'Create a signed storage upload URL for an existing large image or video.',
43
43
  create_media_drop: 'Create a short-lived browser page for a human to upload existing media without a dashboard login.',
44
44
  list_media: 'List uploaded media assets or files uploaded to a selected media-drop session.',
45
45
  generate_captions: 'Generate or adapt text caption suggestions for social platforms. Uses the caption allowance and does not create or publish posts.',
46
46
  list_analytics: 'Read account analytics, post analytics, post feedback insights, or missing-post requirements using the view selector.',
47
- list_google_business_reviews: 'Read Google Business Profile reviews or the public review link using the view selector.',
47
+ list_google_business_reviews: 'Read Google Business Profile reviews, including each review_name needed to reply, or the public review link using the view selector.',
48
48
  audit_google_business_profile: 'Read and audit a connected Google Business Profile location: completeness, categories, media, attributes, reviews, and recommendations.',
49
49
  manage_google_business_review: 'Suggest text replies, publish owner replies, or delete owner replies to Google Business reviews using the action selector. Suggestions do not publish a reply.',
50
50
  list_google_business_media: 'Read existing photos and videos in connected Google Business Profile galleries.',
51
51
  manage_google_business_media: 'Add an existing photo or video to a Google Business gallery, or delete a gallery item using the action selector.',
52
+ list_google_business_service_areas: 'Read the towns and postcodes a Google Business location serves, or search for a town or postcode to add.',
53
+ manage_google_business_service_area: 'Replace the service areas on a Google Business location using the action selector. Preview then confirm.',
52
54
  list_conversations: 'List Instagram or Facebook Page inbox conversations, or read one conversation using the view selector. Requires a Pro plan and posts:read.',
53
55
  manage_conversation: 'Reply to an Instagram or Facebook Page inbox conversation, or synchronize supported social inbox data using the action selector. Requires a Pro plan and posts:write.',
54
56
  list_comments: 'List Instagram, Facebook Page, Threads, or LinkedIn Page comments, or read one comment using the view selector. Requires a Pro plan and posts:read.',
@@ -1,9 +1,43 @@
1
1
  import type { Account, LearnedVoice, ListPostsResponse, Post, PostCountsResponse, PostsRangeEcho } from './api-client.js';
2
+ export declare function platformText(value: unknown): string | undefined;
3
+ /** The saved live post id, from the row or the metadata keys publish actually writes. */
4
+ export declare function platformPostIdText(post: {
5
+ platform_post_id?: unknown;
6
+ metadata?: unknown;
7
+ }): string | undefined;
8
+ /** Caller group and release ids already stored on the post. Order is stable and duplicates are dropped. */
9
+ export declare function groupReleaseIds(post: {
10
+ post_group_id?: unknown;
11
+ metadata?: unknown;
12
+ }): string[];
13
+ /** Why a publish failed, when the payload includes it. */
14
+ export declare function postFailureText(post: {
15
+ failure?: unknown;
16
+ publish_error?: unknown;
17
+ error_message?: unknown;
18
+ }): string | undefined;
19
+ /**
20
+ * The live missing-content report: object items, or a post plus ready/next_actions.
21
+ * The older `{ missing: ["media"] }` body (no post) stays on the generic formatter.
22
+ */
23
+ export declare function isStructuredMissingReport(data: unknown): boolean;
2
24
  type CellValue = string | number | boolean | null | undefined;
3
25
  export declare const DASHBOARD_CALENDAR_URL: string;
4
26
  export declare const DASHBOARD_TABLE_URL: string;
5
27
  export declare const DASHBOARD_CONNECT_URL: string;
28
+ /** Assistant label for the coarse account health fields. Empty when the payload has none. */
29
+ export declare function connectionHealthLabel(account: {
30
+ connection_status?: string | null;
31
+ connection_reason?: string | null;
32
+ connection_since?: string | null;
33
+ }): string;
6
34
  export declare function formatLocalDateTime(value?: string | null): string;
35
+ /** Account and parent-post fields the inbox already stores on a comment. No posterly post id exists on the row. */
36
+ export declare function inboxCommentContext(comment: unknown): {
37
+ accountId?: string;
38
+ caption?: string;
39
+ link?: string;
40
+ };
7
41
  export declare function dashboardUrlForPost(post: Pick<Post, 'id' | 'scheduled_at'>): string;
8
42
  export declare function dashboardUrlForPosts(): string;
9
43
  export declare function dashboardUrlForPostList(posts: Array<Pick<Post, 'scheduled_at'>>): string;
@@ -68,6 +102,16 @@ export declare function formatCalendarDay(day: string): string;
68
102
  * day before); anything else reads as "from X up to Y".
69
103
  */
70
104
  export declare function formatPostRange(range: PostListRange): string;
105
+ export type PublicApiKeyRow = {
106
+ id?: string;
107
+ name?: string;
108
+ key_prefix?: string;
109
+ scopes?: string[];
110
+ created_at?: string | null;
111
+ last_used_at?: string | null;
112
+ };
113
+ /** Assistant card for GET /api/v1/api-keys. Prints only the public fields. */
114
+ export declare function formatApiKeyList(keys: PublicApiKeyRow[] | null | undefined): string;
71
115
  /** ISO 8601 in UTC to the second ("2026-10-07T07:32:54Z"); "unknown" when missing. */
72
116
  export declare function formatIsoTimestamp(value: string | null | undefined): string;
73
117
  /** "Georgia via Dashboard"; whichever half was never recorded reads as unknown. */
@@ -1,14 +1,101 @@
1
+ export function platformText(value) {
2
+ if (Array.isArray(value)) {
3
+ const parts = value.map((item) => (item == null ? '' : String(item).trim())).filter(Boolean);
4
+ return parts.length ? parts.join(', ') : undefined;
5
+ }
6
+ if (typeof value === 'string' && value.trim())
7
+ return value.trim();
8
+ if (typeof value === 'number' && Number.isFinite(value))
9
+ return String(value);
10
+ return undefined;
11
+ }
12
+ function asRecord(value) {
13
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
14
+ }
15
+ function scalarText(value) {
16
+ if (typeof value === 'number' && Number.isFinite(value))
17
+ return String(value);
18
+ if (typeof value === 'string' && value.trim())
19
+ return value.trim();
20
+ return undefined;
21
+ }
22
+ const PLATFORM_POST_ID_KEYS = ['platform_post_id', 'instagram_media_id', 'facebook_post_id', 'x_tweet_id', 'threads_media_id'];
23
+ /** The saved live post id, from the row or the metadata keys publish actually writes. */
24
+ export function platformPostIdText(post) {
25
+ const direct = scalarText(post.platform_post_id);
26
+ if (direct)
27
+ return direct;
28
+ const meta = asRecord(post.metadata);
29
+ for (const key of PLATFORM_POST_ID_KEYS) {
30
+ const value = scalarText(meta[key]);
31
+ if (value)
32
+ return value;
33
+ }
34
+ return scalarText(asRecord(meta.bluesky).uri);
35
+ }
36
+ /** Caller group and release ids already stored on the post. Order is stable and duplicates are dropped. */
37
+ export function groupReleaseIds(post) {
38
+ const meta = asRecord(post.metadata);
39
+ const values = [post.post_group_id, meta.post_group_id, meta.api_group_id, meta.group_id, meta.release_id];
40
+ return [...new Set(values.map(scalarText).filter((value) => Boolean(value)))];
41
+ }
42
+ /** Why a publish failed, when the payload includes it. */
43
+ export function postFailureText(post) {
44
+ const failure = asRecord(post.failure);
45
+ const message = scalarText(failure.message) || scalarText(asRecord(post.publish_error).message) || scalarText(post.error_message);
46
+ if (!message)
47
+ return undefined;
48
+ const code = scalarText(failure.code);
49
+ return code && !message.includes(code) ? `${message} (${code})` : message;
50
+ }
51
+ /**
52
+ * The live missing-content report: object items, or a post plus ready/next_actions.
53
+ * The older `{ missing: ["media"] }` body (no post) stays on the generic formatter.
54
+ */
55
+ export function isStructuredMissingReport(data) {
56
+ if (!data || typeof data !== 'object')
57
+ return false;
58
+ const body = data;
59
+ if (!Array.isArray(body.missing))
60
+ return false;
61
+ if (body.missing.some((item) => item && typeof item === 'object'))
62
+ return true;
63
+ return Boolean(body.post) && ('ready' in body || Array.isArray(body.next_actions));
64
+ }
1
65
  const POSTERLY_APP_URL = (process.env.POSTERLY_URL || 'https://www.poster.ly').replace(/\/$/, '');
2
66
  export const DASHBOARD_CALENDAR_URL = `${POSTERLY_APP_URL}/dashboard/calendar`;
3
67
  export const DASHBOARD_TABLE_URL = `${POSTERLY_APP_URL}/dashboard/table`;
4
68
  export const DASHBOARD_CONNECT_URL = `${POSTERLY_APP_URL}/dashboard/connect`;
69
+ /** Assistant label for the coarse account health fields. Empty when the payload has none. */
70
+ export function connectionHealthLabel(account) {
71
+ if (account.connection_status === 'needs_reconnect') {
72
+ const reason = account.connection_reason === 'access_token_expired'
73
+ ? 'access token expired'
74
+ : 'reconnect required';
75
+ const since = account.connection_since ? ` since ${account.connection_since}` : '';
76
+ return `needs reconnect (${reason}${since})`;
77
+ }
78
+ if (account.connection_status === 'ok')
79
+ return 'ok';
80
+ return '';
81
+ }
5
82
  export function formatLocalDateTime(value) {
6
83
  if (!value)
7
84
  return 'N/A';
8
85
  const date = new Date(value);
9
86
  if (Number.isNaN(date.getTime()))
10
87
  return value;
11
- return date.toLocaleString();
88
+ return formatIsoTimestamp(value);
89
+ }
90
+ /** Account and parent-post fields the inbox already stores on a comment. No posterly post id exists on the row. */
91
+ export function inboxCommentContext(comment) {
92
+ const row = comment && typeof comment === 'object' ? comment : {};
93
+ const rawId = row.social_account_id;
94
+ const accountId = rawId != null && rawId !== '' ? String(rawId) : undefined;
95
+ const preview = row.post_preview && typeof row.post_preview === 'object' ? row.post_preview : null;
96
+ const caption = typeof preview?.caption === 'string' ? preview.caption.replace(/\s+/g, ' ').trim() : '';
97
+ const link = typeof preview?.permalink === 'string' ? preview.permalink.trim() : '';
98
+ return { accountId, caption: caption || undefined, link: link || undefined };
12
99
  }
13
100
  export function dashboardUrlForPost(post) {
14
101
  const baseUrl = isInCurrentMonth(post.scheduled_at) ? DASHBOARD_CALENDAR_URL : DASHBOARD_TABLE_URL;
@@ -117,7 +204,7 @@ export function formatDateTime(value) {
117
204
  const date = new Date(value);
118
205
  if (Number.isNaN(date.getTime()))
119
206
  return value;
120
- return date.toLocaleString();
207
+ return formatIsoTimestamp(value);
121
208
  }
122
209
  export function formatDate(value) {
123
210
  if (!value)
@@ -203,8 +290,20 @@ export function statusLabel(status) {
203
290
  return `⏸️ ${status}`;
204
291
  return status || 'unknown';
205
292
  }
293
+ const GROUPED_INTEGER = /^[+-]?\d{1,3}(?:,\d{3})+$/;
294
+ /** Plain digits for an id, or null when code() should use the normal cell formatter. Keep in step with id-text.ts. */
295
+ function idCodeText(value) {
296
+ if (typeof value === 'number' && Number.isFinite(value))
297
+ return String(value);
298
+ if (typeof value === 'string' && GROUPED_INTEGER.test(value.trim()))
299
+ return value.trim().replace(/,/g, '');
300
+ return null;
301
+ }
206
302
  export function code(value) {
207
- return `\`${formatCell(value).replace(/`/g, '\\`')}\``;
303
+ // Ids stay plain digits. formatCell would print 1961 as "1,961", which is
304
+ // not a valid id to paste back into another tool. Metrics do not use code().
305
+ const text = idCodeText(value) ?? formatCell(value);
306
+ return `\`${text.replace(/`/g, '\\`')}\``;
208
307
  }
209
308
  function formatCell(value) {
210
309
  if (value === null || value === undefined || value === '')
@@ -304,6 +403,25 @@ export function formatPostRange(range) {
304
403
  const to = range.to ? `up to ${formatDateTimeInZone(range.to, tz)}` : '';
305
404
  return `${[from, to].filter(Boolean).join(' ')} (${tz})`;
306
405
  }
406
+ /** Assistant card for GET /api/v1/api-keys. Prints only the public fields. */
407
+ export function formatApiKeyList(keys) {
408
+ const rows = Array.isArray(keys) ? keys : [];
409
+ const table = rows.length
410
+ ? mdTable(['Name', 'Prefix', 'Scopes', 'Created', 'Last used', 'Key ID'], rows.map((key) => [
411
+ key.name || 'unnamed',
412
+ key.key_prefix || 'n/a',
413
+ key.scopes?.length ? key.scopes.join(', ') : 'none',
414
+ key.created_at ? formatIsoTimestamp(key.created_at) : 'unknown',
415
+ key.last_used_at ? formatIsoTimestamp(key.last_used_at) : 'never',
416
+ code(String(key.id || '')),
417
+ ]))
418
+ : 'No API keys on this account.';
419
+ return [
420
+ mdTitle('API keys'),
421
+ table,
422
+ 'The secret is never listed. Revoke one with delete_api_key. That tool refuses to revoke the key making the call.',
423
+ ].join('\n\n');
424
+ }
307
425
  /** ISO 8601 in UTC to the second ("2026-10-07T07:32:54Z"); "unknown" when missing. */
308
426
  export function formatIsoTimestamp(value) {
309
427
  if (!value)
@@ -361,7 +479,8 @@ export function formatPostListPage(data, options) {
361
479
  : first === 1
362
480
  ? `**Complete: all ${total} matching posts are shown.**`
363
481
  : `**Complete: this is the last page (posts ${first}-${last} of ${total}).**`;
364
- const table = mdTable(['Status', 'Post ID', `Scheduled (${tz})`, 'Type', 'Account ID', 'Brand ID', 'Approval', 'Created', 'Created by', 'Caption'],
482
+ const showPlatform = posts.some((post) => platformText(post.platform));
483
+ const table = mdTable(['Status', 'Post ID', `Scheduled (${tz})`, 'Type', ...(showPlatform ? ['Platform'] : []), 'Account ID', 'Brand ID', 'Approval', 'Created', 'Created by', 'Caption'],
365
484
  // The API post row carries account and brand IDs only (no joined names);
366
485
  // list_accounts and list_brands, or view=counts, resolve them.
367
486
  posts.map((post) => [
@@ -369,6 +488,7 @@ export function formatPostListPage(data, options) {
369
488
  code(String(post.id)),
370
489
  formatDateTimeInZone(post.scheduled_at, tz),
371
490
  post.post_type || 'post',
491
+ ...(showPlatform ? [platformText(post.platform) || 'n/a'] : []),
372
492
  post.social_account_id != null ? String(post.social_account_id) : 'n/a',
373
493
  post.brand_id || 'none',
374
494
  approvalCell(post),
@@ -402,7 +522,7 @@ export function formatPostCounts(data) {
402
522
  mdSection('By account', mdTable(['Account', 'Platform', 'Account ID', 'Posts'], (data.by_account || []).map((row) => [
403
523
  row.username ? `@${row.username}` : row.account_id ? 'unknown account' : 'no account',
404
524
  row.platform || 'n/a',
405
- row.account_id ?? 'none',
525
+ row.account_id != null && row.account_id !== '' ? String(row.account_id) : 'none',
406
526
  row.count,
407
527
  ]))),
408
528
  mdSection('By brand', mdTable(['Brand', 'Brand ID', 'Posts'], (data.by_brand || []).map((row) => [row.name || (row.brand_id ? 'unknown brand' : 'no brand'), row.brand_id ?? 'none', row.count]))),
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Preview text for Google Business location edits, shared by the hosted and
3
+ * npm MCP servers. An hours or attribute edit replaces what is on the public
4
+ * profile, so the preview lists what is there now next to what will be set.
5
+ */
6
+ export type GbpPreviewPeriod = {
7
+ open_day?: unknown;
8
+ open_time?: unknown;
9
+ close_day?: unknown;
10
+ close_time?: unknown;
11
+ };
12
+ export type GbpPreviewAttribute = {
13
+ name?: unknown;
14
+ value_type?: unknown;
15
+ values?: unknown;
16
+ };
17
+ export declare const GBP_CLOSED_DAYS_NOTE = "A day with no opening period shows as closed on Google.";
18
+ export declare function gbpPeriodLines(periods: GbpPreviewPeriod[] | null | undefined, empty: string): string;
19
+ export declare function gbpAttributeLines(attributes: GbpPreviewAttribute[] | null | undefined, empty: string): string;
20
+ /** The current values of only the attributes this edit names. */
21
+ export declare function gbpCurrentAttributesFor(current: GbpPreviewAttribute[] | null | undefined, requested: GbpPreviewAttribute[] | null | undefined): GbpPreviewAttribute[];
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Preview text for Google Business location edits, shared by the hosted and
3
+ * npm MCP servers. An hours or attribute edit replaces what is on the public
4
+ * profile, so the preview lists what is there now next to what will be set.
5
+ */
6
+ export const GBP_CLOSED_DAYS_NOTE = 'A day with no opening period shows as closed on Google.';
7
+ export function gbpPeriodLines(periods, empty) {
8
+ const rows = Array.isArray(periods) ? periods : [];
9
+ if (!rows.length)
10
+ return empty;
11
+ return rows
12
+ .map((period) => `- ${String(period?.open_day ?? '?')} ${String(period?.open_time ?? '?')} to ${String(period?.close_day ?? '?')} ${String(period?.close_time ?? '?')}`)
13
+ .join('\n');
14
+ }
15
+ export function gbpAttributeLines(attributes, empty) {
16
+ const rows = Array.isArray(attributes) ? attributes : [];
17
+ if (!rows.length)
18
+ return empty;
19
+ return rows
20
+ .map((attribute) => `- ${String(attribute?.name ?? '?')} (${String(attribute?.value_type ?? '?')}): ${Array.isArray(attribute?.values) ? attribute.values.join(', ') : ''}`)
21
+ .join('\n');
22
+ }
23
+ /** The current values of only the attributes this edit names. */
24
+ export function gbpCurrentAttributesFor(current, requested) {
25
+ const names = new Set((Array.isArray(requested) ? requested : []).map((attribute) => String(attribute?.name ?? '')));
26
+ return (Array.isArray(current) ? current : []).filter((attribute) => names.has(String(attribute?.name ?? '')));
27
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The Google review resource name that reply and delete-reply accept:
3
+ * accounts/{account}/locations/{location}/reviews/{review}.
4
+ *
5
+ * List responses from Google put this on `name`. The public API also copies it
6
+ * to `review_name` so a list row can be passed straight to a reply. Both MCP
7
+ * formatters read it from here so the hosted endpoint and the npm package
8
+ * agree.
9
+ */
10
+ export declare function isGoogleBusinessReviewResourceName(value: unknown): value is string;
11
+ /**
12
+ * locations/{id} from a location_name that may be "locations/{id}",
13
+ * "accounts/{a}/locations/{id}", or either with trailing slashes.
14
+ */
15
+ export declare function googleBusinessLocationResourceName(locationName: string): string | null;
16
+ /**
17
+ * Canonical review_name for one Google review.
18
+ * Prefers a resource name already on the review. Otherwise builds one from
19
+ * the location's account/location metadata and the review id.
20
+ */
21
+ export declare function googleBusinessReviewResourceName(params: {
22
+ name?: unknown;
23
+ review_name?: unknown;
24
+ reviewId?: unknown;
25
+ accountName?: string | null;
26
+ locationName?: string | null;
27
+ }): string | null;
28
+ /** Owner reply text, when Google sent one. Whitespace is collapsed for a single cell. */
29
+ export declare function reviewReplyComment(review: {
30
+ reviewReply?: unknown;
31
+ } | null | undefined): string | null;
32
+ /** review_name a formatted list row can show, from the fields a list response carries. */
33
+ export declare function reviewNameFromListItem(review: {
34
+ review_name?: unknown;
35
+ name?: unknown;
36
+ } | null | undefined): string | null;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The Google review resource name that reply and delete-reply accept:
3
+ * accounts/{account}/locations/{location}/reviews/{review}.
4
+ *
5
+ * List responses from Google put this on `name`. The public API also copies it
6
+ * to `review_name` so a list row can be passed straight to a reply. Both MCP
7
+ * formatters read it from here so the hosted endpoint and the npm package
8
+ * agree.
9
+ */
10
+ /**
11
+ * A path segment is rejected when it is empty, a dot segment, or carries a
12
+ * character that could change what URL the name resolves to (?, #, %).
13
+ */
14
+ function isSafePathSegment(segment) {
15
+ if (!segment || segment === '.' || segment === '..')
16
+ return false;
17
+ return !/[?#%]/.test(segment);
18
+ }
19
+ export function isGoogleBusinessReviewResourceName(value) {
20
+ if (typeof value !== 'string')
21
+ return false;
22
+ const parts = value.trim().split('/');
23
+ if (parts.length !== 6)
24
+ return false;
25
+ if (parts[0] !== 'accounts' || parts[2] !== 'locations' || parts[4] !== 'reviews')
26
+ return false;
27
+ return isSafePathSegment(parts[1]) && isSafePathSegment(parts[3]) && isSafePathSegment(parts[5]);
28
+ }
29
+ /**
30
+ * locations/{id} from a location_name that may be "locations/{id}",
31
+ * "accounts/{a}/locations/{id}", or either with trailing slashes.
32
+ */
33
+ export function googleBusinessLocationResourceName(locationName) {
34
+ const trimmed = locationName.trim().replace(/\/+$/, '');
35
+ if (!trimmed)
36
+ return null;
37
+ const id = trimmed.split('/').filter(Boolean).pop();
38
+ if (!id || !isSafePathSegment(id))
39
+ return null;
40
+ return `locations/${id}`;
41
+ }
42
+ /**
43
+ * Canonical review_name for one Google review.
44
+ * Prefers a resource name already on the review. Otherwise builds one from
45
+ * the location's account/location metadata and the review id.
46
+ */
47
+ export function googleBusinessReviewResourceName(params) {
48
+ for (const candidate of [params.review_name, params.name]) {
49
+ if (isGoogleBusinessReviewResourceName(candidate))
50
+ return candidate.trim();
51
+ }
52
+ const reviewId = typeof params.reviewId === 'string' ? params.reviewId.trim() : '';
53
+ if (!reviewId || reviewId.includes('/'))
54
+ return null;
55
+ const accountName = (params.accountName || '').trim().replace(/\/+$/, '');
56
+ if (!/^accounts\/[^/]+$/.test(accountName))
57
+ return null;
58
+ const locationName = googleBusinessLocationResourceName(params.locationName || '');
59
+ if (!locationName)
60
+ return null;
61
+ const built = `${accountName}/${locationName}/reviews/${reviewId}`;
62
+ return isGoogleBusinessReviewResourceName(built) ? built : null;
63
+ }
64
+ /** Owner reply text, when Google sent one. Whitespace is collapsed for a single cell. */
65
+ export function reviewReplyComment(review) {
66
+ const reply = review?.reviewReply;
67
+ const raw = typeof reply === 'string'
68
+ ? reply
69
+ : reply && typeof reply === 'object'
70
+ ? reply.comment || reply.text
71
+ : '';
72
+ const text = String(raw || '').replace(/\s+/g, ' ').trim();
73
+ return text || null;
74
+ }
75
+ /** review_name a formatted list row can show, from the fields a list response carries. */
76
+ export function reviewNameFromListItem(review) {
77
+ if (!review || typeof review !== 'object')
78
+ return null;
79
+ return googleBusinessReviewResourceName({
80
+ review_name: review.review_name,
81
+ name: review.name,
82
+ });
83
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * npm tool schemas are zod, and a z.number() id rejects both "1961" and
3
+ * "1,961", while a z.string() id rejects the number 1961. Agents copy ids
4
+ * from either shape. Loosen id fields only: counts, limits, and ratings
5
+ * stay strict.
6
+ */
7
+ import { type ZodTypeAny } from 'zod';
8
+ /** Accept a number or a digit string (with or without thousands separators) for one id schema. */
9
+ export declare function loosenIdSchema(schema: ZodTypeAny): ZodTypeAny;
10
+ export declare function loosenIdShape(shape: Record<string, ZodTypeAny>): Record<string, ZodTypeAny>;
11
+ /** Used by scripts/test-mcp-plain-ids.ts so the assertion shares this file's zod. */
12
+ export declare function parseFlexibleId(kind: 'number' | 'string', value: unknown): unknown;
13
+ /** Same loosening for an alias's old object schema, so a pasted id still validates. */
14
+ export declare function loosenIdObject(schema: ZodTypeAny): ZodTypeAny;