UNPKG

@withpica/mcp-server

Version:

MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog

138 lines • 7.25 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. /* eslint-disable @typescript-eslint/no-explicit-any -- ToolExecutor signature uses Record<string, any> */ /** * The in-chat confirm card (ADR-152 amendment 2026-11-11, slice 2a). * * `pica_credits_card` shows who on a song has confirmed their part, who has * been asked, and who hasn't, in a card (`ui://pica/confirm`). From the card * the user can: * - confirm their own parts: one tap opens the song's page on PICA, signed * in, where "these are mine" answers it. A confirmation is the person's * own answer, so it is never made from the chat: the own-parts route * refuses any connected app (requirePersonDecision, ADR-355 C2). * - ask the people not asked yet: the card asks yes first, then calls * pica_credits_ask_to_confirm once per person (the same ask, rate limit * and 24-hour repeat guard as everywhere else, confirm-ask.ts). * Every client without cards gets the same facts as text. */ import { safeViewUrl } from "../lib/view-url.js"; import { deriveWebBaseUrl } from "./app-tools.js"; const TOOL_NAME = "pica_credits_card"; export const CONFIRM_CARD_URI = "ui://pica/confirm"; const STEP_LABEL = { writers: "writers", master_owner: "master owners", }; export class CreditsCardTools { pica; constructor(pica) { this.pica = pica; } getTools() { return [ { definition: { name: TOOL_NAME, scope: "read:catalog", audiences: ["stdio", "http"], // ADR-352 amendment 2026-11-12: on ChatGPT's curated list. hosts: ["openai"], tier: "read", description: "Use when the user asks: 'who has confirmed their credit on X?', " + "'who still hasn't checked their credits?', 'has everyone " + "confirmed?', 'show me the confirmations', 'ask the others to " + "confirm'. It answers for one work. No call lists everyone " + "unconfirmed across the catalogue, so for that, ask the user which " + "songs, or call it once per work. Shows who on a work has confirmed their part, " + "who has been asked, and who hasn't yet. Call it directly: Claude's " + "chat apps and ChatGPT show it as a card, where the user can ask the " + "people not asked yet (the card asks the user to say yes first) and open the " + "work on PICA to confirm their own part. Every other client gets " + "the same list as text. Confirming is always the person's own " + "answer on PICA, never made from the chat: say 'asked', never " + "'confirmed', for someone you asked. → then: " + "pica_credits_ask_to_confirm (ask one person by name), " + "pica_credits_list (the credits and splits themselves)", // ChatGPT's curated list carries neither tool named above, so its // text points at the card's own button and the PICA link instead. hostDescriptions: { openai: "Use when the user asks: 'who has confirmed their credit on X?', " + "'has everyone confirmed?', 'show me the confirmations', 'ask the " + "others to confirm'. Shows who on a work has confirmed their part, " + "who has been asked, and who hasn't yet, as a card. On the card the " + "user can ask the people not asked yet (the card asks the user to say yes " + "first) and open the work on PICA. Confirming is always the " + "person's own answer on PICA, never made from the chat: say " + "'asked', never 'confirmed', for someone the card asked. To change " + "the credits themselves, give the user the PICA link in the result.", }, workflows: ["work-credits-required"], vernacular_kind: "creator-entry", inputSchema: { type: "object", properties: { work_id: { type: "string", description: "The song." }, }, required: ["work_id"], }, annotations: { title: "show who has confirmed on a song", readOnlyHint: true, }, _meta: { ui: { resourceUri: CONFIRM_CARD_URI } }, }, executor: this.show.bind(this), }, ]; } async show(args) { const workId = args?.work_id; // A UUID only: it goes into the SDK's URL path and the card's song link. if (typeof workId !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(workId)) { return errorResult("work_id is required. Find the song with pica_works_query."); } let status; try { status = await this.pica.credits.confirmStatus(workId); } catch { return errorResult("couldn't read who has confirmed on this work. Check the id with pica_works_query."); } const groups = (status?.groups ?? []).map((g) => ({ step: g.step, label: STEP_LABEL[g.step] ?? g.step, people: g.people, })); const songUrl = safeViewUrl({ entity: { kind: "work", id: workId } }) ?? `${deriveWebBaseUrl()}/inspect`; const everyone = groups.flatMap((g) => g.people); const count = (s) => everyone.filter((p) => p.state === s).length; const lines = groups .filter((g) => g.people.length > 0) .map((g) => `${g.label}: ` + g.people.map((p) => `${p.name} (${stateWords(p)})`).join(", ")); const summary = everyone.length === 0 ? `No writers or master owners on this work yet. Add them on PICA: ${songUrl}.` : `${count("confirmed")} confirmed, ${count("asked") + count("held")} asked, ` + `${count("not_asked")} not asked yet. ${lines.join(". ")}. ` + `To confirm their own part, the user opens the work on PICA: ${songUrl}.`; return { content: [{ type: "text", text: summary }], structuredContent: { work_id: workId, song_url: songUrl, groups }, }; } } function stateWords(p) { if (p.state === "confirmed") return "confirmed"; if (p.state === "asked") return "asked"; if (p.state === "held") return "asked, waiting for an owner's ok"; return p.has_email ? "not asked yet" : "not asked yet, no email on record"; } function errorResult(text) { return { content: [{ type: "text", text }], isError: true }; } //# sourceMappingURL=credits-card.js.map