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
@@ -1,14 +1,33 @@
1
1
  import { z } from 'zod';
2
- import { mdSuccess } from '../lib/format.js';
2
+ import { code, mdSuccess } from '../lib/format.js';
3
+ import { suggestionAcceptNote } from '../lib/suggestion-accept-note.js';
3
4
  export const dismissSuggestionTool = {
4
5
  name: 'dismiss_suggestion',
5
- description: 'Dismiss a proactive post suggestion so it stops appearing. WRITE: confirm the exact suggestion with the user first. Never dismisses a suggestion that was already turned into a scheduled post (that would break adoption tracking).',
6
+ description: 'Dismiss a proactive post suggestion so it stops appearing, or pass save_as_draft true to turn it into an unpublished draft instead. A draft is not scheduled and nothing is published. WRITE: confirm the exact suggestion with the user first. Never dismisses, and does not overwrite, a suggestion that was already turned into a post.',
6
7
  inputSchema: z.object({
7
8
  suggestion_id: z
8
9
  .string()
9
10
  .describe('Suggestion ID from list_post_suggestions.'),
11
+ save_as_draft: z
12
+ .boolean()
13
+ .optional()
14
+ .describe('True saves the suggestion as an unpublished draft and does not dismiss it. Omit to dismiss.'),
10
15
  }),
11
16
  async execute(client, input) {
17
+ if (input.scheduled_at || input.publish_at || input.publish) {
18
+ throw new Error('Saving a suggestion creates an unpublished draft. It does not schedule or publish.');
19
+ }
20
+ if (input.save_as_draft === true) {
21
+ const result = await client.acceptSuggestion(input.suggestion_id);
22
+ const postId = result.post_id != null ? code(String(result.post_id)) : 'unknown';
23
+ return [
24
+ mdSuccess(result.already_saved ? 'Suggestion already saved' : 'Suggestion saved as a draft', [
25
+ ['Post ID', postId],
26
+ ['Status', result.status || 'unknown'],
27
+ ]),
28
+ suggestionAcceptNote(Boolean(result.already_saved), result.status ?? null),
29
+ ].join('\n\n');
30
+ }
12
31
  const result = await client.dismissSuggestion(input.suggestion_id);
13
32
  return mdSuccess('Suggestion dismissed', [
14
33
  ['Suggestion ID', input.suggestion_id],
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { formatDate, mdEmpty, mdTable, mdTitle, starGlyphs } from '../lib/format.js';
2
+ import { formatDate, formatIsoTimestamp, mdEmpty, mdTable, mdTitle, starGlyphs } from '../lib/format.js';
3
3
  const SUGGESTED_BASIS_LABELS = {
4
4
  yours: 'Based on your posts',
5
5
  platform: 'Popular on this platform',
@@ -7,7 +7,7 @@ const SUGGESTED_BASIS_LABELS = {
7
7
  };
8
8
  export const findSlotTool = {
9
9
  name: 'find_available_slot',
10
- description: 'Find available time slots for posting. Respects a 1-hour gap between posts and preferred hours (8am-10pm in the given timezone). Returns up to 10 slots. IMPORTANT: pass a timezone explicitly - default is America/New_York and slots will be off if the user is elsewhere. Pass workspace_id to only avoid collisions with posts in that workspace. strategy "best_engagement" (needs account_ids) ranks the next 7 days by when these accounts get the most engagement, with a 1-5 star rating and a reason per slot.',
10
+ description: 'Find available time slots for posting. Respects a 1-hour gap between posts and preferred hours (8am-10pm in the given timezone). Returns up to 10 slots. IMPORTANT: pass a timezone explicitly - default is America/New_York and slots will be off if the user is elsewhere. Each slot includes the UTC instant to pass as scheduled_at. Pass workspace_id to only avoid collisions with posts in that workspace. strategy "best_engagement" (needs account_ids) ranks the next 7 days by when these accounts get the most engagement, with a 1-5 star rating and a reason per slot.',
11
11
  inputSchema: z.object({
12
12
  account_ids: z
13
13
  .array(z.string())
@@ -54,9 +54,10 @@ export const findSlotTool = {
54
54
  `Basis: ${basis}${result.timezone ? ` (${result.timezone})` : ''}`,
55
55
  // local_time already carries the date in the requested timezone, so
56
56
  // no separate Date column (a machine-local date could disagree).
57
- mdTable(['Option', 'Local time', 'Rating', 'Why'], slots.map((slot, index) => [
57
+ mdTable(['Option', 'Local time', 'UTC', 'Rating', 'Why'], slots.map((slot, index) => [
58
58
  index + 1,
59
59
  slot.local_time,
60
+ slot.time ? formatIsoTimestamp(slot.time) : 'n/a',
60
61
  starGlyphs(slot.stars, slot.basis === 'default'),
61
62
  slot.reason || 'n/a',
62
63
  ])),
@@ -68,11 +69,13 @@ export const findSlotTool = {
68
69
  }
69
70
  return [
70
71
  mdTitle(`Available posting slots (${slots.length})`),
71
- mdTable(['Option', 'Local time', 'Date'], slots.map((slot, index) => [
72
+ mdTable(['Option', 'Local time', 'Date', 'UTC'], slots.map((slot, index) => [
72
73
  index + 1,
73
74
  slot.local_time,
74
75
  formatDate(slot.time),
76
+ formatIsoTimestamp(slot.time),
75
77
  ])),
78
+ 'Pass the UTC value to create_post as scheduled_at. Local time uses the timezone you passed. If you left timezone out, that zone is America/New_York.',
76
79
  ].join('\n\n');
77
80
  },
78
81
  };
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { dashboardUrlForPost, formatIsoTimestamp, formatLocalDateTime, formatPostCreator } from '../lib/format.js';
2
+ import { dashboardUrlForPost, formatIsoTimestamp, formatLocalDateTime, formatPostCreator, groupReleaseIds, isStructuredMissingReport, platformPostIdText, platformText, postFailureText } from '../lib/format.js';
3
3
  import { validateArgs } from '../lib/tool-runtime.js';
4
4
  export const getPostTool = {
5
5
  name: 'get_post',
6
- description: 'One post by ID. view=post (default): caption, status, scheduled time, when it was created and by whom (account and channel, such as dashboard, API, or MCP), 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.',
6
+ description: 'One post by ID. view=post (default): caption, status, platform, account, scheduled time, when it was created and by whom (account and channel, such as dashboard, API, or MCP), media, a link back to the post in posterly, and the failure reason when a publish failed. view=missing: each missing field (content, media, account, platform settings, or metadata) and how to fix it before the post can publish.',
7
7
  inputSchema: z.object({
8
8
  post_id: z.number().describe('The post ID to look up'),
9
9
  view: z.enum(['post', 'missing']).optional().describe('post (default) or missing.'),
@@ -22,13 +22,30 @@ export const getPostTool = {
22
22
  async function post(client, input) {
23
23
  const result = await client.getPost(input.post_id);
24
24
  const p = result.post;
25
+ const accountId = p.social_account_id ?? p.account_id;
26
+ const failure = postFailureText(p);
27
+ const platformPostId = platformPostIdText(p);
28
+ const groups = groupReleaseIds(p);
25
29
  const lines = [
26
30
  `Post #${p.id}`,
27
31
  `• Status: ${p.status}`,
28
- `• Caption: ${p.content || '(empty)'}`,
29
- `• Type: ${p.post_type || 'unknown'}`,
30
- `• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`,
31
32
  ];
33
+ const platform = platformText(p.platform);
34
+ if (platform)
35
+ lines.push(`• Platform: ${platform}`);
36
+ if (accountId != null && accountId !== '')
37
+ lines.push(`• Account ID: ${accountId}`);
38
+ if (p.workspace_id)
39
+ lines.push(`• Workspace: ${p.workspace_id}`);
40
+ lines.push(`• Caption: ${p.content || '(empty)'}`);
41
+ lines.push(`• Type: ${p.post_type || 'unknown'}`);
42
+ lines.push(`• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`);
43
+ if (failure)
44
+ lines.push(`• Failure: ${failure}`);
45
+ if (platformPostId)
46
+ lines.push(`• Platform post ID: ${platformPostId}`);
47
+ if (groups.length)
48
+ lines.push(`• Group: ${groups.join(', ')}`);
32
49
  if ('created_at' in p)
33
50
  lines.push(`• Created: ${formatIsoTimestamp(p.created_at)}`);
34
51
  if ('created_by' in p)
@@ -46,5 +63,39 @@ async function post(client, input) {
46
63
  }
47
64
  async function postMissing(client, input) {
48
65
  const result = await client.getPostMissing(input.post_id);
66
+ if (isStructuredMissingReport(result))
67
+ return formatMissingReport(result);
49
68
  return JSON.stringify(result, null, 2);
50
69
  }
70
+ function formatMissingReport(data) {
71
+ const post = data.post && typeof data.post === 'object' ? data.post : null;
72
+ const missing = Array.isArray(data.missing) ? data.missing : [];
73
+ const items = missing.map((item) => {
74
+ if (item && typeof item === 'object') {
75
+ const field = item.field ? String(item.field) : 'item';
76
+ const message = item.message ? String(item.message) : (item.code ? String(item.code) : 'Missing');
77
+ return `${field}: ${message}`;
78
+ }
79
+ return String(item);
80
+ });
81
+ const lines = [
82
+ data.ready ? 'Post is ready to publish' : 'Post is not ready to publish',
83
+ ];
84
+ if (post?.id != null)
85
+ lines.push(`Post #${post.id}`);
86
+ const platform = post ? platformText(post.platform) : undefined;
87
+ if (platform)
88
+ lines.push(`• Platform: ${platform}`);
89
+ const accountId = post ? (post.account_id ?? post.social_account_id) : undefined;
90
+ if (accountId != null && accountId !== '')
91
+ lines.push(`• Account ID: ${accountId}`);
92
+ if (post?.status)
93
+ lines.push(`• Status: ${post.status}`);
94
+ if (post?.post_type)
95
+ lines.push(`• Type: ${post.post_type}`);
96
+ lines.push(items.length ? `Missing:\n${items.map((item) => `• ${item}`).join('\n')}` : 'Nothing required is missing.');
97
+ if (Array.isArray(data.next_actions) && data.next_actions.length) {
98
+ lines.push(`How to fix:\n${data.next_actions.map((action) => `• ${String(action)}`).join('\n')}`);
99
+ }
100
+ return lines.join('\n');
101
+ }
@@ -5,6 +5,7 @@ type ListAccountsInput = {
5
5
  view?: 'accounts' | 'learned_voice' | 'performance_profile' | 'connect_session';
6
6
  workspace_id?: string;
7
7
  account_id?: string | number;
8
+ connection?: 'ok' | 'needs_reconnect';
8
9
  session_id?: string;
9
10
  debug?: boolean;
10
11
  };
@@ -15,17 +16,20 @@ export declare const listAccountsTool: {
15
16
  view: z.ZodOptional<z.ZodEnum<["accounts", "learned_voice", "performance_profile", "connect_session"]>>;
16
17
  workspace_id: z.ZodOptional<z.ZodString>;
17
18
  account_id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
19
+ connection: z.ZodOptional<z.ZodEnum<["ok", "needs_reconnect"]>>;
18
20
  session_id: z.ZodOptional<z.ZodString>;
19
21
  debug: z.ZodOptional<z.ZodBoolean>;
20
22
  }, "strip", z.ZodTypeAny, {
21
23
  account_id?: string | number | undefined;
22
24
  workspace_id?: string | undefined;
25
+ connection?: "ok" | "needs_reconnect" | undefined;
23
26
  view?: "accounts" | "learned_voice" | "performance_profile" | "connect_session" | undefined;
24
27
  session_id?: string | undefined;
25
28
  debug?: boolean | undefined;
26
29
  }, {
27
30
  account_id?: string | number | undefined;
28
31
  workspace_id?: string | undefined;
32
+ connection?: "ok" | "needs_reconnect" | undefined;
29
33
  view?: "accounts" | "learned_voice" | "performance_profile" | "connect_session" | undefined;
30
34
  session_id?: string | undefined;
31
35
  debug?: boolean | undefined;
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { DASHBOARD_CONNECT_URL, code, formatConnectedAccounts, formatDateTime, formatLocalDateTime, formatPercent, mdBullets, mdEmpty, mdKeyValue, mdLearnedVoice, mdQuote, mdSection, mdTable, mdTitle, } from '../lib/format.js';
2
+ import { DASHBOARD_CONNECT_URL, code, connectionHealthLabel, formatConnectedAccounts, formatDateTime, formatLocalDateTime, formatPercent, mdBullets, mdEmpty, mdKeyValue, mdLearnedVoice, mdQuote, mdSection, mdTable, mdTitle, } from '../lib/format.js';
3
3
  import { validateArgs } from '../lib/tool-runtime.js';
4
4
  export const listAccountsTool = {
5
5
  name: 'list_accounts',
6
- description: "Connected social accounts and what posterly has learned about them. view=accounts (default): connected accounts, optionally one workspace_id or one account_id; Instagram rows identify direct-login versus Meta-linked connections and whether native media tags/collaborators are available, so check this before Instagram user_tags or collaborators. view=learned_voice (account_id): the voice learned from the account's real published captions (summary, traits, style guidelines, habits); read-only, never overwrites the saved brand profile. view=performance_profile (account_id): 90-day coaching stats, engagement-rate trend, and summary (Pro plan or higher; platforms without per-post analytics never get one). view=connect_session (session_id): poll a session from create_connect_session and keep the user updated in plain language; stop when status is connected, failed, cancelled, or expired.",
6
+ description: "Connected social accounts and what posterly has learned about them. view=accounts (default): connected accounts, optionally one workspace_id or one account_id. Each row has connection_status ok or needs_reconnect (reason and date, never a token). Pass connection needs_reconnect to list only accounts that need a reconnect. Instagram rows identify direct-login versus Meta-linked connections and whether native media tags/collaborators are available, so check this before Instagram user_tags or collaborators. view=learned_voice (account_id): the voice learned from the account's real published captions (summary, traits, style guidelines, habits); read-only, never overwrites the saved brand profile. view=performance_profile (account_id): 90-day coaching stats, engagement-rate trend, and summary (Pro plan or higher; platforms without per-post analytics never get one). view=connect_session (session_id): poll a session from create_connect_session and keep the user updated in plain language; stop when status is connected, failed, cancelled, or expired.",
7
7
  inputSchema: z.object({
8
8
  view: z
9
9
  .enum(['accounts', 'learned_voice', 'performance_profile', 'connect_session'])
@@ -17,6 +17,10 @@ export const listAccountsTool = {
17
17
  .union([z.string(), z.number()])
18
18
  .optional()
19
19
  .describe('Social account ID from list_accounts. Required for learned_voice and performance_profile; with view=accounts it returns just that account.'),
20
+ connection: z
21
+ .enum(['ok', 'needs_reconnect'])
22
+ .optional()
23
+ .describe('view=accounts: ok, or needs_reconnect to list only accounts that need a reconnect.'),
20
24
  session_id: z.string().optional().describe('view=connect_session: connect session ID returned by create_connect_session.'),
21
25
  debug: z
22
26
  .boolean()
@@ -43,7 +47,7 @@ export const listAccountsTool = {
43
47
  },
44
48
  };
45
49
  async function accountsList(client, input) {
46
- const listed = await client.listAccounts({ workspace_id: input.workspace_id });
50
+ const listed = await client.listAccounts({ workspace_id: input.workspace_id, connection: input.connection });
47
51
  // There is no GET /accounts/:id, so account_id filters the list here.
48
52
  const accounts = input.account_id !== undefined
49
53
  ? listed.filter((account) => String(account.id) === String(input.account_id))
@@ -57,15 +61,30 @@ async function accountsList(client, input) {
57
61
  : mdEmpty('connected accounts', 'posterly does not see any connected social accounts yet.', 'Connect accounts in the posterly dashboard, then run this again.');
58
62
  }
59
63
  const hasInstagram = accounts.some((account) => account.platform === 'instagram');
64
+ // Only when the API sent them, so older fixtures without these fields stay unchanged.
65
+ const hasHealth = accounts.some((account) => connectionHealthLabel(account));
66
+ const showType = accounts.some((account) => account.account_type);
67
+ const showLocation = accounts.some((account) => account.location_id);
68
+ const headers = [
69
+ 'Platform',
70
+ 'Account',
71
+ 'Account ID',
72
+ ...(showType ? ['Type'] : []),
73
+ 'Workspace',
74
+ ...(showLocation ? ['Location ID'] : []),
75
+ ...(hasHealth ? ['Health'] : []),
76
+ ...(hasInstagram ? ['Connection', 'Native tags', 'Collaborators'] : []),
77
+ ];
60
78
  return [
61
79
  mdTitle(`Connected accounts (${accounts.length})`),
62
- mdTable(hasInstagram
63
- ? ['Platform', 'Account', 'Account ID', 'Workspace', 'Connection', 'Native tags', 'Collaborators']
64
- : ['Platform', 'Account', 'Account ID', 'Workspace'], accounts.map((account) => [
80
+ mdTable(headers, accounts.map((account) => [
65
81
  account.platform,
66
82
  `@${account.username}`,
67
83
  code(account.id),
84
+ ...(showType ? [account.account_type || 'n/a'] : []),
68
85
  account.workspace_id ? code(account.workspace_id) : 'default',
86
+ ...(showLocation ? [account.location_id ? code(String(account.location_id)) : 'n/a'] : []),
87
+ ...(hasHealth ? [connectionHealthLabel(account) || 'n/a'] : []),
69
88
  ...(hasInstagram
70
89
  ? account.platform === 'instagram'
71
90
  ? [
@@ -14,6 +14,7 @@ type ListAnalyticsInput = {
14
14
  post_id?: number;
15
15
  checkpoint?: Checkpoint;
16
16
  presentation?: AnalyticsPresentation;
17
+ include_extras?: boolean;
17
18
  };
18
19
  export declare const listAnalyticsTool: {
19
20
  name: string;
@@ -28,6 +29,7 @@ export declare const listAnalyticsTool: {
28
29
  post_id: z.ZodOptional<z.ZodNumber>;
29
30
  checkpoint: z.ZodOptional<z.ZodEnum<["1h", "6h", "24h", "72h", "7d"]>>;
30
31
  presentation: z.ZodOptional<z.ZodEnum<["compact", "table", "json"]>>;
32
+ include_extras: z.ZodOptional<z.ZodBoolean>;
31
33
  }, "strip", z.ZodTypeAny, {
32
34
  view: "posts" | "accounts" | "insights";
33
35
  account_id?: string | number | undefined;
@@ -38,6 +40,7 @@ export declare const listAnalyticsTool: {
38
40
  from?: string | undefined;
39
41
  to?: string | undefined;
40
42
  presentation?: "compact" | "table" | "json" | undefined;
43
+ include_extras?: boolean | undefined;
41
44
  }, {
42
45
  view: "posts" | "accounts" | "insights";
43
46
  account_id?: string | number | undefined;
@@ -48,6 +51,7 @@ export declare const listAnalyticsTool: {
48
51
  from?: string | undefined;
49
52
  to?: string | undefined;
50
53
  presentation?: "compact" | "table" | "json" | undefined;
54
+ include_extras?: boolean | undefined;
51
55
  }>;
52
56
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
53
57
  legacySchemas: {
@@ -1,10 +1,10 @@
1
1
  import { z } from 'zod';
2
- import { formatDateTime, mdEmpty, mdKeyValue, mdSection, mdTitle, truncateText } from '../lib/format.js';
2
+ import { formatDateTime, formatIsoTimestamp, mdEmpty, mdKeyValue, mdSection, mdTitle, truncateText } from '../lib/format.js';
3
3
  import { validateArgs } from '../lib/tool-runtime.js';
4
4
  const presentationSchema = z.enum(['compact', 'table', 'json']).optional();
5
5
  export const listAnalyticsTool = {
6
6
  name: 'list_analytics',
7
- description: 'Analytics for connected social accounts (Instagram, X, Facebook, LinkedIn, Google Business Profile, Pinterest, YouTube, and Threads). view=accounts (account_id): daily snapshots and a period summary with platform-native display_metrics labels. Google Business Profile account analytics includes Calls, Website clicks, and Directions along with Profile Views, Search Views, Maps Views, Customer Actions, and Posts. view=posts (account_id): per-post likes, comments/replies, reach, impressions/views, saves, shares, reposts, quotes, plays, clicks, and watch time, most recent first, with limit/offset. view=insights: per-post feedback insights with a performance tier (great/good/mixed/poor), diagnosis, next action, and baseline, filtered by account_id, post_id, or checkpoint (1h, 6h, 24h, 72h, 7d); read-only, Pro plan or higher. presentation (accounts and posts): compact for Telegram/mobile, table for Markdown clients, json for custom chart/card renderers.',
7
+ description: 'Analytics for connected social accounts (Instagram, X, Facebook, LinkedIn, Google Business Profile, Pinterest, YouTube, and Threads). view=accounts (account_id): daily snapshots and a period summary with platform-native display_metrics labels. Google Business Profile account analytics includes Calls, Website clicks, and Directions along with Profile Views, Search Views, Maps Views, Customer Actions, and Posts. view=posts (account_id): per-post likes, comments/replies, reach, impressions/views, saves, shares, reposts, quotes, plays, clicks, and watch time, most recent first, with limit/offset. Google Business has no per-post rows; its totals are on view=accounts. view=insights: per-post feedback insights with a performance tier (great/good/mixed/poor), diagnosis, next action, and baseline, filtered by account_id, post_id, or checkpoint (1h, 6h, 24h, 72h, 7d); read-only, Pro plan or higher. presentation (accounts and posts): compact for Telegram/mobile, table for Markdown clients, json for custom chart/card renderers. include_extras on accounts asks for saved audience breakdowns, the last analytics sync, and entity snapshots. Those stay off until snapshot extras are switched on, and this does not start a new sync.',
8
8
  inputSchema: z.object({
9
9
  view: z.enum(['accounts', 'posts', 'insights']).describe('accounts, posts, or insights.'),
10
10
  account_id: z
@@ -32,6 +32,7 @@ export const listAnalyticsTool = {
32
32
  .optional()
33
33
  .describe('insights: filter to one checkpoint after publish.'),
34
34
  presentation: presentationSchema.describe('accounts and posts: compact, table, or json.'),
35
+ include_extras: z.boolean().optional().describe('accounts: also return saved audience breakdowns, sync status, and entity snapshots when that read is switched on.'),
35
36
  }),
36
37
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
37
38
  legacySchemas: {
@@ -77,7 +78,7 @@ async function postInsights(client, input) {
77
78
  const blocks = insights.map((insight) => {
78
79
  const heading = `${insight.title || 'Insight'} (${insight.performance_tier}, ${insight.checkpoint})`;
79
80
  return mdSection(heading, mdKeyValue([
80
- ['Post ID', insight.post_id],
81
+ ['Post ID', insight.post_id != null ? String(insight.post_id) : undefined],
81
82
  ['Platform', insight.platform],
82
83
  ['Account', insight.username ? `@${insight.username}` : String(insight.social_account_id)],
83
84
  ['Diagnosis', truncateText(insight.diagnosis, 220)],
@@ -91,9 +92,10 @@ async function postInsights(client, input) {
91
92
  return [mdTitle(`Post feedback insights (${insights.length})`), ...blocks].join('\n\n');
92
93
  }
93
94
  function formatAccountAnalytics(result, presentation) {
94
- const { account, range, summary, snapshots } = result;
95
+ const { account, range, summary, snapshots, extras } = result;
95
96
  const rows = accountMetricRows(summary, account.platform);
96
97
  const insights = analyticsInsights(summary, account.platform);
98
+ const saved = formatAccountExtras(extras);
97
99
  if (presentation === 'json') {
98
100
  return JSON.stringify({
99
101
  type: 'account_analytics',
@@ -104,6 +106,7 @@ function formatAccountAnalytics(result, presentation) {
104
106
  insights,
105
107
  summary,
106
108
  snapshots,
109
+ ...(extras ? { extras } : {}),
107
110
  }, null, 2);
108
111
  }
109
112
  if (presentation === 'table') {
@@ -122,6 +125,7 @@ function formatAccountAnalytics(result, presentation) {
122
125
  '',
123
126
  '**Quick read**',
124
127
  insights.map((insight) => `- ${insight}`).join('\n'),
128
+ ...(saved ? [saved] : []),
125
129
  ].join('\n');
126
130
  }
127
131
  return [
@@ -137,8 +141,22 @@ function formatAccountAnalytics(result, presentation) {
137
141
  '',
138
142
  '**Quick read**',
139
143
  insights.map((insight) => `- ${insight}`).join('\n'),
144
+ ...(saved ? [saved] : []),
140
145
  ].join('\n');
141
146
  }
147
+ function formatAccountExtras(extras) {
148
+ if (!extras)
149
+ return '';
150
+ if (extras.enabled !== true)
151
+ return '\n**Saved detail**\nSaved audience breakdowns are switched off.';
152
+ const days = Array.isArray(extras.demographics) ? extras.demographics.length : 0;
153
+ const entities = Array.isArray(extras.entity_snapshots) ? extras.entity_snapshots.length : 0;
154
+ const sync = extras.sync_status;
155
+ const syncLine = sync
156
+ ? `Last sync ${sync.last_synced_at || 'unknown'} (${sync.status || 'unknown'}), ${sync.posts_synced ?? 'n/a'} posts.`
157
+ : 'No sync status saved.';
158
+ return `\n**Saved detail**\n- Audience days: ${days}\n- ${syncLine}\n- Entity snapshots: ${entities}`;
159
+ }
142
160
  function accountMetricRows(summary, platform) {
143
161
  const nativeRows = nativeMetricRows(summary);
144
162
  if (nativeRows.length > 0)
@@ -224,7 +242,12 @@ function escapeCell(value) {
224
242
  function formatPostAnalytics(result, presentation) {
225
243
  const { account, range, posts, total } = result;
226
244
  if (posts.length === 0) {
227
- return `No analytics found for ${accountLabel(account.username)} (${account.platform}) between ${range.from} and ${range.to}.`;
245
+ const who = `${accountLabel(account.username)} (${account.platform})`;
246
+ const window = `between ${range.from} and ${range.to}`;
247
+ if (account.platform === 'google_business') {
248
+ return `Google Business analytics cover the location (profile views, searches, and customer actions), not each post. No per-post rows were found for ${who} ${window}. Ask for the account view to see those totals.`;
249
+ }
250
+ return `No analytics found for ${who} ${window}.`;
228
251
  }
229
252
  const totals = posts.reduce((acc, post) => {
230
253
  acc.likes += post.likes || 0;
@@ -387,8 +410,7 @@ function postExtras(platform, post) {
387
410
  function dateTime(value) {
388
411
  if (!value)
389
412
  return 'n/a';
390
- const date = new Date(value);
391
- return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
413
+ return formatIsoTimestamp(value);
392
414
  }
393
415
  function compact(value, maxLength) {
394
416
  const text = String(value || '').replace(/\s+/g, ' ').trim();
@@ -10,7 +10,11 @@ type CommentsInput = {
10
10
  search?: string;
11
11
  limit?: number;
12
12
  offset?: number;
13
+ since?: string;
14
+ until?: string;
13
15
  };
16
+ /** One list line for a comment: when, account, author ("you" or "(no handle)" when needed), flags, text. */
17
+ export declare function formatCommentListLine(comment: Record<string, unknown>): string;
14
18
  export declare const listCommentsTool: {
15
19
  name: string;
16
20
  description: string;
@@ -23,14 +27,18 @@ export declare const listCommentsTool: {
23
27
  search: z.ZodOptional<z.ZodString>;
24
28
  limit: z.ZodOptional<z.ZodNumber>;
25
29
  offset: z.ZodOptional<z.ZodNumber>;
30
+ since: z.ZodOptional<z.ZodString>;
31
+ until: z.ZodOptional<z.ZodString>;
26
32
  }, "strip", z.ZodTypeAny, {
27
33
  platform?: "instagram" | "facebook" | "threads" | "linkedin" | undefined;
28
34
  account_id?: number | undefined;
29
35
  workspace_id?: string | undefined;
30
36
  limit?: number | undefined;
31
37
  offset?: number | undefined;
38
+ since?: string | undefined;
32
39
  filter?: "all" | "unread" | "flagged" | undefined;
33
40
  search?: string | undefined;
41
+ until?: string | undefined;
34
42
  comment_id?: string | undefined;
35
43
  }, {
36
44
  platform?: "instagram" | "facebook" | "threads" | "linkedin" | undefined;
@@ -38,8 +46,10 @@ export declare const listCommentsTool: {
38
46
  workspace_id?: string | undefined;
39
47
  limit?: number | undefined;
40
48
  offset?: number | undefined;
49
+ since?: string | undefined;
41
50
  filter?: "all" | "unread" | "flagged" | undefined;
42
51
  search?: string | undefined;
52
+ until?: string | undefined;
43
53
  comment_id?: string | undefined;
44
54
  }>;
45
55
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { formatLocalDateTime, truncateText } from '../lib/format.js';
2
+ import { formatLocalDateTime, inboxCommentContext, truncateText } from '../lib/format.js';
3
3
  import { validateArgs } from '../lib/tool-runtime.js';
4
4
  const INBOX_PLATFORMS = ['instagram', 'facebook', 'threads', 'linkedin'];
5
5
  /**
@@ -19,18 +19,55 @@ function describeSkippedWorkspaces(result) {
19
19
  });
20
20
  return [`Skipped ${skipped.length} workspace${skipped.length === 1 ? '' : 's'} you belong to:`, ...lines].join('\n');
21
21
  }
22
+ /** "on @account (Workspace)" for a list row, or null when the API sent neither. */
23
+ function ownerLabel(row) {
24
+ const account = typeof row.account_username === 'string' && row.account_username ? `@${row.account_username}` : '';
25
+ const workspace = typeof row.workspace_name === 'string' && row.workspace_name ? row.workspace_name : '';
26
+ if (account && workspace)
27
+ return `on ${account} (${workspace})`;
28
+ if (account || workspace)
29
+ return `on ${account || workspace}`;
30
+ return null;
31
+ }
32
+ /** One list line for a comment: when, account, author ("you" or "(no handle)" when needed), flags, text. */
33
+ export function formatCommentListLine(comment) {
34
+ const author = comment.author_is_business
35
+ ? 'you'
36
+ : typeof comment.author_username === 'string' && comment.author_username
37
+ ? `@${comment.author_username}`
38
+ : '(no handle)';
39
+ const platform = typeof comment.platform === 'string' ? comment.platform : 'unknown';
40
+ const flags = [];
41
+ if (comment.is_read === false)
42
+ flags.push('unread');
43
+ if (comment.is_hidden)
44
+ flags.push('hidden');
45
+ if (comment.is_flagged)
46
+ flags.push('flagged');
47
+ const flagLabel = flags.length > 0 ? `, ${flags.join(', ')}` : '';
48
+ const text = truncateText(typeof comment.content === 'string' ? comment.content : '', 80);
49
+ const replies = Array.isArray(comment.replies) ? comment.replies.length : 0;
50
+ const when = typeof comment.posted_at === 'string' && comment.posted_at ? `[${formatLocalDateTime(comment.posted_at)}]` : null;
51
+ const owner = ownerLabel(comment);
52
+ const context = inboxCommentContext(comment);
53
+ const account = context.accountId ? `account ${context.accountId}` : null;
54
+ const post = context.caption ? `post: ${truncateText(context.caption, 80)}` : context.link ? `post: ${context.link}` : null;
55
+ return `- ${[String(comment.id), when].filter(Boolean).join(' ')} (${[platform, owner, account, author].filter(Boolean).join(', ')}${flagLabel}${replies ? `, ${replies} replies` : ''}): ${text}${post ? ` (${post})` : ''}`;
56
+ }
22
57
  export const listCommentsTool = {
23
58
  name: 'list_comments',
24
- description: 'Social inbox comments and replies for Instagram, Facebook Pages, Threads, and LinkedIn Pages (Pro plan or higher plus posts:read). Without comment_id: list comments filtered by account, platform, unread/flagged, or search, with limit/offset paging. With comment_id: one comment and its replies; only workspace_id may be added.',
59
+ description: 'Social inbox comments and replies for Instagram, Facebook Pages, Threads, and LinkedIn Pages (Pro plan or higher plus posts:read). Without comment_id: list comments filtered by account, platform, unread/flagged, search, or since/until dates, with limit/offset paging. With comment_id: one comment and its replies; only workspace_id may be added. YouTube and TikTok are refused rather than returned as an empty list. They stay off until each platform is reviewed and an inbox provider exists.',
25
60
  inputSchema: z.object({
26
- comment_id: z.string().min(1).optional().describe('One comment (from a list call) with its replies.'),
27
- workspace_id: z.string().optional().describe('Optional. Omit to search every workspace you belong to; pass a workspace ID from whoami to limit to one.'),
28
- account_id: z.number().int().positive().optional().describe('Social account ID from list_accounts.'),
29
- platform: z.enum(INBOX_PLATFORMS).optional().describe('instagram, facebook, threads, or linkedin.'),
30
- filter: z.enum(['all', 'unread', 'flagged']).optional().describe('Comment filter. Defaults to all.'),
61
+ comment_id: z.string().min(1).optional().describe('One comment and its replies.'),
62
+ workspace_id: z.string().optional().describe('Omit to search all your workspaces, or pass an ID from whoami.'),
63
+ account_id: z.number().int().positive().optional().describe('From list_accounts.'),
64
+ platform: z.enum(INBOX_PLATFORMS).optional(),
65
+ filter: z.enum(['all', 'unread', 'flagged']).optional().describe('Default all.'),
31
66
  search: z.string().optional().describe('Search comment content or author username.'),
32
- limit: z.number().int().min(1).max(100).optional().describe('Number of comments to return. Default 50, max 100.'),
33
- offset: z.number().int().min(0).optional().describe('Skip this many comments before returning results.'),
67
+ limit: z.number().int().min(1).max(100).optional().describe('Rows to return. Default 50.'),
68
+ offset: z.number().int().min(0).optional().describe('Rows to skip.'),
69
+ since: z.string().optional().describe('ISO date/time, inclusive.'),
70
+ until: z.string().optional().describe('ISO date/time, inclusive.'),
34
71
  }),
35
72
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
36
73
  legacySchemas: {
@@ -57,19 +94,7 @@ async function commentList(client, input) {
57
94
  }
58
95
  const lines = [`Inbox comments (showing ${result.comments.length} of ${result.total}):`];
59
96
  for (const comment of result.comments) {
60
- const author = typeof comment.author_username === 'string' ? `@${comment.author_username}` : 'unknown';
61
- const platform = typeof comment.platform === 'string' ? comment.platform : 'unknown';
62
- const flags = [];
63
- if (comment.is_read === false)
64
- flags.push('unread');
65
- if (comment.is_hidden)
66
- flags.push('hidden');
67
- if (comment.is_flagged)
68
- flags.push('flagged');
69
- const flagLabel = flags.length > 0 ? `, ${flags.join(', ')}` : '';
70
- const text = truncateText(typeof comment.content === 'string' ? comment.content : '', 80);
71
- const replies = Array.isArray(comment.replies) ? comment.replies.length : 0;
72
- lines.push(`- ${String(comment.id)} (${platform}, ${author}${flagLabel}${replies ? `, ${replies} replies` : ''}): ${text}`);
97
+ lines.push(formatCommentListLine(comment));
73
98
  }
74
99
  if (result.hasMore) {
75
100
  const nextOffset = (input.offset ?? 0) + result.comments.length;
@@ -92,6 +117,13 @@ async function oneComment(client, input) {
92
117
  `• Posted: ${formatLocalDateTime(typeof comment.posted_at === 'string' ? comment.posted_at : null)}`,
93
118
  `• Content: ${typeof comment.content === 'string' ? comment.content : '(empty)'}`,
94
119
  ];
120
+ const context = inboxCommentContext(comment);
121
+ if (context.accountId)
122
+ lines.push(`• Account ID: ${context.accountId}`);
123
+ if (context.caption)
124
+ lines.push(`• Post: ${context.caption}`);
125
+ if (context.link)
126
+ lines.push(`• Post link: ${context.link}`);
95
127
  if (typeof comment.media_permalink === 'string')
96
128
  lines.push(`• Media: ${comment.media_permalink}`);
97
129
  const replies = Array.isArray(comment.replies) ? comment.replies : [];
@@ -5,12 +5,21 @@ type ConversationsInput = {
5
5
  conversation_id?: string;
6
6
  workspace_id?: string;
7
7
  account_id?: number;
8
- platform?: 'instagram' | 'facebook' | 'threads';
8
+ platform?: 'instagram' | 'facebook';
9
9
  filter?: 'all' | 'unread' | 'starred' | 'archived';
10
10
  search?: string;
11
11
  limit?: number;
12
12
  offset?: number;
13
+ since?: string;
14
+ until?: string;
13
15
  };
16
+ /**
17
+ * One list line for a DM conversation: when, account, participant ("(no
18
+ * handle)" when missing), and a preview that starts with "you: " when the
19
+ * business sent the last message and falls back to [media] / [unsupported]
20
+ * when there is no text.
21
+ */
22
+ export declare function formatConversationListLine(conversation: Record<string, unknown>): string;
14
23
  export declare const listConversationsTool: {
15
24
  name: string;
16
25
  description: string;
@@ -18,28 +27,34 @@ export declare const listConversationsTool: {
18
27
  conversation_id: z.ZodOptional<z.ZodString>;
19
28
  workspace_id: z.ZodOptional<z.ZodString>;
20
29
  account_id: z.ZodOptional<z.ZodNumber>;
21
- platform: z.ZodOptional<z.ZodEnum<["instagram", "facebook", "threads"]>>;
30
+ platform: z.ZodOptional<z.ZodEnum<["instagram", "facebook"]>>;
22
31
  filter: z.ZodOptional<z.ZodEnum<["all", "unread", "starred", "archived"]>>;
23
32
  search: z.ZodOptional<z.ZodString>;
24
33
  limit: z.ZodOptional<z.ZodNumber>;
25
34
  offset: z.ZodOptional<z.ZodNumber>;
35
+ since: z.ZodOptional<z.ZodString>;
36
+ until: z.ZodOptional<z.ZodString>;
26
37
  }, "strip", z.ZodTypeAny, {
27
- platform?: "instagram" | "facebook" | "threads" | undefined;
38
+ platform?: "instagram" | "facebook" | undefined;
28
39
  account_id?: number | undefined;
29
40
  workspace_id?: string | undefined;
30
41
  limit?: number | undefined;
31
42
  offset?: number | undefined;
43
+ since?: string | undefined;
32
44
  filter?: "all" | "unread" | "starred" | "archived" | undefined;
33
45
  search?: string | undefined;
46
+ until?: string | undefined;
34
47
  conversation_id?: string | undefined;
35
48
  }, {
36
- platform?: "instagram" | "facebook" | "threads" | undefined;
49
+ platform?: "instagram" | "facebook" | undefined;
37
50
  account_id?: number | undefined;
38
51
  workspace_id?: string | undefined;
39
52
  limit?: number | undefined;
40
53
  offset?: number | undefined;
54
+ since?: string | undefined;
41
55
  filter?: "all" | "unread" | "starred" | "archived" | undefined;
42
56
  search?: string | undefined;
57
+ until?: string | undefined;
43
58
  conversation_id?: string | undefined;
44
59
  }>;
45
60
  /** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */