posterly-mcp-server 0.44.0 → 0.45.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.
- package/README.md +310 -111
- package/dist/index.js +190 -894
- package/dist/lib/alias-transport.d.ts +84 -0
- package/dist/lib/alias-transport.js +193 -0
- package/dist/lib/api-client.d.ts +18 -0
- package/dist/lib/api-client.js +55 -0
- package/dist/lib/preview-token-core.d.ts +62 -0
- package/dist/lib/preview-token-core.js +131 -0
- package/dist/lib/preview-token.d.ts +23 -0
- package/dist/lib/preview-token.js +44 -0
- package/dist/lib/tool-registry.d.ts +246 -0
- package/dist/lib/tool-registry.js +394 -0
- package/dist/lib/tool-runtime.d.ts +68 -0
- package/dist/lib/tool-runtime.js +85 -0
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/tools/audit-google-business-profile.js +1 -1
- package/dist/tools/connect-account.d.ts +4 -4
- package/dist/tools/connect-account.js +2 -2
- package/dist/tools/create-connect-session.d.ts +2 -2
- package/dist/tools/create-connect-session.js +2 -2
- package/dist/tools/create-post.d.ts +6 -6
- package/dist/tools/create-post.js +3 -3
- package/dist/tools/create-posts-batch.d.ts +4 -4
- package/dist/tools/create-webhook.d.ts +2 -2
- package/dist/tools/delete-post.d.ts +34 -10
- package/dist/tools/delete-post.js +52 -16
- package/dist/tools/generate-captions.d.ts +2 -2
- package/dist/tools/generate-image.d.ts +4 -4
- package/dist/tools/generate-image.js +2 -2
- package/dist/tools/generate-video.d.ts +6 -6
- package/dist/tools/generate-video.js +1 -1
- package/dist/tools/get-agent-signup-info.js +2 -2
- package/dist/tools/get-post.d.ts +16 -1
- package/dist/tools/get-post.js +35 -19
- package/dist/tools/list-accounts.d.ts +49 -3
- package/dist/tools/list-accounts.js +148 -33
- package/dist/tools/list-analytics.d.ts +111 -0
- package/dist/tools/list-analytics.js +393 -0
- package/dist/tools/list-brands.d.ts +38 -3
- package/dist/tools/list-brands.js +138 -20
- package/dist/tools/list-comments.d.ts +29 -9
- package/dist/tools/list-comments.js +75 -34
- package/dist/tools/list-conversations.d.ts +32 -9
- package/dist/tools/list-conversations.js +63 -27
- package/dist/tools/list-google-business-media.js +1 -1
- package/dist/tools/list-google-business-reviews.d.ts +32 -9
- package/dist/tools/list-google-business-reviews.js +77 -52
- package/dist/tools/list-jobs.d.ts +60 -0
- package/dist/tools/list-jobs.js +81 -0
- package/dist/tools/list-platforms.d.ts +62 -3
- package/dist/tools/list-platforms.js +118 -9
- package/dist/tools/list-posts.d.ts +2 -2
- package/dist/tools/manage-comment.d.ts +102 -0
- package/dist/tools/manage-comment.js +125 -0
- package/dist/tools/manage-conversation.d.ts +79 -0
- package/dist/tools/manage-conversation.js +75 -0
- package/dist/tools/manage-google-business-media.d.ts +103 -0
- package/dist/tools/manage-google-business-media.js +126 -0
- package/dist/tools/manage-google-business-review.d.ts +146 -0
- package/dist/tools/manage-google-business-review.js +115 -0
- package/dist/tools/manage-oauth-client.d.ts +121 -0
- package/dist/tools/manage-oauth-client.js +94 -0
- package/dist/tools/manage-webhook.d.ts +99 -0
- package/dist/tools/manage-webhook.js +87 -0
- package/dist/tools/start-signup.d.ts +2 -2
- package/dist/tools/submit-agent-feedback.d.ts +4 -4
- package/dist/tools/trigger-platform-helper.d.ts +2 -2
- package/dist/tools/update-post.d.ts +62 -11
- package/dist/tools/update-post.js +79 -26
- package/dist/tools/upload-media.d.ts +32 -9
- package/dist/tools/upload-media.js +54 -18
- package/dist/tools/validate-post.d.ts +4 -4
- package/dist/tools/whoami.d.ts +15 -2
- package/dist/tools/whoami.js +221 -25
- package/package.json +5 -3
- package/scripts/test-alias-transport.mjs +368 -0
- package/scripts/test-client-header-sanitization.mjs +78 -0
- package/scripts/test-tool-annotations.mjs +38 -17
- package/server.json +9 -2
- package/src/index.ts +227 -1443
- package/src/lib/alias-transport.ts +233 -0
- package/src/lib/api-client.ts +65 -0
- package/src/lib/preview-token-core.ts +157 -0
- package/src/lib/preview-token.ts +54 -0
- package/src/lib/tool-registry.ts +538 -0
- package/src/lib/tool-runtime.ts +117 -0
- package/src/lib/version.ts +1 -1
- package/src/tools/audit-google-business-profile.ts +1 -1
- package/src/tools/connect-account.ts +2 -2
- package/src/tools/create-connect-session.ts +2 -2
- package/src/tools/create-post.ts +3 -3
- package/src/tools/delete-post.ts +60 -19
- package/src/tools/generate-image.ts +2 -2
- package/src/tools/generate-video.ts +1 -1
- package/src/tools/get-agent-signup-info.ts +2 -2
- package/src/tools/get-post.ts +35 -21
- package/src/tools/list-accounts.ts +187 -39
- package/src/tools/list-analytics.ts +444 -0
- package/src/tools/list-brands.ts +162 -26
- package/src/tools/list-comments.ts +86 -43
- package/src/tools/list-conversations.ts +81 -39
- package/src/tools/list-google-business-media.ts +1 -1
- package/src/tools/list-google-business-reviews.ts +93 -64
- package/src/tools/list-jobs.ts +91 -0
- package/src/tools/list-platforms.ts +135 -11
- package/src/tools/manage-comment.ts +142 -0
- package/src/tools/manage-conversation.ts +89 -0
- package/src/tools/manage-google-business-media.ts +147 -0
- package/src/tools/manage-google-business-review.ts +139 -0
- package/src/tools/manage-oauth-client.ts +116 -0
- package/src/tools/manage-webhook.ts +103 -0
- package/src/tools/update-post.ts +106 -39
- package/src/tools/upload-media.ts +76 -28
- package/src/tools/whoami.ts +253 -30
- package/tool-annotations.json +76 -149
- package/tool-registry.json +2085 -0
- package/src/tools/add-google-business-media.ts +0 -50
- package/src/tools/create-oauth-client.ts +0 -36
- package/src/tools/delete-comment.ts +0 -29
- package/src/tools/delete-google-business-media.ts +0 -30
- package/src/tools/delete-google-business-review-reply.ts +0 -30
- package/src/tools/delete-oauth-client.ts +0 -23
- package/src/tools/delete-post-group.ts +0 -17
- package/src/tools/delete-webhook.ts +0 -17
- package/src/tools/get-account-analytics.ts +0 -171
- package/src/tools/get-brand-profile.ts +0 -86
- package/src/tools/get-brand.ts +0 -34
- package/src/tools/get-comment.ts +0 -47
- package/src/tools/get-connect-link.ts +0 -61
- package/src/tools/get-connect-session.ts +0 -63
- package/src/tools/get-conversation.ts +0 -44
- package/src/tools/get-google-business-review-link.ts +0 -30
- package/src/tools/get-image-job.ts +0 -36
- package/src/tools/get-learned-voice.ts +0 -31
- package/src/tools/get-mcp-status.ts +0 -212
- package/src/tools/get-performance-profile.ts +0 -47
- package/src/tools/get-platform-schema.ts +0 -56
- package/src/tools/get-post-analytics.ts +0 -243
- package/src/tools/get-post-insights.ts +0 -60
- package/src/tools/get-post-missing.ts +0 -16
- package/src/tools/get-video-job.ts +0 -36
- package/src/tools/list-brand-accounts.ts +0 -36
- package/src/tools/reply-google-business-review.ts +0 -32
- package/src/tools/reply-to-comment.ts +0 -30
- package/src/tools/send-message.ts +0 -28
- package/src/tools/suggest-google-business-review-reply.ts +0 -44
- package/src/tools/sync-inbox.ts +0 -28
- package/src/tools/test-webhook.ts +0 -18
- package/src/tools/update-comment.ts +0 -31
- package/src/tools/update-oauth-client.ts +0 -38
- package/src/tools/update-post-release-id.ts +0 -25
- package/src/tools/update-post-status.ts +0 -31
- package/src/tools/update-webhook.ts +0 -36
- package/src/tools/upload-media-from-url.ts +0 -33
|
@@ -31,7 +31,7 @@ const PLATFORM_CREDENTIAL_FIELDS: Record<string, string[]> = {
|
|
|
31
31
|
export const connectAccountTool = {
|
|
32
32
|
name: 'connect_account',
|
|
33
33
|
description:
|
|
34
|
-
'Connect a credential-based social account (telegram, bluesky, discord, wordpress, devto, hashnode, lemmy) directly, without a browser session. Call
|
|
34
|
+
'Connect a credential-based social account (telegram, bluesky, discord, wordpress, devto, hashnode, lemmy) directly, without a browser session. Call list_platforms with view=connect_link first to discover the exact credential fields the platform needs. Prefer scoped secrets: app passwords (Bluesky, WordPress), bot tokens (Telegram), webhook URLs (Discord), and API tokens (Dev.to, Hashnode) over primary passwords. Warn the user that any credential they share passes through this conversation. For OAuth platforms (Instagram, X, LinkedIn, ...) use create_connect_session instead.',
|
|
35
35
|
inputSchema: z.object({
|
|
36
36
|
platform: z
|
|
37
37
|
.enum(CREDENTIAL_PLATFORMS)
|
|
@@ -70,7 +70,7 @@ export const connectAccountTool = {
|
|
|
70
70
|
|
|
71
71
|
const missing = allowedFields.filter((field) => !(field in credentials));
|
|
72
72
|
if (missing.length > 0) {
|
|
73
|
-
return `Missing credential field(s) for ${input.platform}: ${missing.join(', ')}. Call
|
|
73
|
+
return `Missing credential field(s) for ${input.platform}: ${missing.join(', ')}. Call list_platforms with view=connect_link and target=${input.platform} to see field descriptions.`;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const result = await client.connectAccountCredentials({
|
|
@@ -6,7 +6,7 @@ import { CONNECT_INPUTS } from '../generated/platform-manifest.js';
|
|
|
6
6
|
export const createConnectSessionTool = {
|
|
7
7
|
name: 'create_connect_session',
|
|
8
8
|
description:
|
|
9
|
-
'Create a short-lived posterly dashboard handoff session for connecting a social account. Send the secure connection URL to the user, then poll
|
|
9
|
+
'Create a short-lived posterly dashboard handoff session for connecting a social account. Send the secure connection URL to the user, then poll list_accounts with view=connect_session to narrate progress. Do not ask for social media passwords or OAuth codes; posterly handles those browser steps.',
|
|
10
10
|
inputSchema: z.object({
|
|
11
11
|
platform: z
|
|
12
12
|
.enum(CONNECT_INPUTS)
|
|
@@ -49,7 +49,7 @@ function formatConnectSession(session: ConnectSession, includeRaw: boolean): str
|
|
|
49
49
|
`Expires: ${formatLocalDateTime(session.expires_at)}`,
|
|
50
50
|
`Dashboard connect page: ${DASHBOARD_CONNECT_URL}`,
|
|
51
51
|
'',
|
|
52
|
-
'Next step for the AI agent: send the secure connection URL to the user, explain that posterly will handle the browser OAuth step, then poll
|
|
52
|
+
'Next step for the AI agent: send the secure connection URL to the user, explain that posterly will handle the browser OAuth step, then poll list_accounts with view=connect_session until the account is connected or the session ends.',
|
|
53
53
|
includeRaw ? `\nRaw connect session:\n${JSON.stringify(session, null, 2)}` : '',
|
|
54
54
|
].filter(Boolean).join('\n');
|
|
55
55
|
}
|
package/src/tools/create-post.ts
CHANGED
|
@@ -156,7 +156,7 @@ export const createPostPayloadInputSchema = z.object({
|
|
|
156
156
|
.describe('For X or Threads only: array of 2+ strings, one per post in the thread. The first entry leads, the rest reply in order. When set, the platform must be twitter or threads.'),
|
|
157
157
|
instagram_settings: instagramSettingsSchema
|
|
158
158
|
.optional()
|
|
159
|
-
.describe('Instagram-specific settings. If “tag” is ambiguous, distinguish caption @mentions (put @username in caption), native media tags (user_tags), and co-author invitations (collaborators). Native media tags work with eligible direct or Meta-linked accounts; collaborators require an eligible Meta-linked account. Call
|
|
159
|
+
.describe('Instagram-specific settings. If “tag” is ambiguous, distinguish caption @mentions (put @username in caption), native media tags (user_tags), and co-author invitations (collaborators). Native media tags work with eligible direct or Meta-linked accounts; collaborators require an eligible Meta-linked account. Call list_platforms with view=schema and account_id first.'),
|
|
160
160
|
platform_settings: platformSettingsSchema
|
|
161
161
|
.optional()
|
|
162
162
|
.describe('Platform-specific settings for the selected account. Use this for non-Instagram settings and prefer it over raw metadata.'),
|
|
@@ -237,9 +237,9 @@ export const createPostTool = {
|
|
|
237
237
|
'4. If scheduling multiple posts in one turn, list every post first and confirm the batch as a whole, then prefer `create_posts_batch` so they are created in one API request.\n\n' +
|
|
238
238
|
'AFTER CALLING: Tell the user the post was created, include the posterly dashboard link returned by the tool, and offer the next natural action. Do not narrate raw HTTP, curl, or API plumbing.\n\n' +
|
|
239
239
|
'Provide either account_id OR username+platform to identify the account. If scheduled_at is omitted, the post publishes immediately. If workspace_id is omitted, the server resolves one from the social account, falling back to the caller\'s default (personal) workspace - pass workspace_id explicitly if the user has more than one workspace.\n\n' +
|
|
240
|
-
'MEDIA URLS: Posterly storage URLs are used as-is. Third-party HTTP(S) media URLs are copied into posterly storage before the post is saved, so API-created posts do not later fail on expired signed URLs. Short-lived signed URLs must still be live when this tool runs. You can also call `
|
|
240
|
+
'MEDIA URLS: Posterly storage URLs are used as-is. Third-party HTTP(S) media URLs are copied into posterly storage before the post is saved, so API-created posts do not later fail on expired signed URLs. Short-lived signed URLs must still be live when this tool runs. You can also call `upload_media` with `url` first if you want to upload once and reuse the returned posterly URL across posts.\n\n' +
|
|
241
241
|
'THREADS: Pass `thread_posts` (an array of 2+ strings) to schedule a multi-post thread on X (Twitter) or Threads (Meta). The first entry is the lead post; the rest are published as replies in the same chain. X entries are capped at 280 characters each (4000 for verified, 25000 for organization accounts); Threads entries are capped at 500 characters each. When `thread_posts` is set, `caption` is ignored.\n\n' +
|
|
242
|
-
'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `
|
|
242
|
+
'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `list_platforms` with `view: "schema"` and the account ID first. `instagram_settings` remains as a backwards-compatible alias.\n\n' +
|
|
243
243
|
'TIKTOK MEDIA: TikTok supports a single video or a photo slideshow of 1 to 35 images, never multiple videos. Image media auto-detects as a slideshow, so you usually do not set post_type or media_type for photos and every image is posted. Pass `platform_settings.media_type: "PHOTO"` to force a slideshow explicitly.',
|
|
244
244
|
inputSchema: createPostInputSchema,
|
|
245
245
|
|
package/src/tools/delete-post.ts
CHANGED
|
@@ -1,31 +1,72 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
|
-
import { dashboardUrlForPosts } from '../lib/format.js';
|
|
3
|
+
import { code, dashboardUrlForPosts } from '../lib/format.js';
|
|
4
|
+
import { previewThenConfirm, validateArgs, type ToolContext } from '../lib/tool-runtime.js';
|
|
5
|
+
|
|
6
|
+
type DeletePostInput = {
|
|
7
|
+
post_id?: number;
|
|
8
|
+
group_id?: string;
|
|
9
|
+
confirm?: boolean;
|
|
10
|
+
preview_id?: string;
|
|
11
|
+
};
|
|
4
12
|
|
|
5
13
|
export const deletePostTool = {
|
|
6
14
|
name: 'delete_post',
|
|
7
15
|
description:
|
|
8
|
-
'Delete
|
|
9
|
-
'REQUIRED BEFORE CALLING: Fetch the post with `get_post` first and show the user what will be deleted (caption, account, scheduled time). Get explicit confirmation ("yes delete it", "remove it") before calling. Never delete multiple posts in a single batch without listing each one and confirming the full list.',
|
|
16
|
+
'Delete posts. DESTRUCTIVE and IRREVERSIBLE: deleted posts and captions cannot be recovered, and published or currently publishing posts are never deleted. post_id: delete one scheduled or draft post; fetch it with `get_post` first, show the user what will be deleted (caption, account, scheduled time), and pass confirm=true only after explicit confirmation ("yes delete it", "remove it"). group_id: delete every draft, scheduled, failed, or paused post matching a caller-defined group_id, post_group_id, api_group_id, or release_id; preview then confirm: call without confirm to get a preview and preview_id, show it, then call again with confirm=true and that preview_id. Never delete several posts one by one without listing each and confirming the full list.',
|
|
10
17
|
inputSchema: z.object({
|
|
11
|
-
post_id: z.number().describe('
|
|
12
|
-
|
|
18
|
+
post_id: z.number().optional().describe('Delete this one post.'),
|
|
19
|
+
group_id: z.string().min(1).max(160).optional().describe('Delete every unpublished post in this group or release instead.'),
|
|
20
|
+
confirm: z
|
|
21
|
+
.boolean()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('post_id: true after explicit user confirmation of the deletion. group_id: leave out to get a preview; true only with the preview_id after the user approved it.'),
|
|
24
|
+
preview_id: z.string().optional().describe('group_id: the preview_id from the preview call. Required with confirm: true.'),
|
|
13
25
|
}),
|
|
26
|
+
/** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
|
|
27
|
+
legacySchemas: {
|
|
28
|
+
delete_post_group: z.object({
|
|
29
|
+
group_id: z.string().min(1).max(160),
|
|
30
|
+
confirm: z.literal(true),
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
14
33
|
|
|
15
|
-
async execute(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
async execute(client: PosterlyClient, input: DeletePostInput, ctx: ToolContext) {
|
|
35
|
+
const { mode, args } = validateArgs(ctx, 'delete_post', input);
|
|
36
|
+
if (mode === 'group') {
|
|
37
|
+
return previewThenConfirm({
|
|
38
|
+
tool: 'delete_post',
|
|
39
|
+
action: 'group',
|
|
40
|
+
args,
|
|
41
|
+
nonce: false,
|
|
42
|
+
legacyRefusal: 'Refusing to delete post group without confirm=true after explicit user confirmation.',
|
|
43
|
+
ctx,
|
|
44
|
+
// GET /api/v1/posts has no group filter, so the preview says in plain
|
|
45
|
+
// words which posts match instead of listing them.
|
|
46
|
+
describe: async () => [
|
|
47
|
+
`Deletes every draft, scheduled, failed, or paused post whose group_id, post_group_id, api_group_id, or release_id is ${code(args.group_id)}. Published posts are never deleted. This cannot be undone.`,
|
|
48
|
+
'To see the posts first, call list_posts and check each post\'s group or release ID.',
|
|
49
|
+
].join('\n\n'),
|
|
50
|
+
run: async () => {
|
|
51
|
+
const result = await client.deletePostGroup(args.group_id);
|
|
52
|
+
return JSON.stringify(result, null, 2);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
21
55
|
}
|
|
22
|
-
|
|
23
|
-
return [
|
|
24
|
-
`Post #${result.id} deleted successfully.`,
|
|
25
|
-
'It has been removed from the posterly queue.',
|
|
26
|
-
`View queue in posterly: ${dashboardUrlForPosts()}`,
|
|
27
|
-
'',
|
|
28
|
-
'Next step for the AI agent: tell the user the post is gone and offer to create, reschedule, or review the next post.',
|
|
29
|
-
].join('\n');
|
|
56
|
+
return deleteOne(client, args as { post_id: number; confirm?: boolean });
|
|
30
57
|
},
|
|
31
58
|
};
|
|
59
|
+
|
|
60
|
+
async function deleteOne(client: PosterlyClient, input: { post_id: number; confirm?: boolean }): Promise<string> {
|
|
61
|
+
if (input.confirm !== true) {
|
|
62
|
+
throw new Error('Refusing to delete post without confirm=true after explicit user confirmation.');
|
|
63
|
+
}
|
|
64
|
+
const result = await client.deletePost(input.post_id);
|
|
65
|
+
return [
|
|
66
|
+
`Post #${result.id} deleted successfully.`,
|
|
67
|
+
'It has been removed from the posterly queue.',
|
|
68
|
+
`View queue in posterly: ${dashboardUrlForPosts()}`,
|
|
69
|
+
'',
|
|
70
|
+
'Next step for the AI agent: tell the user the post is gone and offer to create, reschedule, or review the next post.',
|
|
71
|
+
].join('\n');
|
|
72
|
+
}
|
|
@@ -5,7 +5,7 @@ import { mdKeyValue, mdTitle } from '../lib/format.js';
|
|
|
5
5
|
export const generateImageTool = {
|
|
6
6
|
name: 'generate_image',
|
|
7
7
|
description:
|
|
8
|
-
'Queue an AI image job via posterly using Nano Banana (Gemini) or Grok Imagine Image 2.0 (xAI). Returns job_id. Poll
|
|
8
|
+
'Queue an AI image job via posterly using Nano Banana (Gemini) or Grok Imagine Image 2.0 (xAI). Returns job_id. Poll list_jobs with type=image until status is completed, then pass urls to create_post as media_url / media_urls. Gemini thinking high does not change the credit price.\n\n' +
|
|
9
9
|
'COSTS CREDITS. Every call consumes part of the user\'s monthly AI image quota (or purchased credits once the quota is exhausted). Do NOT call speculatively - always describe the image you\'re about to generate (subject, style, aspect ratio, quality/thinking, resolution) to the user and get confirmation before calling.\n\n' +
|
|
10
10
|
'If the user is over their plan limit and has no credits, this tool returns a 402 with upgrade info. Surface that message verbatim - do not retry.\n\n' +
|
|
11
11
|
'Common aspect ratios by platform:\n' +
|
|
@@ -100,7 +100,7 @@ export const generateImageTool = {
|
|
|
100
100
|
['Credits used', result.credits_used],
|
|
101
101
|
['Billed from', result.usage?.billed_from],
|
|
102
102
|
]),
|
|
103
|
-
result.message || 'Poll
|
|
103
|
+
result.message || 'Poll list_jobs with type=image and this job_id until status is completed, then pass urls to create_post.',
|
|
104
104
|
].filter(Boolean).join('\n\n');
|
|
105
105
|
},
|
|
106
106
|
};
|
|
@@ -4,7 +4,7 @@ import type { PosterlyClient } from '../lib/api-client.js';
|
|
|
4
4
|
export const generateVideoTool = {
|
|
5
5
|
name: 'generate_video',
|
|
6
6
|
description:
|
|
7
|
-
'Queue an AI video generation job with Google Veo 3.1 or xAI Grok Imagine Video 1.5. COSTS CREDITS: confirm provider, prompt, duration, resolution, aspect ratio, audio choice, and credit cost with the user before calling. Grok supports 1
|
|
7
|
+
'Queue an AI video generation job with Google Veo 3.1 or xAI Grok Imagine Video 1.5. COSTS CREDITS: confirm provider, prompt, duration, resolution, aspect ratio, audio choice, and credit cost with the user before calling. Grok supports 1 to 15 seconds and 480p to 1080p; reference-to-video is capped at 720p. Poll list_jobs with type=video for status and final video_url.',
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
provider: z.enum(['google', 'xai']).default('google').optional(),
|
|
10
10
|
prompt: z.string().min(5).max(4000),
|
|
@@ -18,14 +18,14 @@ export const getAgentSignupInfoTool = {
|
|
|
18
18
|
authState,
|
|
19
19
|
'',
|
|
20
20
|
'Pre-auth tools:',
|
|
21
|
-
'-
|
|
21
|
+
'- whoami with view=status: checks the installed server version, latest npm version, MCP endpoint health, API auth health, and whether POSTERLY_API_KEY is configured.',
|
|
22
22
|
'- start_signup: starts paid signup and returns a signup poll URL, a browser Checkout fallback, and, when enabled, a prepaid PaymentIntent for a Link virtual card (credential_type: card).',
|
|
23
23
|
'- get_signup_session: polls payment, password, and agent-access status.',
|
|
24
24
|
'',
|
|
25
25
|
'After posterly access is installed, onboard the user IN THIS chat (do not send them to /onboarding-v2):',
|
|
26
26
|
'- whoami: confirm the paid account and read onboarding.next_step.',
|
|
27
27
|
'- About you: confirm name and IANA timezone.',
|
|
28
|
-
'- create_connect_session
|
|
28
|
+
'- create_connect_session, then list_accounts with view=connect_session: first social account in the browser.',
|
|
29
29
|
'- Brand voice: ask how they want to sound, then use that on captions.',
|
|
30
30
|
'- create_post: first scheduled post after validate_post and explicit confirm.',
|
|
31
31
|
'',
|
package/src/tools/get-post.ts
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
3
|
import { dashboardUrlForPost, formatLocalDateTime } from '../lib/format.js';
|
|
4
|
+
import { validateArgs, type ToolContext } from '../lib/tool-runtime.js';
|
|
4
5
|
|
|
5
6
|
export const getPostTool = {
|
|
6
7
|
name: 'get_post',
|
|
7
8
|
description:
|
|
8
|
-
'
|
|
9
|
+
'One post by ID. view=post (default): caption, status, scheduled time, media, and platform info. view=missing: whether the post is missing required content, media, account, platform settings, or metadata before it can publish; use it to repair failed or imported posts.',
|
|
9
10
|
inputSchema: z.object({
|
|
10
11
|
post_id: z.number().describe('The post ID to look up'),
|
|
12
|
+
view: z.enum(['post', 'missing']).optional().describe('post (default) or missing.'),
|
|
11
13
|
}),
|
|
14
|
+
/** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
|
|
15
|
+
legacySchemas: {
|
|
16
|
+
get_post_missing: z.object({ post_id: z.number().int().positive() }),
|
|
17
|
+
},
|
|
12
18
|
|
|
13
|
-
async execute(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
async execute(client: PosterlyClient, input: { post_id: number; view?: 'post' | 'missing' }, ctx: ToolContext) {
|
|
20
|
+
const { mode, args } = validateArgs(ctx, 'get_post', input);
|
|
21
|
+
if (mode === 'missing') return postMissing(client, args as { post_id: number });
|
|
22
|
+
return post(client, args as { post_id: number });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`• Caption: ${p.content || '(empty)'}`,
|
|
24
|
-
`• Type: ${p.post_type || 'unknown'}`,
|
|
25
|
-
`• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`,
|
|
26
|
-
`• View in posterly: ${dashboardUrlForPost({ id: p.id, scheduled_at: p.scheduled_at })}`,
|
|
27
|
-
];
|
|
26
|
+
async function post(client: PosterlyClient, input: { post_id: number }): Promise<string> {
|
|
27
|
+
const result = await client.getPost(input.post_id);
|
|
28
|
+
const p = result.post as Record<string, any>;
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const lines = [
|
|
31
|
+
`Post #${p.id}`,
|
|
32
|
+
`• Status: ${p.status}`,
|
|
33
|
+
`• Caption: ${p.content || '(empty)'}`,
|
|
34
|
+
`• Type: ${p.post_type || 'unknown'}`,
|
|
35
|
+
`• Scheduled: ${formatLocalDateTime(p.scheduled_at)}`,
|
|
36
|
+
`• View in posterly: ${dashboardUrlForPost({ id: p.id, scheduled_at: p.scheduled_at })}`,
|
|
37
|
+
];
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
};
|
|
39
|
+
if (p.platform_post_url) lines.push(`• Published URL: ${p.platform_post_url}`);
|
|
40
|
+
if (p.media_url) lines.push(`• Media: ${p.media_url}`);
|
|
41
|
+
if (p.media_urls?.length) lines.push(`• Media (${p.media_urls.length}): ${p.media_urls.join(', ')}`);
|
|
42
|
+
|
|
43
|
+
return lines.join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function postMissing(client: PosterlyClient, input: { post_id: number }): Promise<string> {
|
|
47
|
+
const result = await client.getPostMissing(input.post_id);
|
|
48
|
+
return JSON.stringify(result, null, 2);
|
|
49
|
+
}
|
|
@@ -1,54 +1,202 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
|
-
import {
|
|
2
|
+
import type { ConnectSession, PosterlyClient } from '../lib/api-client.js';
|
|
3
|
+
import {
|
|
4
|
+
DASHBOARD_CONNECT_URL,
|
|
5
|
+
code,
|
|
6
|
+
formatConnectedAccounts,
|
|
7
|
+
formatDateTime,
|
|
8
|
+
formatLocalDateTime,
|
|
9
|
+
formatPercent,
|
|
10
|
+
mdBullets,
|
|
11
|
+
mdEmpty,
|
|
12
|
+
mdKeyValue,
|
|
13
|
+
mdLearnedVoice,
|
|
14
|
+
mdQuote,
|
|
15
|
+
mdSection,
|
|
16
|
+
mdTable,
|
|
17
|
+
mdTitle,
|
|
18
|
+
} from '../lib/format.js';
|
|
19
|
+
import { validateArgs, type ToolContext } from '../lib/tool-runtime.js';
|
|
20
|
+
|
|
21
|
+
type ListAccountsInput = {
|
|
22
|
+
view?: 'accounts' | 'learned_voice' | 'performance_profile' | 'connect_session';
|
|
23
|
+
workspace_id?: string;
|
|
24
|
+
account_id?: string | number;
|
|
25
|
+
session_id?: string;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
};
|
|
4
28
|
|
|
5
29
|
export const listAccountsTool = {
|
|
6
30
|
name: 'list_accounts',
|
|
7
31
|
description:
|
|
8
|
-
|
|
32
|
+
"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.",
|
|
9
33
|
inputSchema: z.object({
|
|
34
|
+
view: z
|
|
35
|
+
.enum(['accounts', 'learned_voice', 'performance_profile', 'connect_session'])
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('accounts (default), learned_voice, performance_profile, or connect_session.'),
|
|
10
38
|
workspace_id: z
|
|
11
39
|
.string()
|
|
12
40
|
.optional()
|
|
13
|
-
.describe('
|
|
41
|
+
.describe('view=accounts: filter to accounts in a specific workspace (get IDs via whoami).'),
|
|
42
|
+
account_id: z
|
|
43
|
+
.union([z.string(), z.number()])
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('Social account ID from list_accounts. Required for learned_voice and performance_profile; with view=accounts it returns just that account.'),
|
|
46
|
+
session_id: z.string().optional().describe('view=connect_session: connect session ID returned by create_connect_session.'),
|
|
47
|
+
debug: z
|
|
48
|
+
.boolean()
|
|
49
|
+
.optional()
|
|
50
|
+
.describe('view=connect_session: when true, include the raw connect session JSON for debugging. Keep false for normal user-facing agent flows.'),
|
|
14
51
|
}),
|
|
52
|
+
/** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
|
|
53
|
+
legacySchemas: {
|
|
54
|
+
get_learned_voice: z.object({ account_id: z.union([z.string(), z.number()]) }),
|
|
55
|
+
get_performance_profile: z.object({ account_id: z.union([z.string(), z.number()]) }),
|
|
56
|
+
get_connect_session: z.object({ session_id: z.string(), debug: z.boolean().optional() }),
|
|
57
|
+
},
|
|
15
58
|
|
|
16
|
-
async execute(client: PosterlyClient, input:
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
59
|
+
async execute(client: PosterlyClient, input: ListAccountsInput, ctx: ToolContext) {
|
|
60
|
+
const { mode, args } = validateArgs(ctx, 'list_accounts', input);
|
|
61
|
+
if (mode === 'learned_voice') return learnedVoice(client, args as { account_id: string | number });
|
|
62
|
+
if (mode === 'performance_profile') return performanceProfile(client, args as { account_id: string | number });
|
|
63
|
+
if (mode === 'connect_session') {
|
|
64
|
+
const result = await client.getConnectSession(args.session_id);
|
|
65
|
+
return formatConnectSession(result.connect_session, Boolean(args.debug));
|
|
23
66
|
}
|
|
67
|
+
return accountsList(client, args as ListAccountsInput);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
24
70
|
|
|
25
|
-
|
|
71
|
+
async function accountsList(client: PosterlyClient, input: ListAccountsInput): Promise<string> {
|
|
72
|
+
const listed = await client.listAccounts({ workspace_id: input.workspace_id });
|
|
73
|
+
// There is no GET /accounts/:id, so account_id filters the list here.
|
|
74
|
+
const accounts = input.account_id !== undefined
|
|
75
|
+
? listed.filter((account) => String(account.id) === String(input.account_id))
|
|
76
|
+
: listed;
|
|
26
77
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
account.instagram_tagging?.media_user_tags?.supported ? 'yes' : 'no',
|
|
43
|
-
account.instagram_tagging?.collaborators?.supported ? 'yes' : 'no',
|
|
44
|
-
]
|
|
45
|
-
: ['—', '—', '—']
|
|
46
|
-
: []),
|
|
47
|
-
]),
|
|
48
|
-
),
|
|
78
|
+
if (input.account_id !== undefined && accounts.length === 0) {
|
|
79
|
+
return mdEmpty('connected account', `No connected account has the ID ${String(input.account_id)}.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (accounts.length === 0) {
|
|
83
|
+
return input.workspace_id
|
|
84
|
+
? mdEmpty('connected accounts', 'This workspace does not have any social accounts connected yet.')
|
|
85
|
+
: mdEmpty('connected accounts', 'posterly does not see any connected social accounts yet.', 'Connect accounts in the posterly dashboard, then run this again.');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const hasInstagram = accounts.some((account) => account.platform === 'instagram');
|
|
89
|
+
|
|
90
|
+
return [
|
|
91
|
+
mdTitle(`Connected accounts (${accounts.length})`),
|
|
92
|
+
mdTable(
|
|
49
93
|
hasInstagram
|
|
50
|
-
? '
|
|
51
|
-
: '',
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
94
|
+
? ['Platform', 'Account', 'Account ID', 'Workspace', 'Connection', 'Native tags', 'Collaborators']
|
|
95
|
+
: ['Platform', 'Account', 'Account ID', 'Workspace'],
|
|
96
|
+
accounts.map((account) => [
|
|
97
|
+
account.platform,
|
|
98
|
+
`@${account.username}`,
|
|
99
|
+
code(account.id),
|
|
100
|
+
account.workspace_id ? code(account.workspace_id) : 'default',
|
|
101
|
+
...(hasInstagram
|
|
102
|
+
? account.platform === 'instagram'
|
|
103
|
+
? [
|
|
104
|
+
account.connection_mode === 'meta' ? 'Meta-linked' : account.connection_mode === 'instagram_direct' ? 'Direct login' : 'unknown',
|
|
105
|
+
account.instagram_tagging?.media_user_tags?.supported ? 'yes' : 'no',
|
|
106
|
+
account.instagram_tagging?.collaborators?.supported ? 'yes' : 'no',
|
|
107
|
+
]
|
|
108
|
+
: ['n/a', 'n/a', 'n/a']
|
|
109
|
+
: []),
|
|
110
|
+
]),
|
|
111
|
+
),
|
|
112
|
+
hasInstagram
|
|
113
|
+
? '_Instagram caption @mentions use @username in caption text. Native media tags work with eligible direct or Meta-linked accounts; collaborator invitations require an eligible Meta-linked account._'
|
|
114
|
+
: '',
|
|
115
|
+
].filter(Boolean).join('\n\n');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function learnedVoice(client: PosterlyClient, input: { account_id: string | number }): Promise<string> {
|
|
119
|
+
const { learned_voice } = await client.getAccountLearnedVoice(input.account_id);
|
|
120
|
+
|
|
121
|
+
const body = mdLearnedVoice(learned_voice);
|
|
122
|
+
if (!body) {
|
|
123
|
+
return [
|
|
124
|
+
mdTitle('No learned voice yet'),
|
|
125
|
+
'posterly has not learned a voice for this account yet. It learns automatically once the account has enough published posts (the captions are analyzed; the saved brand profile is never overwritten).',
|
|
126
|
+
].join('\n\n');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return [mdTitle('Learned voice (from published captions)'), body].join('\n\n');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function performanceProfile(client: PosterlyClient, input: { account_id: string | number }): Promise<string> {
|
|
133
|
+
const { performance_profile, reason } = await client.getAccountPerformanceProfile(input.account_id);
|
|
134
|
+
|
|
135
|
+
if (!performance_profile) {
|
|
136
|
+
const detail = reason === 'platform_not_measurable'
|
|
137
|
+
? 'This platform does not produce per-post analytics, so posterly cannot build a performance profile for it.'
|
|
138
|
+
: reason === 'feature_not_available'
|
|
139
|
+
? 'Performance profiles require a Pro plan or higher.'
|
|
140
|
+
: 'posterly has not built a performance profile for this account yet. It needs about 90 days of tracked posts to learn from.';
|
|
141
|
+
return mdEmpty('performance profile yet', detail);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const label = performance_profile.username
|
|
145
|
+
? `@${performance_profile.username}${performance_profile.platform ? ` (${performance_profile.platform})` : ''}`
|
|
146
|
+
: `account ${performance_profile.social_account_id}`;
|
|
147
|
+
|
|
148
|
+
const rate = performance_profile.engagement_rate_avg != null
|
|
149
|
+
? formatPercent(performance_profile.engagement_rate_avg * 100)
|
|
150
|
+
: 'n/a';
|
|
151
|
+
|
|
152
|
+
return [
|
|
153
|
+
mdTitle('Account performance profile', `${label} · last ${performance_profile.window_days ?? 90} days`),
|
|
154
|
+
performance_profile.narrative_summary ? mdSection('Summary', mdQuote(performance_profile.narrative_summary)) : '',
|
|
155
|
+
performance_profile.bullets.length ? mdSection('What is working', mdBullets(performance_profile.bullets)) : '',
|
|
156
|
+
mdSection('Stats', mdKeyValue([
|
|
157
|
+
['Posts sampled', performance_profile.sample_size],
|
|
158
|
+
['Avg engagement rate', rate],
|
|
159
|
+
['Engagement trend', performance_profile.engagement_rate_trend],
|
|
160
|
+
['Derived at', formatDateTime(performance_profile.derived_at)],
|
|
161
|
+
])),
|
|
162
|
+
].filter(Boolean).join('\n\n');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function formatConnectSession(session: ConnectSession, includeRaw: boolean): string {
|
|
166
|
+
const connected = session.connected_count ?? session.connected_accounts?.length ?? 0;
|
|
167
|
+
return [
|
|
168
|
+
`posterly connect session: ${session.id}`,
|
|
169
|
+
`Platform: ${session.platform}`,
|
|
170
|
+
`Status: ${session.status}`,
|
|
171
|
+
`Message: ${session.status_message}`,
|
|
172
|
+
`Connected accounts: ${connected}`,
|
|
173
|
+
`Accounts: ${formatConnectedAccounts(session.connected_accounts)}`,
|
|
174
|
+
session.error_message ? `Error: ${session.error_message}` : '',
|
|
175
|
+
`Expires: ${formatLocalDateTime(session.expires_at)}`,
|
|
176
|
+
`Dashboard connect page: ${DASHBOARD_CONNECT_URL}`,
|
|
177
|
+
'',
|
|
178
|
+
guidanceForStatus(session),
|
|
179
|
+
includeRaw ? `\nRaw connect session:\n${JSON.stringify(session, null, 2)}` : '',
|
|
180
|
+
].filter(Boolean).join('\n');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function guidanceForStatus(session: ConnectSession): string {
|
|
184
|
+
switch (session.status) {
|
|
185
|
+
case 'created':
|
|
186
|
+
case 'opened':
|
|
187
|
+
case 'awaiting_provider':
|
|
188
|
+
return 'Next step for the AI agent: tell the user posterly is waiting for browser approval, then keep polling this session. Do not ask for social passwords or OAuth codes.';
|
|
189
|
+
case 'awaiting_credentials':
|
|
190
|
+
return 'Next step for the AI agent: tell the user posterly needs them to finish the browser credential step, then keep polling. Do not ask the user to paste credentials into chat.';
|
|
191
|
+
case 'connected':
|
|
192
|
+
return `Next step for the AI agent: tell the user ${formatConnectedAccounts(session.connected_accounts)} is connected, then ask what they want to schedule first or offer to create a test post.`;
|
|
193
|
+
case 'failed':
|
|
194
|
+
return 'Next step for the AI agent: tell the user the connection failed, share the error if present, and offer to create a fresh connect session.';
|
|
195
|
+
case 'cancelled':
|
|
196
|
+
return 'Next step for the AI agent: tell the user the connection was cancelled and offer to create a fresh connect session when they are ready.';
|
|
197
|
+
case 'expired':
|
|
198
|
+
return 'Next step for the AI agent: tell the user the connection link expired and create a fresh connect session if they still want to connect this account.';
|
|
199
|
+
default:
|
|
200
|
+
return 'Next step for the AI agent: explain the current connection status in plain language and keep polling unless the session is terminal.';
|
|
201
|
+
}
|
|
202
|
+
}
|