UNPKG

@withpica/mcp-server

Version:

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

219 lines • 14.7 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. import { formatStructured, formatSuccess } from "@withpica/mcp-utils"; export class ShareSendTools { pica; constructor(pica) { this.pica = pica; } getTools() { return [ { definition: { name: "pica_share_send", scope: "write:catalog", audiences: ["stdio", "http"], tier: "write", workflows: "infrastructure", vernacular_kind: "creator-entry", description: "Use when the user asks: 'send this song to my publisher', " + "'share this work with sarah', 'email the report to my manager', " + "'shoot this over to <name>', 'forward to <email>'. " + "Sends a withPICA-branded email containing a scoped share link " + "share-link to a named recipient. To send SEVERAL works — an " + "album, a pitch of three works — pass entity_ids: the recipient " + "gets ONE email and ONE link with a track list, never one per " + "work. The page the recipient opens shows each work's audio, " + "identifiers (ISRC, ISWC, label), genre, lyrics, and credits " + "(names and roles); split percentages are withheld unless " + "include_splits is true. Recipients can be PICA users, " + "existing org collaborators, or any external email address. " + "A first send to a NEW outside address does not go out at once. " + "With the organisation's own key it returns " + "outcome 'confirmation_required' and a confirm_token: check the " + "address with the user, then re-call with the same arguments " + "plus confirm_token (one use, 10 minutes). Through a connected " + "assistant (Claude, ChatGPT, an agent grant) it returns outcome " + "'owner_approval_required': the owner approves it in PICA and it " + "goes out then; tell them, and don't re-send. Sender capped at 20 external " + "sends / 24h. Recipient capped at 20 shares / 30 days from all senders. " + "Email From is always noreply@withpica.com; " + "Reply-to is the sender's email; recipient can report unwanted " + "contact via a footer link in the email. " + "This sends the WORK itself, as a scoped share link the " + "recipient can open. Use pica_send_message instead to invite " + "someone or to ask them for a file — that is the Send Hub outbox, " + "and it carries no link to an asset. Use pica_share_links_create " + "when the user wants a link to copy and no email sent. " + "To email a link that already exists (made with pica_share_links_create, " + "or in the browser), pass share_link_id instead of entity_id(s): the link's " + "own settings are sent as they are, and on a specific-people link the " + "address must be one of its recipients, who gets their own URL.", inputSchema: { type: "object", properties: { entity_type: { type: "string", enum: ["recording", "work", "audio_file", "document"], description: "Asset class. v1: only 'work' is supported; other values return ENTITY_TYPE_NOT_SUPPORTED.", }, entity_id: { type: "string", description: "UUID of the work being shared. Give this OR entity_ids.", }, entity_ids: { type: "array", items: { type: "string", format: "uuid" }, description: "UUIDs of several works to send together as one link and one email, in the order the recipient should see them (max 50, one organisation). Give this OR entity_id.", }, include_splits: { type: "boolean", description: "Default false. true shows each collaborator's split percentage to the recipient. Credits (names and roles) are always shown; a co-writer's share only goes out when the sender asks for it.", }, recipient: { type: "object", description: "Who to send to. { kind: 'user_id' | 'collaborator_id' | 'email', value: <id-or-email> }. Internal users and existing org collaborators are detected automatically when kind='email'; otherwise the address is classified external and goes through the first-send confirmation + marketing-guard.", properties: { kind: { type: "string", enum: ["user_id", "collaborator_id", "email"], description: "user_id = existing PICA user; collaborator_id = a person from the sender's org; email = arbitrary address (internal user / collaborator detected automatically; otherwise classified external).", }, value: { type: "string" }, }, required: ["kind", "value"], }, note: { type: "string", description: "Optional message from the sender (≤500 chars). Rendered in the email above the share-link CTA and on the page the link opens.", }, expires_in_days: { type: "number", description: "Share-link TTL in days. Default 30, max 90.", }, scope: { type: "string", enum: ["view", "view+download"], description: "Default 'view'. 'view+download' allows the recipient to download attached files.", }, confirm_token: { type: "string", description: "The confirm_token a 'confirmation_required' answer gave. Send it back with the same arguments once the user has checked the address. One use, 10 minutes.", }, included_file_ids: { type: "array", items: { type: "string", format: "uuid" }, description: "optional: audio_files ids to include in the share (across every work being sent); omit to share all of the works' files", }, share_link_id: { type: "string", format: "uuid", description: "Email this existing share link (from pica_share_links_create or pica_share_links_query) instead of making one. Not with entity_id(s), expires_in_days, scope, included_file_ids or include_splits: the link's own settings stand.", }, }, required: ["entity_type", "recipient"], }, // `destructiveHint` was declared true and read false: `tier` drives // that hint (ADR-230), and this tool is tier "write" / risk // "mutating" — it creates a share link and sends a mail, destroying // nothing. The friction it does need is in the route: a first send // to a new outside address waits for a server-minted confirm token // or the owner's approval (lib/services/share-send-confirm.ts), not // in the hint. `openWorldHint` stays true and is the // honest warning here: the effect leaves PICA and cannot be recalled. annotations: { destructiveHint: false, openWorldHint: true }, }, executor: this.shareSend.bind(this), }, ]; } async shareSend(args) { try { const result = await this.pica.shareSend.send({ entity_type: args.entity_type, entity_id: typeof args.entity_id === "string" ? args.entity_id : undefined, entity_ids: Array.isArray(args.entity_ids) ? args.entity_ids : undefined, include_splits: args.include_splits === true ? true : undefined, recipient: args.recipient, note: args.note, expires_in_days: args.expires_in_days, scope: args.scope, confirm_token: typeof args.confirm_token === "string" ? args.confirm_token : undefined, included_file_ids: Array.isArray(args.included_file_ids) ? args.included_file_ids : undefined, share_link_id: typeof args.share_link_id === "string" ? args.share_link_id : undefined, }); if ("outcome" in result) { // Not sent yet: a first send to a new outside address. return formatStructured({ ...result, suggestion: suggestionFor(result.outcome === "owner_approval_required" ? "OWNER_APPROVAL_REQUIRED" : "FIRST_EXTERNAL_SEND_CONFIRMATION_REQUIRED"), next_tool: result.outcome === "confirmation_required" ? "pica_share_send" : undefined, }, "pica_share_send — not sent yet"); } return formatSuccess(`shared via withPICA — ${result.recipient_resolution.classification}`, result); } catch (e) { const errCode = e?.error_code ?? e?.code ?? "SHARE_SEND_ERROR"; const status = e?.status ?? e?.statusCode; return formatStructured({ error: e?.message ?? String(e), error_code: errCode, ...(typeof status === "number" ? { status } : {}), suggestion: suggestionFor(errCode), next_tool: "pica_share_send", }, "pica_share_send — error"); } } } function suggestionFor(code) { switch (code) { case "FIRST_EXTERNAL_SEND_CONFIRMATION_REQUIRED": return "First time sending to this address. Check it with the user, then re-call with the same arguments plus confirm_token."; case "OWNER_APPROVAL_REQUIRED": return "First time sending to this address, so PICA has asked the owner to approve it. Tell the user it's waiting for the owner's yes; it goes out once they approve. Don't send it again. To check, call pica_approval_status with the approval's approval_reference."; case "CONFIRM_TOKEN_INVALID": return "That confirm_token was used, expired, or was for a different send. Call again without it to get a new one."; case "ROLE_ADDRESS_REJECTED": return "The address looks like a role/system inbox (noreply@, postmaster@, abuse@, etc). Pick the recipient's personal email instead."; case "RECIPIENT_VOLUME_EXCEEDED": return "This person has been sent 20 shares through withPICA in the last 30 days. Wait for the window to clear, or contact them another way."; case "SENDER_RATE_LIMIT_EXCEEDED": return "You've sent 20+ external shares in the last 24h. Wait an hour and retry, or send to internal collaborators in the meantime."; case "ENTITY_NOT_FOUND": return "One or more works weren't found in your catalog (missing_ids names them; merged-away works count as missing). Verify with pica_works_get."; case "ENTITY_ID_REQUIRED": return "Pass entity_id (one work) or entity_ids (several works)."; case "TOO_MANY_ENTITIES": return "One send carries at most 50 works. Split the set, or share the release with pica_share_links_create (release_id)."; case "ENTITIES_SPAN_ORGS": return "All works in one send must belong to the same organisation. Send each organisation's works separately."; case "ENTITY_TYPE_NOT_SUPPORTED": return "v1 supports entity_type='work' only. Recording/audio_file/document share-send is on the roadmap."; case "FORBIDDEN": return "You're not a member of the asset's organisation. Switch context with pica_organisations_switch or share an asset you own."; case "LINK_SETTINGS_FIXED": return "With share_link_id the link's own settings are sent; drop entity_id(s), expires_in_days, scope, included_file_ids and include_splits, or make a new link instead."; case "SHARE_LINK_NOT_FOUND": return "That share link isn't in your catalogue. List them with pica_share_links_query."; case "SHARE_LINK_NOT_LIVE": return "The link is turned off or expired. Turn it back on with pica_share_links_update, or make a new one."; case "RECIPIENT_NOT_ON_LINK": return "On a specific-people link only its recipients can be sent their own URL. Make a link that names this person, or send them a different link."; case "RECIPIENT_NOT_FOUND": return "The recipient lookup failed. For collaborator_id, verify it's in your current org. For user_id, confirm the user exists."; default: return "Re-check the entity_id and recipient shape against the tool description."; } } //# sourceMappingURL=share-send.js.map