postfast-mcp 0.13.1 → 0.15.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 (53) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +16 -0
  4. package/dist/core/app.d.ts +0 -8
  5. package/dist/core/app.js +1 -25
  6. package/dist/core/app.js.map +1 -1
  7. package/dist/core/backend-port.d.ts +40 -1
  8. package/dist/core/build-tools.d.ts +26 -11
  9. package/dist/core/build-tools.js +73 -16
  10. package/dist/core/build-tools.js.map +1 -1
  11. package/dist/core/confirm-token.d.ts +12 -6
  12. package/dist/core/confirm-token.js +24 -9
  13. package/dist/core/confirm-token.js.map +1 -1
  14. package/dist/core/index.d.ts +2 -1
  15. package/dist/core/index.js +2 -1
  16. package/dist/core/index.js.map +1 -1
  17. package/dist/core/instructions.js +3 -3
  18. package/dist/core/instructions.js.map +1 -1
  19. package/dist/core/scope-challenge.d.ts +46 -0
  20. package/dist/core/scope-challenge.js +73 -0
  21. package/dist/core/scope-challenge.js.map +1 -0
  22. package/dist/core/shared.d.ts +4 -0
  23. package/dist/core/shared.js +9 -0
  24. package/dist/core/shared.js.map +1 -1
  25. package/dist/core/tool-def.d.ts +11 -1
  26. package/dist/core/tools/accounts.js +7 -0
  27. package/dist/core/tools/accounts.js.map +1 -1
  28. package/dist/core/tools/app.js +5 -0
  29. package/dist/core/tools/app.js.map +1 -1
  30. package/dist/core/tools/inbox-confirm.d.ts +6 -7
  31. package/dist/core/tools/inbox-confirm.js +171 -83
  32. package/dist/core/tools/inbox-confirm.js.map +1 -1
  33. package/dist/core/tools/inbox.js +16 -6
  34. package/dist/core/tools/inbox.js.map +1 -1
  35. package/dist/core/tools/index.js +2 -0
  36. package/dist/core/tools/index.js.map +1 -1
  37. package/dist/core/tools/posts.js +6 -0
  38. package/dist/core/tools/posts.js.map +1 -1
  39. package/dist/core/tools/tiktok.js +1 -0
  40. package/dist/core/tools/tiktok.js.map +1 -1
  41. package/dist/core/tools/uploads.js +2 -0
  42. package/dist/core/tools/uploads.js.map +1 -1
  43. package/dist/core/tools/webhooks.d.ts +2 -0
  44. package/dist/core/tools/webhooks.js +191 -0
  45. package/dist/core/tools/webhooks.js.map +1 -0
  46. package/dist/core/tools/workspaces.js +2 -0
  47. package/dist/core/tools/workspaces.js.map +1 -1
  48. package/dist/core/types.d.ts +83 -0
  49. package/dist/stdio/index.js +1 -1
  50. package/dist/stdio/rest-adapter.d.ts +10 -1
  51. package/dist/stdio/rest-adapter.js +41 -0
  52. package/dist/stdio/rest-adapter.js.map +1 -1
  53. package/package.json +1 -1
@@ -11,7 +11,7 @@
11
11
  {
12
12
  "name": "postfast",
13
13
  "description": "Schedule, manage, and analyze social media posts via PostFast. Supports Facebook, Instagram, X, TikTok, LinkedIn, YouTube, BlueSky, Threads, Pinterest, Telegram, and Google Business Profile.",
14
- "version": "0.13.1",
14
+ "version": "0.15.0",
15
15
  "author": {
16
16
  "name": "PostFast",
17
17
  "email": "me@peturgeorgievv.com"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "postfast",
3
3
  "description": "Schedule, manage, and analyze social media posts via PostFast. Supports Facebook, Instagram, X, TikTok, LinkedIn, YouTube, BlueSky, Threads, Pinterest, Telegram, and Google Business Profile. Needs POSTFAST_API_KEY set before Claude Code starts; in PostFast, open API in the sidebar and click Generate API Key.",
4
- "version": "0.13.1",
4
+ "version": "0.15.0",
5
5
  "author": {
6
6
  "name": "PostFast",
7
7
  "email": "me@peturgeorgievv.com"
@@ -13,7 +13,7 @@
13
13
  "mcpServers": {
14
14
  "postfast": {
15
15
  "command": "npx",
16
- "args": ["-y", "postfast-mcp@0.13.1"],
16
+ "args": ["-y", "postfast-mcp@0.15.0"],
17
17
  "env": {
18
18
  "POSTFAST_API_KEY": "${POSTFAST_API_KEY}"
19
19
  }
package/README.md CHANGED
@@ -167,6 +167,22 @@ Comments on your posts — TikTok, Instagram, Facebook Pages, and Threads — in
167
167
  | `set_inbox_conversation_status` | Triage: OPEN / SNOOZED / CLOSED |
168
168
  | `assign_inbox_conversation` | Assign a conversation to a workspace member (or unassign) |
169
169
 
170
+ ### Webhooks
171
+
172
+ PostFast can send a signed JSON event to your own HTTPS endpoint when a post publishes or fails for good, or when an account connects, reconnects or disconnects. Deliveries follow the [Standard Webhooks](https://www.standardwebhooks.com) spec (`webhook-id`, `webhook-timestamp` and `webhook-signature` headers), so any Standard Webhooks library verifies them. On the hosted connector, only workspace admins can use these tools.
173
+
174
+ | Tool | Description |
175
+ |------|-------------|
176
+ | `list_webhook_endpoints` | List the workspace's endpoints, turned-off ones included (`active`, `disabledReason`, last success and failure) |
177
+ | `get_webhook_endpoint` | Fetch one endpoint |
178
+ | `create_webhook_endpoint` | Register an HTTPS URL for some or all of `post.published`, `post.failed`, `account.connected` and `account.disconnected`; the answer carries the signing secret, which is never shown again |
179
+ | `update_webhook_endpoint` | Change an endpoint's URL, events or description, or turn it off and back on |
180
+ | `delete_webhook_endpoint` | Delete an endpoint together with its delivery log |
181
+ | `test_webhook_endpoint` | Send a test event, or a sample of one event type, and see how your receiver answered |
182
+ | `list_webhook_deliveries` | An endpoint's delivery log for the last 30 days: each attempt's status code, and the payload as sent |
183
+
184
+ Store the secret in your receiver as soon as the endpoint is created. An endpoint receives every event of its types from the whole workspace; to follow one account, filter on `data.post.socialMediaId` or `data.account.id`. A workspace can have 5 active endpoints.
185
+
170
186
  ## Supported Platforms
171
187
 
172
188
  Facebook, Instagram, X (Twitter), TikTok, LinkedIn, YouTube, BlueSky, Threads, Pinterest, Telegram, Google Business Profile
@@ -32,11 +32,3 @@ export declare const APP_ICON: ToolIcon;
32
32
  export declare function appViewHtml(): string;
33
33
  /** Registers the view as the app's UI resource. */
34
34
  export declare function registerAppResource(server: McpServer, app: AppOptions): void;
35
- /**
36
- * Lists icons on the named tools in tools/list. McpServer has no field for
37
- * tool icons, so this wraps its tools/list handler and adds `icons` to those
38
- * tools only; every other field stays the SDK's own output. If the SDK keeps
39
- * its handlers elsewhere, the icons are skipped with a log and the host falls
40
- * back to the app's own logo.
41
- */
42
- export declare function listToolIcons(server: McpServer, icons: Map<string, ToolIcon[]>): void;
package/dist/core/app.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { LOOPBACK_HOSTS } from './shared.js';
2
3
  /** Versioned: a change an open view can't handle ships under a new URI. */
3
4
  export const APP_RESOURCE_URI = 'ui://postfast/app-v1';
4
5
  export const APP_RESOURCE_MIME_TYPE = 'text/html;profile=mcp-app';
5
- const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
6
6
  /** Throws unless every option is a bare origin: https, or http on a loopback host. */
7
7
  export function assertAppOptions(app) {
8
8
  for (const key of ['mediaOrigin', 'domain', 'webAppUrl']) {
@@ -80,28 +80,4 @@ export function registerAppResource(server, app) {
80
80
  contents: [{ uri: APP_RESOURCE_URI, mimeType: APP_RESOURCE_MIME_TYPE, text, _meta }],
81
81
  }));
82
82
  }
83
- /**
84
- * Lists icons on the named tools in tools/list. McpServer has no field for
85
- * tool icons, so this wraps its tools/list handler and adds `icons` to those
86
- * tools only; every other field stays the SDK's own output. If the SDK keeps
87
- * its handlers elsewhere, the icons are skipped with a log and the host falls
88
- * back to the app's own logo.
89
- */
90
- export function listToolIcons(server, icons) {
91
- const handlers = server.server._requestHandlers;
92
- const list = handlers instanceof Map ? handlers.get('tools/list') : undefined;
93
- if (!list) {
94
- console.error('[postfast-mcp/core] tool icons not listed: no tools/list handler to wrap');
95
- return;
96
- }
97
- handlers.set('tools/list', async (request, extra) => {
98
- const result = (await list(request, extra));
99
- for (const tool of result.tools ?? []) {
100
- const toolIcons = icons.get(tool.name);
101
- if (toolIcons)
102
- tool.icons = toolIcons;
103
- }
104
- return result;
105
- });
106
- }
107
83
  //# sourceMappingURL=app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/core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G,WAAW,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,CAAC,gBAAgB,CACrB,mBAAmB,EACnB,gBAAgB,EAChB;QACE,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,qCAAqC;QAClD,QAAQ,EAAE,sBAAsB;QAChC,KAAK;KACN,EACD,KAAK,IAAI,EAAE,CAAC,CAAC;QACX,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,QAAQ,EAAE,sBAAsB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;KACrF,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AnalyticsResponse, AppAction, AppCalendar, AppEntrypoint, AppPostDetail, FollowerHistory, GbpLocation, PaginatedPosts, PinterestBoard, Place, Platform, SignedUploadUrl, SocialAccount, UploadType, YouTubePlaylist } from './types.js';
1
+ import type { AnalyticsResponse, AppAction, AppCalendar, AppEntrypoint, AppPostDetail, FollowerHistory, GbpLocation, PaginatedPosts, PaginatedWebhookDeliveries, PinterestBoard, Place, Platform, SignedUploadUrl, SocialAccount, UploadType, WebhookEndpoint, WebhookEvent, WebhookTestResult, YouTubePlaylist } from './types.js';
2
2
  export interface ListPostsArgs {
3
3
  page: number;
4
4
  limit: number;
@@ -66,6 +66,11 @@ export interface ListInboxItemsArgs {
66
66
  export interface InboxReplyArgs {
67
67
  itemId: string;
68
68
  text: string;
69
+ /**
70
+ * Sends with the same key go out once: the backend returns the first send's
71
+ * result for a repeat. Set by the remote reply tools from their confirm token.
72
+ */
73
+ idempotencyKey?: string;
69
74
  }
70
75
  export interface SetInboxItemStateArgs {
71
76
  itemId: string;
@@ -120,6 +125,30 @@ export interface LocalUploadResult {
120
125
  type: UploadType;
121
126
  contentType: string;
122
127
  }
128
+ export interface CreateWebhookEndpointArgs {
129
+ url: string;
130
+ events: WebhookEvent[];
131
+ description?: string;
132
+ }
133
+ /** Omitted fields keep their value; `description: null` removes it. */
134
+ export interface UpdateWebhookEndpointArgs {
135
+ id: string;
136
+ url?: string;
137
+ events?: WebhookEvent[];
138
+ description?: string | null;
139
+ active?: boolean;
140
+ }
141
+ export interface TestWebhookEndpointArgs {
142
+ id: string;
143
+ /** Send a sample of this event type instead of `webhook.test`. */
144
+ sampleEvent?: WebhookEvent;
145
+ }
146
+ export interface ListWebhookDeliveriesArgs {
147
+ endpointId: string;
148
+ page?: number;
149
+ limit?: number;
150
+ getCount?: boolean;
151
+ }
123
152
  /**
124
153
  * Everything the catalog tools need from a backend. The stdio bin implements
125
154
  * it over the public REST API (pf-api-key); the deployed host implements it
@@ -174,4 +203,14 @@ export interface BackendPort {
174
203
  deletedIds: string[];
175
204
  notFoundIds: string[];
176
205
  } | unknown>;
206
+ listWebhookEndpoints?(workspaceId?: string): Promise<WebhookEndpoint[] | unknown>;
207
+ getWebhookEndpoint?(id: string, workspaceId?: string): Promise<WebhookEndpoint | unknown>;
208
+ createWebhookEndpoint?(args: CreateWebhookEndpointArgs, workspaceId?: string): Promise<WebhookEndpoint | unknown>;
209
+ updateWebhookEndpoint?(args: UpdateWebhookEndpointArgs, workspaceId?: string): Promise<WebhookEndpoint | unknown>;
210
+ /** Answers `{ ok: true }`. */
211
+ deleteWebhookEndpoint?(id: string, workspaceId?: string): Promise<{
212
+ ok: true;
213
+ } | unknown>;
214
+ testWebhookEndpoint?(args: TestWebhookEndpointArgs, workspaceId?: string): Promise<WebhookTestResult | unknown>;
215
+ listWebhookDeliveries?(args: ListWebhookDeliveriesArgs, workspaceId?: string): Promise<PaginatedWebhookDeliveries | unknown>;
177
216
  }
@@ -2,6 +2,7 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { type AppOptions } from './app.js';
4
4
  import type { BackendPort } from './backend-port.js';
5
+ import { type ScopeChallengeOptions } from './scope-challenge.js';
5
6
  import type { Binding, ResolvedTool } from './tool-def.js';
6
7
  export interface ConfirmGateOptions {
7
8
  /** HMAC key for confirm tokens; at least 32 characters. */
@@ -22,11 +23,12 @@ export interface BuildToolsOptions {
22
23
  */
23
24
  port?: BackendPort;
24
25
  /**
25
- * Remote only. The key that signs prepare_inbox_action / confirm_inbox_action
26
- * tokens for comment replies, private replies and deletions. The remote
27
- * catalogue holds every post and reply for the user's yes either way;
28
- * without a key those two tools are left out (logged once), so comment
29
- * replies and deletions are unavailable.
26
+ * Remote only. The key that signs and checks the confirm tokens of the
27
+ * comment tools: preview_comment_reply → reply_to_comment,
28
+ * preview_private_reply → send_private_reply and preview_comment_deletion →
29
+ * delete_comment. The remote catalogue holds every post and reply for the
30
+ * user's yes either way; without a key those six tools are left out (logged
31
+ * once), so comment replies and deletions are unavailable.
30
32
  */
31
33
  confirmGate?: ConfirmGateOptions;
32
34
  /**
@@ -53,15 +55,28 @@ export declare function buildTools(options: BuildToolsOptions): ResolvedTool[];
53
55
  export declare function toolResult(data: unknown): CallToolResult;
54
56
  /** A business/tool error the model should see and react to (not a protocol error). */
55
57
  export declare function toolError(message: string): CallToolResult;
56
- /** Run a handler, converting thrown errors into `isError` tool results. */
57
- export declare function runTool(fn: () => Promise<unknown>, toResult?: (data: unknown) => CallToolResult): Promise<CallToolResult>;
58
+ /**
59
+ * Run a handler, converting thrown errors into `isError` tool results.
60
+ * `onError` may answer an error with a result of its own; when it returns
61
+ * nothing, the error's message is the result.
62
+ */
63
+ export declare function runTool(fn: () => Promise<unknown>, toResult?: (data: unknown) => CallToolResult, onError?: (err: unknown) => CallToolResult | undefined): Promise<CallToolResult>;
58
64
  export interface RegisterToolsOptions extends BuildToolsOptions {
59
65
  port: BackendPort;
66
+ /**
67
+ * Remote only. When a tool's port call throws InsufficientScopeError (the
68
+ * backend refused the token's scopes), the result becomes an OAuth
69
+ * insufficient_scope challenge naming this metadata URL and the tool's
70
+ * scopes, so a client can ask the user for them and retry. Without it the
71
+ * error stays an ordinary tool error.
72
+ */
73
+ scopeChallenge?: ScopeChallengeOptions;
60
74
  }
61
75
  /**
62
- * Register the resolved catalog for a binding on an MCP server. With `app`,
63
- * also registers the view as a UI resource and lists the app tools' icons,
64
- * but only when a registered tool opens the view (a port without the app
65
- * methods registers neither).
76
+ * Register the resolved catalog for a binding on an MCP server. On the remote
77
+ * binding every tool lists its `securitySchemes`. With `app`, also registers
78
+ * the view as a UI resource and lists the app tools' icons, but only when a
79
+ * registered tool opens the view (a port without the app methods registers
80
+ * neither).
66
81
  */
67
82
  export declare function registerCatalogTools(server: McpServer, options: RegisterToolsOptions): void;
@@ -1,4 +1,5 @@
1
- import { APP_RESOURCE_URI, assertAppOptions, listToolIcons, registerAppResource, } from './app.js';
1
+ import { APP_RESOURCE_URI, assertAppOptions, registerAppResource, } from './app.js';
2
+ import { assertScopeChallengeOptions, insufficientScopeResult, isInsufficientScopeError, } from './scope-challenge.js';
2
3
  import { workspaceIdField } from './shared.js';
3
4
  import { ALL_TOOLS } from './tools/index.js';
4
5
  let warnedNoConfirmSecret = false;
@@ -12,7 +13,7 @@ export function buildTools(options) {
12
13
  const secret = remote ? confirmGate?.secret : undefined;
13
14
  if (remote && !secret && !warnedNoConfirmSecret) {
14
15
  warnedNoConfirmSecret = true;
15
- console.error('[postfast-mcp/core] no confirmGate secret: prepare_inbox_action and confirm_inbox_action are left out, so comment replies and deletions are unavailable');
16
+ console.error('[postfast-mcp/core] no confirmGate secret: the comment reply, private reply and deletion tools are left out, so comment replies and deletions are unavailable');
16
17
  }
17
18
  const appOn = remote && !!app;
18
19
  if (appOn)
@@ -40,6 +41,8 @@ export function buildTools(options) {
40
41
  const inputSchema = typeof def.inputSchema === 'function' ? def.inputSchema(binding) : def.inputSchema;
41
42
  const annotations = remote && def.remoteAnnotations ? def.remoteAnnotations : def.annotations;
42
43
  const ctx = contextFor(def);
44
+ // Remote only: the hosted connector is the one clients sign in to with OAuth.
45
+ const securitySchemes = remote && def.scopes ? [{ type: 'oauth2', scopes: [...def.scopes] }] : undefined;
43
46
  return {
44
47
  name: def.name,
45
48
  title: def.title,
@@ -48,8 +51,9 @@ export function buildTools(options) {
48
51
  ? { ...inputSchema, workspaceId: workspaceIdField }
49
52
  : inputSchema,
50
53
  annotations: { title: def.title, ...annotations },
51
- _meta: def._meta,
54
+ _meta: securitySchemes ? { ...def._meta, securitySchemes } : def._meta,
52
55
  ...(def.icons ? { icons: def.icons } : {}),
56
+ ...(securitySchemes ? { securitySchemes } : {}),
53
57
  portMethod: def.portMethod,
54
58
  // Hand the confirm secret and app options to run(), also for hosts that call tool.run() themselves.
55
59
  run: Object.keys(ctx).length
@@ -88,23 +92,66 @@ export function toolError(message) {
88
92
  isError: true,
89
93
  };
90
94
  }
91
- /** Run a handler, converting thrown errors into `isError` tool results. */
92
- export async function runTool(fn, toResult = toolResult) {
95
+ /**
96
+ * Run a handler, converting thrown errors into `isError` tool results.
97
+ * `onError` may answer an error with a result of its own; when it returns
98
+ * nothing, the error's message is the result.
99
+ */
100
+ export async function runTool(fn, toResult = toolResult, onError) {
93
101
  try {
94
102
  return toResult(await fn());
95
103
  }
96
104
  catch (err) {
97
- return toolError(err.message || 'Tool execution failed.');
105
+ return onError?.(err) ?? toolError(err.message || 'Tool execution failed.');
106
+ }
107
+ }
108
+ /**
109
+ * The challenge for a tool whose call the backend refused for scope, or
110
+ * undefined when one cannot help: the tool needs no scope, or the token
111
+ * already has every scope the tool declares (asking again would loop).
112
+ */
113
+ function scopeChallengeFor(tool, options, authInfo) {
114
+ const scopes = tool.securitySchemes?.flatMap((scheme) => scheme.scopes) ?? [];
115
+ const granted = Array.isArray(authInfo?.scopes) ? authInfo.scopes : undefined;
116
+ if (!scopes.length || (granted && scopes.every((scope) => granted.includes(scope)))) {
117
+ return undefined;
98
118
  }
119
+ return insufficientScopeResult({ ...options, scopes, grantedScopes: granted });
99
120
  }
100
121
  /**
101
- * Register the resolved catalog for a binding on an MCP server. With `app`,
102
- * also registers the view as a UI resource and lists the app tools' icons,
103
- * but only when a registered tool opens the view (a port without the app
104
- * methods registers neither).
122
+ * Adds fields McpServer has no option for (`securitySchemes`, `icons`) to the
123
+ * named tools in tools/list, by wrapping its tools/list handler; every other
124
+ * field stays the SDK's own output. If the SDK keeps its handlers elsewhere,
125
+ * nothing is added and a log line says so: `securitySchemes` still reach
126
+ * clients in each tool's `_meta`, and the host falls back to the app's logo.
127
+ */
128
+ function listToolFields(server, fields) {
129
+ const handlers = server.server._requestHandlers;
130
+ const list = handlers instanceof Map ? handlers.get('tools/list') : undefined;
131
+ if (!list) {
132
+ console.error('[postfast-mcp/core] securitySchemes and icons not listed at the top level: no tools/list handler to wrap');
133
+ return;
134
+ }
135
+ handlers.set('tools/list', async (request, extra) => {
136
+ const result = (await list(request, extra));
137
+ for (const tool of result.tools ?? []) {
138
+ Object.assign(tool, fields.get(tool.name));
139
+ }
140
+ return result;
141
+ });
142
+ }
143
+ /**
144
+ * Register the resolved catalog for a binding on an MCP server. On the remote
145
+ * binding every tool lists its `securitySchemes`. With `app`, also registers
146
+ * the view as a UI resource and lists the app tools' icons, but only when a
147
+ * registered tool opens the view (a port without the app methods registers
148
+ * neither).
105
149
  */
106
150
  export function registerCatalogTools(server, options) {
107
151
  const { port } = options;
152
+ const scopeChallenge = options.binding === 'remote' ? options.scopeChallenge : undefined;
153
+ if (scopeChallenge)
154
+ assertScopeChallengeOptions(scopeChallenge);
108
155
  const tools = buildTools(options);
109
156
  for (const tool of tools) {
110
157
  server.registerTool(tool.name, {
@@ -113,19 +160,29 @@ export function registerCatalogTools(server, options) {
113
160
  inputSchema: tool.inputSchema,
114
161
  annotations: tool.annotations,
115
162
  ...(tool._meta ? { _meta: tool._meta } : {}),
116
- }, (args) => runTool(() => {
163
+ }, (args, extra) => runTool(() => {
117
164
  const { workspaceId, ...rest } = args ?? {};
118
165
  return tool.run(port, rest, workspaceId);
119
- }, tool.toResult));
166
+ }, tool.toResult, scopeChallenge
167
+ ? (err) => isInsufficientScopeError(err)
168
+ ? scopeChallengeFor(tool, scopeChallenge, extra?.authInfo)
169
+ : undefined
170
+ : undefined));
171
+ }
172
+ const listed = new Map();
173
+ for (const tool of tools) {
174
+ if (tool.securitySchemes)
175
+ listed.set(tool.name, { securitySchemes: tool.securitySchemes });
120
176
  }
121
177
  const opensView = (tool) => tool._meta?.ui?.resourceUri === APP_RESOURCE_URI;
122
178
  if (options.app && tools.some(opensView)) {
123
179
  registerAppResource(server, options.app);
124
- const icons = new Map();
125
- for (const tool of tools)
180
+ for (const tool of tools) {
126
181
  if (tool.icons)
127
- icons.set(tool.name, tool.icons);
128
- listToolIcons(server, icons);
182
+ listed.set(tool.name, { ...listed.get(tool.name), icons: tool.icons });
183
+ }
129
184
  }
185
+ if (listed.size)
186
+ listToolFields(server, listed);
130
187
  }
131
188
  //# sourceMappingURL=build-tools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-tools.js","sourceRoot":"","sources":["../../src/core/build-tools.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAsC7C,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAChF,MAAM,MAAM,GAAG,OAAO,KAAK,QAAQ,CAAC;IACpC,IAAI,MAAM,IAAI,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,MAAM,GAAG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C,IAAI;QAAE,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC"}
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Tokens that tie confirm_inbox_action to exactly what prepare_inbox_action
3
- * previewed: an HMAC over the workspace, item, action and text. Format
4
- * `v1.<exp>.<jti>.<base64url mac>`, exp in epoch seconds. Stateless apart from
5
- * the used-jti list below, so a token verifies on any replica of a host.
2
+ * Tokens that tie a comment reply, private reply or deletion to exactly what
3
+ * its preview tool showed: an HMAC over the workspace, item, action and text.
4
+ * Format `v1.<exp>.<jti>.<base64url mac>`, exp in epoch seconds. Stateless
5
+ * apart from the used-jti list below, so a token verifies on any replica of a
6
+ * host. The action is signed too, so a token previewed for one operation never
7
+ * carries out another.
6
8
  */
7
9
  export type ConfirmAction = 'REPLY' | 'PRIVATE_REPLY' | 'DELETE';
8
10
  export interface ConfirmFields {
@@ -18,6 +20,10 @@ export declare function sign(fields: ConfirmFields, secret: string, now?: number
18
20
  /**
19
21
  * Verify a token against the caller's own values and reserve its jti in the
20
22
  * same synchronous step, so two concurrent confirms cannot both pass. Returns
21
- * a release() for when the action itself then fails.
23
+ * the jti, which identifies this one approved action, and a release() for
24
+ * when the action itself then fails.
22
25
  */
23
- export declare function redeem(confirmToken: string, fields: ConfirmFields, secret: string, now?: number): () => void;
26
+ export declare function redeem(confirmToken: string, fields: ConfirmFields, secret: string, now?: number): {
27
+ jti: string;
28
+ release: () => void;
29
+ };
@@ -1,12 +1,20 @@
1
1
  import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
2
2
  const TTL_SECONDS = 900;
3
- const MISMATCH = 'confirmToken does not match this action. Prepare it again with prepare_inbox_action and confirm exactly what was previewed.';
4
- const EXPIRED = 'confirmToken has expired. Prepare the action again.';
3
+ /** The tool that previews each action, named in the errors so the model knows how to start over. */
4
+ const PREVIEW_TOOLS = {
5
+ REPLY: 'preview_comment_reply',
6
+ PRIVATE_REPLY: 'preview_private_reply',
7
+ DELETE: 'preview_comment_deletion',
8
+ };
9
+ const missing = (action) => `confirmToken is required. Preview it first with ${PREVIEW_TOOLS[action]}.`;
10
+ const mismatch = (action) => `confirmToken does not match this request. Preview it again with ${PREVIEW_TOOLS[action]} and pass exactly what was previewed.`;
11
+ const expired = (action) => `confirmToken has expired. Preview it again with ${PREVIEW_TOOLS[action]}.`;
5
12
  const USED = 'This confirmToken was already used.';
6
13
  /**
7
14
  * jti -> exp of every redeemed token that has not expired yet. Module-level,
8
15
  * so it spans sessions and buildTools() calls, but it is per process: a token
9
- * replayed on another replica of a host is not caught here.
16
+ * replayed on another replica of a host is not caught here. The reply tools
17
+ * send the jti as the backend's idempotency key, so such a replay sends once.
10
18
  */
11
19
  const usedJtis = new Map();
12
20
  function prune(nowSeconds) {
@@ -36,29 +44,36 @@ export function sign(fields, secret, now = Date.now()) {
36
44
  /**
37
45
  * Verify a token against the caller's own values and reserve its jti in the
38
46
  * same synchronous step, so two concurrent confirms cannot both pass. Returns
39
- * a release() for when the action itself then fails.
47
+ * the jti, which identifies this one approved action, and a release() for
48
+ * when the action itself then fails.
40
49
  */
41
50
  export function redeem(confirmToken, fields, secret, now = Date.now()) {
42
51
  const nowSeconds = Math.floor(now / 1000);
43
52
  prune(nowSeconds);
53
+ if (typeof confirmToken !== 'string' || !confirmToken) {
54
+ throw new Error(missing(fields.action));
55
+ }
44
56
  const parts = confirmToken.split('.');
45
57
  const [version, expText, jti, given] = parts;
46
58
  if (parts.length !== 4 || version !== 'v1' || !/^\d+$/.test(expText)) {
47
- throw new Error(MISMATCH);
59
+ throw new Error(mismatch(fields.action));
48
60
  }
49
61
  const exp = Number(expText);
50
62
  if (nowSeconds > exp)
51
- throw new Error(EXPIRED);
63
+ throw new Error(expired(fields.action));
52
64
  const expected = Buffer.from(mac(secret, exp, jti, fields));
53
65
  const actual = Buffer.from(given);
54
66
  if (expected.length !== actual.length || !timingSafeEqual(expected, actual)) {
55
- throw new Error(MISMATCH);
67
+ throw new Error(mismatch(fields.action));
56
68
  }
57
69
  if (usedJtis.has(jti))
58
70
  throw new Error(USED);
59
71
  usedJtis.set(jti, exp);
60
- return () => {
61
- usedJtis.delete(jti);
72
+ return {
73
+ jti,
74
+ release: () => {
75
+ usedJtis.delete(jti);
76
+ },
62
77
  };
63
78
  }
64
79
  //# sourceMappingURL=confirm-token.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"confirm-token.js","sourceRoot":"","sources":["../../src/core/confirm-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkBtE,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,QAAQ,GACZ,6HAA6H,CAAC;AAChI,MAAM,OAAO,GAAG,qDAAqD,CAAC;AACtE,MAAM,IAAI,GAAG,qCAAqC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE3C,SAAS,KAAK,CAAC,UAAkB;IAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;QAClC,IAAI,GAAG,GAAG,UAAU;YAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,SAAS,GAAG,CAAC,MAAc,EAAE,GAAW,EAAE,GAAW,EAAE,MAAqB;IAC1E,2EAA2E;IAC3E,yDAAyD;IACzD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;SAChC,MAAM,CACL,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,MAAM,EA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,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvB,OAAO;QACL,GAAG;QACH,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -7,7 +7,8 @@ export * from './backend-port.js';
7
7
  export { APP_RESOURCE_MIME_TYPE, APP_RESOURCE_URI, appViewHtml, assertAppOptions, type AppOptions, } from './app.js';
8
8
  export { buildTools, registerCatalogTools, runTool, toolError, toolResult, type BuildToolsOptions, type ConfirmGateOptions, type RegisterToolsOptions, } from './build-tools.js';
9
9
  export { SERVER_INSTRUCTIONS, instructionsFor } from './instructions.js';
10
- export { CAPTION_MIME_TYPES, CREATE_APPROVAL_STATUSES, CREATE_STATUSES, DOCUMENT_MIME_TYPES, IMAGE_MIME_TYPES, PLATFORMS, POST_STATUSES, SET_APPROVAL_STATUSES, VIDEO_MIME_TYPES, jsonParse, uploadTypeFor, workspaceIdField, } from './shared.js';
10
+ export { InsufficientScopeError, insufficientScopeResult, type InsufficientScopeOptions, type ScopeChallengeOptions, type SecurityScheme, } from './scope-challenge.js';
11
+ export { CAPTION_MIME_TYPES, CREATE_APPROVAL_STATUSES, CREATE_STATUSES, DOCUMENT_MIME_TYPES, IMAGE_MIME_TYPES, PLATFORMS, POST_STATUSES, SET_APPROVAL_STATUSES, VIDEO_MIME_TYPES, WEBHOOK_EVENTS, jsonParse, uploadTypeFor, workspaceIdField, } from './shared.js';
11
12
  export type { Binding, ResolvedTool, ResolvedToolAnnotations, ToolAnnotations, ToolDef, ToolIcon, } from './tool-def.js';
12
13
  export { ALL_TOOLS } from './tools/index.js';
13
14
  export * from './types.js';
@@ -7,7 +7,8 @@ export * from './backend-port.js';
7
7
  export { APP_RESOURCE_MIME_TYPE, APP_RESOURCE_URI, appViewHtml, assertAppOptions, } from './app.js';
8
8
  export { buildTools, registerCatalogTools, runTool, toolError, toolResult, } from './build-tools.js';
9
9
  export { SERVER_INSTRUCTIONS, instructionsFor } from './instructions.js';
10
- export { CAPTION_MIME_TYPES, CREATE_APPROVAL_STATUSES, CREATE_STATUSES, DOCUMENT_MIME_TYPES, IMAGE_MIME_TYPES, PLATFORMS, POST_STATUSES, SET_APPROVAL_STATUSES, VIDEO_MIME_TYPES, jsonParse, uploadTypeFor, workspaceIdField, } from './shared.js';
10
+ export { InsufficientScopeError, insufficientScopeResult, } from './scope-challenge.js';
11
+ export { CAPTION_MIME_TYPES, CREATE_APPROVAL_STATUSES, CREATE_STATUSES, DOCUMENT_MIME_TYPES, IMAGE_MIME_TYPES, PLATFORMS, POST_STATUSES, SET_APPROVAL_STATUSES, VIDEO_MIME_TYPES, WEBHOOK_EVENTS, jsonParse, uploadTypeFor, workspaceIdField, } from './shared.js';
11
12
  export { ALL_TOOLS } from './tools/index.js';
12
13
  export * from './types.js';
13
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,UAAU,GAIX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AASrB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,UAAU,GAIX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAIxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AASrB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,cAAc,YAAY,CAAC"}
@@ -8,8 +8,8 @@
8
8
  * surfaces differ (workspace switching and conversation-media/URL uploads on
9
9
  * the remote host, local files on stdio) and in how posts and comment replies
10
10
  * go out: on the remote binding every post is held until approve_posts, and
11
- * replies and comment deletions go through prepare_inbox_action and
12
- * confirm_inbox_action, each only after the user says yes.
11
+ * each reply, private reply and comment deletion is previewed by one tool and
12
+ * carried out by another, only after the user says yes.
13
13
  */
14
14
  const INTRO = `PostFast schedules and publishes social posts across X, Instagram, Facebook, TikTok, LinkedIn, YouTube, Threads, Pinterest, Bluesky, Telegram, and Google Business Profile.`;
15
15
  const CONNECTED = `Before scheduling, confirm the target account's connectionStatus is CONNECTED. A DISABLED account will not publish (disconnected accounts are the #1 cause of failed posts) — saving a DRAFT is still allowed.`;
@@ -64,7 +64,7 @@ const REMOTE_INSTRUCTIONS = [
64
64
  CONTROLS,
65
65
  FAILED,
66
66
  REMOTE_DELETE_POST,
67
- `Social inbox (comments on your posts: TikTok, Instagram, Facebook Pages, Threads; an account's inboxCapable flag from list_accounts says what is live today): read with list_inbox_conversations → list_inbox_items (get_inbox_unread_count for the total). To reply publicly under a comment (REPLY), send an Instagram private reply (PRIVATE_REPLY: one per comment, within 7 days) or delete a comment permanently (DELETE), call prepare_inbox_action, show the user the preview, and carry it out with confirm_inbox_action only after they say yes, even if they gave you the text. Whether and how long a reply can be comes ONLY from the conversation's server-computed canReply / maxReplyLength / windowState / disabledReason; never assume platform rules. Hide or restore a comment with set_inbox_item_state (HIDE / UNHIDE), triage with set_inbox_conversation_status and assign_inbox_conversation, and call mark_inbox_conversation_read after presenting a thread. It is a comments inbox; never present it as DMs or messages.`,
67
+ `Social inbox (comments on your posts: TikTok, Instagram, Facebook Pages, Threads; an account's inboxCapable flag from list_accounts says what is live today): read with list_inbox_conversations → list_inbox_items (get_inbox_unread_count for the total). A public reply under a comment, an Instagram private reply (one per comment, within 7 days) and a permanent comment deletion each take two tools: preview it with preview_comment_reply, preview_private_reply or preview_comment_deletion, show the user the preview, and carry it out with reply_to_comment, send_private_reply or delete_comment only after they say yes, even if they gave you the text. Whether and how long a reply can be comes ONLY from the conversation's server-computed canReply / maxReplyLength / windowState / disabledReason; never assume platform rules. Hide or restore a comment with set_inbox_item_state (HIDE / UNHIDE), triage with set_inbox_conversation_status and assign_inbox_conversation, and call mark_inbox_conversation_read after presenting a thread. It is a comments inbox; never present it as DMs or messages.`,
68
68
  ].join('\n\n');
69
69
  export const SERVER_INSTRUCTIONS = {
70
70
  stdio: STDIO_INSTRUCTIONS,
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/core/instructions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,MAAM,KAAK,GAAG,6KAA6K,CAAC;AAE5L,MAAM,SAAS,GAAG,gNAAgN,CAAC;AAEnO,MAAM,KAAK,GAAG,8uBAA8uB,CAAC;AAE7vB,MAAM,MAAM,GAAG;;;;;;;;;;;wLAWyK,CAAC;AAEzL,MAAM,QAAQ,GAAG;;;;;;;;;;0RAUyQ,CAAC;AAE3R,MAAM,MAAM,GAAG,mHAAmH,CAAC;AAEnI,MAAM,WAAW,GAAG,gPAAgP,CAAC;AAErQ,MAAM,kBAAkB,GAAG,GAAG,WAAW,uKAAuK,CAAC;AAEjN,MAAM,kBAAkB,GAAG;IACzB,KAAK;IACL,qSAAqS;IACrS,+EAA+E;IAC/E,SAAS;IACT,yXAAyX;IACzX,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,WAAW;IACX,y4BAAy4B;CAC14B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEf,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,8cAA8c;IAC9c,sIAAsI;IACtI,SAAS;IACT,4QAA4Q;IAC5Q,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,kBAAkB;IAClB,s/BAAs/B;CACv/B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEf,MAAM,CAAC,MAAM,mBAAmB,GAA4B;IAC1D,KAAK,EAAE,kBAAkB;IACzB,MAAM,EAAE,mBAAmB;CAC5B,CAAC;AAEF;;;;GAIG;AACH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