diff --git a/src/credits.ts b/src/credits.ts index 85839fc..6f9a7cc 100644 --- a/src/credits.ts +++ b/src/credits.ts @@ -35,6 +35,9 @@ export function creditClass(tool: string, kind: string): CreditClass { if (method === "get_analytics") return action === "export_contacts" ? "export" : "read"; if (method === "call_recordings") return action === "list" || action === "search" ? "read" : "export"; if (method === "send_message" || method === "create_attachment_upload") return "send"; + // kaption-links.MCP.5 — create_tracked_links is a send (2 credits); list_tracked_links and get_link_clicks fall + // through to read (1). + if (method === "create_tracked_links") return "send"; if (method.startsWith("manage_")) { if (READ_ACTIONS.has(action)) return "read"; if (SEND_ACTIONS[method]?.has(action)) return "send"; diff --git a/src/ledger-credits.test.ts b/src/ledger-credits.test.ts index bde8a77..85b7c9c 100644 --- a/src/ledger-credits.test.ts +++ b/src/ledger-credits.test.ts @@ -86,10 +86,10 @@ function restApi(answer: (() => Response) | Record = planAnswer return { fetcher, asked }; } -function fakeRoom(phone: string, fail = false) { +function fakeRoom(phone: string, fail = false, features: Record = {}) { const room = { calls: [] as string[], - async watchManage() { return { manage_kaption: true, plans: true }; }, + async watchManage() { return { manage_kaption: true, plans: true, ...features }; }, async meteringPhone() { return phone; }, async handleMcpRequestSettled(method: string) { room.calls.push(method); @@ -100,8 +100,8 @@ function fakeRoom(phone: string, fail = false) { return room; } -async function world(vars: Record = {}, opts: { fail?: boolean } = {}) { - const room = fakeRoom(PHONE, opts.fail); +async function world(vars: Record = {}, opts: { fail?: boolean; features?: Record } = {}) { + const room = fakeRoom(PHONE, opts.fail, opts.features); const envRef = { env: {} as Env }; const ns = ledgers(envRef); envRef.env = { @@ -188,6 +188,15 @@ describe("mcp-usage-ledger.CREDITS the credit table", () => { expect(creditsOf("query", "messages")).toBe(1); }); + it("kaption-links.MCP.5 — create_tracked_links is a send (2 credits), list_tracked_links and get_link_clicks are reads (1)", () => { + expect(creditClass("create_tracked_links", "")).toBe("send"); + expect(creditsOf("create_tracked_links", "")).toBe(2); + expect(creditClass("list_tracked_links", "")).toBe("read"); + expect(creditsOf("list_tracked_links", "")).toBe(1); + expect(creditClass("get_link_clicks", "")).toBe("read"); + expect(creditsOf("get_link_clicks", "")).toBe(1); + }); + it("advanced-analytics.MCP.6 — each new get_analytics section costs one read credit", () => { for (const section of ["community_activity", "channel_posts", "post_detail", "community_changes", "message_reads"]) { const kind = usageKind("get_analytics", { section, chat_id: "120363000000000001@newsletter", post_id: "123" }); @@ -276,6 +285,21 @@ describe("mcp-usage-ledger.CREDITS a credits month", () => { expect(((await read.json()) as any).month).toMatchObject({ credits: 3, from: "2026-11-25T00:00:00.000Z" }); }); + it("kaption-links.MCP.5 — relayed Kaption Links calls weigh 2 (create) and 1 (list, clicks) in the month, cloud and local alike", async () => { + vi.useFakeTimers({ toFake: ["Date"], now: Date.UTC(2026, 11, 10, 12) }); + vi.stubGlobal("fetch", restApi(planAnswer({ tier: "business", limit: 2000, enforced_by: "none", enforce: false })).fetcher); + const w = await world({}, { features: { kaption_links: true } }); + // Cloud: 2 creates (4), 1 list (1), 1 clicks read (1) = 6 credits. + for (let i = 0; i < 2; i++) expect((await w.tool("create_tracked_links", { links: [{ url: "https://example.com/sale" }] })).isError).toBeFalsy(); + expect((await w.tool("list_tracked_links", { q: "sale" })).isError).toBeFalsy(); + expect((await w.tool("get_link_clicks", {})).isError).toBeFalsy(); + expect(w.room.calls).toEqual(["create_tracked_links", "create_tracked_links", "list_tracked_links", "get_link_clicks"]); + expect(await w.month()).toMatchObject({ counted: 4, credits: 6 }); + // Local hub batch rows weigh the same. + expect((await postBatch(w, "batch_links_01", [{ tool: "create_tracked_links", calls: 3 }, { tool: "get_link_clicks" }])).status).toBe(200); + expect(await w.month()).toMatchObject({ counted: 8, credits: 13 }); + }); + it("mcp-usage-pricing.CREDITS_V2.4, mcp-usage-ledger.SINGLE.10 — a Pro month in credits is counted and shown, never refused", async () => { vi.useFakeTimers({ toFake: ["Date"], now: Date.UTC(2026, 11, 3, 12) }); vi.stubGlobal("fetch", restApi(planAnswer({ tier: "pro", limit: 2, enforced_by: "none", enforce: false })).fetcher); diff --git a/src/manage-kaption.test.ts b/src/manage-kaption.test.ts index 609da58..dc83aa5 100644 --- a/src/manage-kaption.test.ts +++ b/src/manage-kaption.test.ts @@ -35,6 +35,7 @@ import { PLANS_UI_HTML } from "./plans-ui"; import { TOOLS, getToolsForMCP } from "./tools"; import channelsCanonical from "./test-support/mcp-channels-communities-tools.json"; import exportChatCanonical from "./test-support/mcp-export-chat-tools.json"; +import linksCanonical from "./test-support/mcp-links-tools.json"; import { FakeKV } from "./test-support/fake-kv"; const flush = () => new Promise((resolve) => setTimeout(resolve, 10)); @@ -276,8 +277,8 @@ describe("whatsapp-channels-communities.HUB the channels and communities tools o }); describe("chat-export.MCP export_chat on the relay", () => { - it("chat-export.MCP.2, MCP.4 — is the pinned kaptionai definition, verbatim (read-only), last in TOOLS", async () => { - expect(TOOLS[TOOLS.length - 1].name).toBe("export_chat"); + it("chat-export.MCP.2, MCP.4 — is the pinned kaptionai definition, verbatim (read-only), right before the Kaption Links tools", async () => { + expect(TOOLS[TOOLS.length - 1 - LINK_TOOLS.length].name).toBe("export_chat"); const want = (exportChatCanonical as any[])[0]; const got = getToolsForMCP().find((t) => t.name === "export_chat")!; expect({ name: got.name, title: got.title, description: got.description, inputSchema: normalized(got.inputSchema), annotations: got.annotations }).toEqual(want); @@ -317,6 +318,73 @@ describe("chat-export.MCP export_chat on the relay", () => { }); }); +const LINK_TOOLS = ["create_tracked_links", "list_tracked_links", "get_link_clicks"]; + +describe("kaption-links.MCP the Kaption Links tools on the relay", () => { + it("kaption-links.MCP.1-3, MCP.10 — are the pinned kaptionai definitions, verbatim, last in TOOLS", async () => { + expect(TOOLS.slice(-LINK_TOOLS.length).map((t) => t.name)).toEqual(LINK_TOOLS); + expect((linksCanonical as any[]).map((t) => t.name)).toEqual(LINK_TOOLS); + const exported = getToolsForMCP(); + const listed = (await (await session(fakeRoom({ kaption_links: true }))).client.listTools()).tools; + for (const want of linksCanonical as any[]) { + const got = exported.find((t) => t.name === want.name)!; + expect({ name: got.name, title: got.title, description: got.description, inputSchema: normalized(got.inputSchema), annotations: got.annotations }).toEqual(normalized(want)); + const l = listed.find((t) => t.name === want.name)!; + expect(l.title, want.name).toBe(want.title); + expect(l.description, want.name).toBe(want.description); + expect(l.annotations, want.name).toEqual(want.annotations); + expect(normalized(l.inputSchema), want.name).toEqual(normalized(want.inputSchema)); + } + }); + + it("kaption-links.MCP.10 — only features.kaption_links true shows them; false, absent or an older extension hides them", async () => { + expect([...visibleManageTools([{ kaption_links: true }])]).toEqual(LINK_TOOLS); + expect(readManageFeatures({ kaption_links: true, export_chat: "yes" })).toEqual({ kaption_links: true }); + expect(readManageFeatures({ kaption_links: 1 })).toEqual({}); + for (const features of [{}, null, { manage_kaption: true, export_chat: true, channels_communities: true }, { kaption_links: false }]) { + const names = (await (await session(fakeRoom(features))).client.listTools()).tools.map((t) => t.name); + for (const name of LINK_TOOLS) expect(names, JSON.stringify(features)).not.toContain(name); + } + }); + + it("kaption-links.MCP.10 — appear with list_changed and are forwarded unchanged by name; hidden calls never reach the extension", async () => { + const room = fakeRoom({ manage_kaption: true }); + const s = await session(room); + const hidden: any = await s.client.callTool({ name: "create_tracked_links", arguments: { links: [{ url: "https://example.com" }] } }); + expect(hidden.isError).toBe(true); + expect(room.calls).toEqual([]); + room.features = { manage_kaption: true, kaption_links: true }; + await s.agent.refreshManageVisibility(); + await flush(); + expect(await s.manage()).toEqual(expect.arrayContaining(LINK_TOOLS)); + expect(s.changed.tools).toBeGreaterThan(0); + const calls: Array<[string, Record]> = [ + ["create_tracked_links", { links: [{ url: "https://example.com/menu", title: "Menu", post_id: "weekly-menu-48", chat_id: "120363000000000001@newsletter" }] }], + ["list_tracked_links", { q: "sale", limit: 10, cursor: "c_1", target_session: "s_2" }], + ["get_link_clicks", { link: "l_0123456789abcdef", granularity: "hour", from: "2026-11-20" }], + ["get_link_clicks", {}], + ]; + for (const [name, args] of calls) { + const res: any = await s.client.callTool({ name, arguments: args }); + expect(res.isError, name).toBeFalsy(); + } + expect(room.calls).toEqual(calls.map(([method, params]) => ({ method, params }))); + // The pinned schemas are enforced before forwarding: 0 or 21 links, a 101 limit, an unknown field or granularity. + for (const [name, args] of [ + ["create_tracked_links", { links: [] }], + ["create_tracked_links", { links: Array.from({ length: 21 }, () => ({ url: "https://example.com" })) }], + ["create_tracked_links", { links: [{ url: "https://example.com", phone: "x" }] }], + ["list_tracked_links", { limit: 101 }], + ["list_tracked_links", { limit: 2.5 }], + ["get_link_clicks", { granularity: "week" }], + ] as Array<[string, Record]>) { + const res: any = await s.client.callTool({ name, arguments: args }); + expect(res.isError, `${name} ${JSON.stringify(args)}`).toBe(true); + } + expect(room.calls).toHaveLength(calls.length); + }); +}); + describe("mcp-manage-kaption.LIST.2 an MCP session lists the manage tools from its extension's features", () => { it("hidden for an extension that said nothing, or when none is connected", async () => { expect(await (await session(fakeRoom({}))).manage()).toEqual([]); @@ -331,7 +399,7 @@ describe("mcp-manage-kaption.LIST.2 an MCP session lists the manage tools from i expect(room.watchers).toEqual(["ab".repeat(32)]); expect(await s.manage()).toEqual(["get_kaption_settings", "update_kaption_settings", "reconnect_kaption_connection", "kaption_help", "report_bug"]); - room.features = { manage_kaption: true, business_agent: true, plans: true, scheduled_status: true, channels_communities: true, export_chat: true }; + room.features = { manage_kaption: true, business_agent: true, plans: true, scheduled_status: true, channels_communities: true, export_chat: true, kaption_links: true }; await s.agent.refreshManageVisibility(); await flush(); expect(await s.manage()).toEqual(MANAGE_KAPTION_TOOLS); diff --git a/src/manage-kaption.ts b/src/manage-kaption.ts index 29db7df..f0bc193 100644 --- a/src/manage-kaption.ts +++ b/src/manage-kaption.ts @@ -32,6 +32,9 @@ export interface ManageFeatures { channels_communities?: boolean; /** chat-export.MCP.6 — MCP_EXPORT_CHAT on for this account (export_chat). */ export_chat?: boolean; + /** kaption-links.MCP.10 — MCP_KAPTION_LINKS on for this account (create_tracked_links, list_tracked_links, + * get_link_clicks). */ + kaption_links?: boolean; } /** mcp-manage-kaption.LIST.2 — which `features` key shows each tool. */ @@ -56,11 +59,15 @@ export const MANAGE_TOOL_FEATURE: Readonly> get_community: 'channels_communities', get_community_digest: 'channels_communities', export_chat: 'export_chat', + // kaption-links.MCP.10 — the Kaption Links tools, answered by the extension's account core. + create_tracked_links: 'kaption_links', + list_tracked_links: 'kaption_links', + get_link_clicks: 'kaption_links', }); export const MANAGE_KAPTION_TOOLS: readonly string[] = Object.freeze(Object.keys(MANAGE_TOOL_FEATURE)); -const FEATURE_KEYS: Array = ['manage_kaption', 'business_agent', 'plans', 'scheduled_status', 'channels_communities', 'export_chat']; +const FEATURE_KEYS: Array = ['manage_kaption', 'business_agent', 'plans', 'scheduled_status', 'channels_communities', 'export_chat', 'kaption_links']; /** Only booleans are kept; anything else (missing, "yes", 1) is unknown, which counts as no. */ export function readManageFeatures(features: unknown): ManageFeatures { diff --git a/src/relay.test.ts b/src/relay.test.ts index 6a2c86f..31f7ffe 100644 --- a/src/relay.test.ts +++ b/src/relay.test.ts @@ -77,14 +77,17 @@ describe("Tool registration", () => { "get_community", "get_community_digest", "export_chat", + "create_tracked_links", + "list_tracked_links", + "get_link_clicks", ]; - it("exports exactly 47 tools", () => { - expect(TOOLS).toHaveLength(47); + it("exports exactly 50 tools", () => { + expect(TOOLS).toHaveLength(50); }); it("keeps local API credentials off the public cloud tool surface", () => { - expect(CLOUD_TOOLS).toHaveLength(46); + expect(CLOUD_TOOLS).toHaveLength(49); expect(CLOUD_TOOLS.map((tool) => tool.name)).not.toContain("get_api_info"); }); diff --git a/src/test-support/mcp-links-tools.json b/src/test-support/mcp-links-tools.json new file mode 100644 index 0000000..919c79b --- /dev/null +++ b/src/test-support/mcp-links-tools.json @@ -0,0 +1,152 @@ +[ + { + "name": "create_tracked_links", + "title": "Create tracked links", + "description": "Turn up to 20 web addresses into Kaption short links (go.kaptionai.com/…) that count clicks, so the user can see who opened what they shared. Business and Business Agent plans. Use it before the user posts a link in a channel, a group or Status, or sends it to many people. Each link can have a title (shown only to the user) and, to group clicks by post, the post id and the chat it goes to (a channel id ending in @newsletter, a group id ending in @g.us, or status@broadcast; never a person). Only public http and https addresses can be tracked. Creating the same link again within 10 minutes answers the existing one. This only creates links: nothing is sent, and the short link sends visitors straight to the original address. When the account doesn't have the plan, the answer says which plan adds it and gives the checkout link.\n\nExamples:\n { links: [{ url: \"https://shop.example.com/sale\", title: \"Black Friday sale\" }] }\n { links: [{ url: \"https://example.com/menu\", post_id: \"weekly-menu-48\", chat_id: \"120363000000000001@newsletter\" }] }", + "inputSchema": { + "type": "object", + "properties": { + "links": { + "type": "array", + "minItems": 1, + "maxItems": 20, + "description": "The addresses to track (1 to 20)", + "items": { + "type": "object", + "properties": { + "url": { + "type": "string", + "description": "The full address, starting with https:// or http://" + }, + "title": { + "type": "string", + "description": "A name for the link the user will recognise (at most 120 characters)" + }, + "post_id": { + "type": "string", + "description": "Any id the user's post goes by, to group its clicks (at most 128 characters)" + }, + "chat_id": { + "type": "string", + "description": "The channel (…@newsletter), group (…@g.us) or status@broadcast the link is posted to" + } + }, + "required": [ + "url" + ], + "additionalProperties": false + } + }, + "target_session": { + "type": "string", + "description": "Session ID for multi-account routing" + } + }, + "required": [ + "links" + ], + "additionalProperties": false + }, + "annotations": { + "title": "Create tracked links", + "readOnlyHint": false, + "destructiveHint": false, + "idempotentHint": false, + "openWorldHint": true + } + }, + { + "name": "list_tracked_links", + "title": "List tracked links", + "description": "List the user's Kaption short links, newest first, each with its short address, the original address, title, post and chat, when it was made, and its clicks (total, unique visitors, last click). Unique visitors are an estimate. Filter by post_id, chat_id or q (words in the title or the address). Pages: when next_cursor is not null, call again with cursor = next_cursor. Changes nothing.\n\nExamples:\n { }\n { q: \"sale\", limit: 10 }\n { chat_id: \"120363000000000001@newsletter\" }", + "inputSchema": { + "type": "object", + "properties": { + "q": { + "type": "string", + "description": "Words in the title or the original address" + }, + "post_id": { + "type": "string", + "description": "Only the links of this post" + }, + "chat_id": { + "type": "string", + "description": "Only the links posted to this channel, group or status@broadcast" + }, + "limit": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "description": "Links per page (default 20, at most 100)" + }, + "cursor": { + "type": "string", + "description": "next_cursor of the previous page" + }, + "target_session": { + "type": "string", + "description": "Session ID for multi-account routing" + } + }, + "additionalProperties": false + }, + "annotations": { + "title": "List tracked links", + "readOnlyHint": true, + "destructiveHint": false, + "idempotentHint": true, + "openWorldHint": true + } + }, + { + "name": "get_link_clicks", + "title": "Get link clicks", + "description": "Read who clicked the user's Kaption short links. With link (the link id from list_tracked_links, or the short address such as https://go.kaptionai.com/Ab12Cd3): that link's clicks over time (per day, or per hour for the last 30 days), the countries, the sites the clicks came from and the device types. With post_id and/or chat_id: the clicks per post and chat (a channel, a group or Status). With neither: the account's totals and its 10 most clicked links. Link previews made by WhatsApp and other apps are not counted as clicks (bots shows how many were left out). Unique visitors are an estimate. Times are UTC. Business and Business Agent plans; otherwise the answer says which plan adds it. Changes nothing.\n\nExamples:\n { link: \"https://go.kaptionai.com/Ab12Cd3\" }\n { link: \"l_0123456789abcdef\", granularity: \"hour\", from: \"2026-11-20\" }\n { chat_id: \"120363000000000001@newsletter\" }\n { }", + "inputSchema": { + "type": "object", + "properties": { + "link": { + "type": "string", + "description": "The link id (l_…) or its short address" + }, + "post_id": { + "type": "string", + "description": "Clicks of this post's links" + }, + "chat_id": { + "type": "string", + "description": "Clicks of the links posted to this channel, group or status@broadcast" + }, + "granularity": { + "type": "string", + "enum": [ + "day", + "hour" + ], + "description": "With link: clicks per day (default) or per hour" + }, + "from": { + "type": "string", + "description": "Start, as a date or date and time (ISO 8601). Default: the last 30 days (2 days per hour)" + }, + "to": { + "type": "string", + "description": "End, as a date or date and time (ISO 8601). Default: now" + }, + "target_session": { + "type": "string", + "description": "Session ID for multi-account routing" + } + }, + "additionalProperties": false + }, + "annotations": { + "title": "Get link clicks", + "readOnlyHint": true, + "destructiveHint": false, + "idempotentHint": true, + "openWorldHint": true + } + } +] diff --git a/src/tools.ts b/src/tools.ts index d369c06..5a1836d 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -895,6 +895,71 @@ export const TOOLS: ToolDefinition[] = [ target_session: z.string().optional().describe("Session ID for multi-account routing"), }), }, + // kaption-links.MCP.1-3, MCP.10 (kaptionai features/links/kaption-links.feature.yaml) — Kaption Links, the link + // shortener with click analytics (Business plans). Verbatim from kaptionai kext/scripts/mcp-links-tools.json (pinned in + // src/test-support/mcp-links-tools.json), target_session included like every routed tool. The relay never answers + // them: listed only while a connected extension said features.kaption_links (manage-kaption.ts) and forwarded by name. + { + name: "create_tracked_links", + description: [ + "Turn up to 20 web addresses into Kaption short links (go.kaptionai.com/…) that count clicks, so the user can see who opened what they shared. Business and Business Agent plans. Use it before the user posts a link in a channel, a group or Status, or sends it to many people. Each link can have a title (shown only to the user) and, to group clicks by post, the post id and the chat it goes to (a channel id ending in @newsletter, a group id ending in @g.us, or status@broadcast; never a person). Only public http and https addresses can be tracked. Creating the same link again within 10 minutes answers the existing one. This only creates links: nothing is sent, and the short link sends visitors straight to the original address. When the account doesn't have the plan, the answer says which plan adds it and gives the checkout link.", + "", + "Examples:", + " { links: [{ url: \"https://shop.example.com/sale\", title: \"Black Friday sale\" }] }", + " { links: [{ url: \"https://example.com/menu\", post_id: \"weekly-menu-48\", chat_id: \"120363000000000001@newsletter\" }] }", + ].join("\n"), + inputSchema: z.object({ + links: z.array( + z.object({ + url: z.string().describe("The full address, starting with https:// or http://"), + title: z.string().optional().describe("A name for the link the user will recognise (at most 120 characters)"), + post_id: z.string().optional().describe("Any id the user's post goes by, to group its clicks (at most 128 characters)"), + chat_id: z.string().optional().describe("The channel (…@newsletter), group (…@g.us) or status@broadcast the link is posted to"), + }).strict(), + ).min(1).max(20).describe("The addresses to track (1 to 20)"), + target_session: z.string().optional().describe("Session ID for multi-account routing"), + }).strict(), + }, + { + name: "list_tracked_links", + description: [ + "List the user's Kaption short links, newest first, each with its short address, the original address, title, post and chat, when it was made, and its clicks (total, unique visitors, last click). Unique visitors are an estimate. Filter by post_id, chat_id or q (words in the title or the address). Pages: when next_cursor is not null, call again with cursor = next_cursor. Changes nothing.", + "", + "Examples:", + " { }", + " { q: \"sale\", limit: 10 }", + " { chat_id: \"120363000000000001@newsletter\" }", + ].join("\n"), + inputSchema: z.object({ + q: z.string().optional().describe("Words in the title or the original address"), + post_id: z.string().optional().describe("Only the links of this post"), + chat_id: z.string().optional().describe("Only the links posted to this channel, group or status@broadcast"), + limit: z.number().int().min(1).max(100).optional().describe("Links per page (default 20, at most 100)"), + cursor: z.string().optional().describe("next_cursor of the previous page"), + target_session: z.string().optional().describe("Session ID for multi-account routing"), + }).strict(), + }, + { + name: "get_link_clicks", + description: [ + "Read who clicked the user's Kaption short links. With link (the link id from list_tracked_links, or the short address such as https://go.kaptionai.com/Ab12Cd3): that link's clicks over time (per day, or per hour for the last 30 days), the countries, the sites the clicks came from and the device types. With post_id and/or chat_id: the clicks per post and chat (a channel, a group or Status). With neither: the account's totals and its 10 most clicked links. Link previews made by WhatsApp and other apps are not counted as clicks (bots shows how many were left out). Unique visitors are an estimate. Times are UTC. Business and Business Agent plans; otherwise the answer says which plan adds it. Changes nothing.", + "", + "Examples:", + " { link: \"https://go.kaptionai.com/Ab12Cd3\" }", + " { link: \"l_0123456789abcdef\", granularity: \"hour\", from: \"2026-11-20\" }", + " { chat_id: \"120363000000000001@newsletter\" }", + " { }", + ].join("\n"), + inputSchema: z.object({ + link: z.string().optional().describe("The link id (l_…) or its short address"), + post_id: z.string().optional().describe("Clicks of this post's links"), + chat_id: z.string().optional().describe("Clicks of the links posted to this channel, group or status@broadcast"), + granularity: z.enum(["day", "hour"]).optional().describe("With link: clicks per day (default) or per hour"), + from: z.string().optional().describe("Start, as a date or date and time (ISO 8601). Default: the last 30 days (2 days per hour)"), + to: z.string().optional().describe("End, as a date or date and time (ISO 8601). Default: now"), + target_session: z.string().optional().describe("Session ID for multi-account routing"), + }).strict(), + }, ]; /** @@ -979,6 +1044,9 @@ const TOOL_TITLES: Record = { list_scheduled_channel_posts: "List scheduled channel posts", get_community_digest: "Get community digest", export_chat: "Export chat", + create_tracked_links: "Create tracked links", + list_tracked_links: "List tracked links", + get_link_clicks: "Get link clicks", }; // Safety annotations use OpenAI's review definitions: @@ -1038,6 +1106,10 @@ const TOOL_ANNOTATIONS: Record = { list_scheduled_channel_posts: { title: "List scheduled channel posts", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }, get_community_digest: { title: "Get community digest", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }, export_chat: { title: "Export chat", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }, + // kaption-links.MCP.1-3 — as pinned in kaptionai kext/scripts/mcp-links-tools.json (a write that is not destructive). + create_tracked_links: { title: "Create tracked links", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }, + list_tracked_links: { title: "List tracked links", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }, + get_link_clicks: { title: "Get link clicks", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }, }; // mcp.TOOLS — directories (Claude's Connectors Directory) read the listing name from annotations.title, so every tool @@ -1121,6 +1193,15 @@ export function zodToJsonSchema(schema: z.ZodType): Record { } if (schema instanceof z.ZodNumber) { + // kaption-links.MCP.2 — an .int() number is published as an integer with its bounds (minimum/maximum), as the + // MCP SDK lists it; other numbers stay a plain number. + if (schema.isInt) { + const result: Record = { type: "integer" }; + if (schema.minValue !== null) result.minimum = schema.minValue; + if (schema.maxValue !== null) result.maximum = schema.maxValue; + if (schema.description) result.description = schema.description; + return result; + } const result: Record = { type: "number" }; if (schema.description) result.description = schema.description; return result; @@ -1161,6 +1242,8 @@ export function zodToJsonSchema(schema: z.ZodType): Record { const result: Record = { type: "array", items: zodToJsonSchema(schema.element) }; if (schema.description) result.description = schema.description; // whatsapp-channels-communities.HUB.2 — a .max(n) on an array is published as maxItems. + // kaption-links.MCP.1 — and a .min(n) as minItems. + if (schema._def.minLength) result.minItems = schema._def.minLength.value; if (schema._def.maxLength) result.maxItems = schema._def.maxLength.value; return result; }