@withpica/mcp-server
Version:
MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog
184 lines • 9.1 kB
JavaScript
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved.
import { formatSuccess } from "@withpica/mcp-utils";
/** Why they have access, in the panel's words (WhoHasAccess.tsx reasonLine). */
export function reasonWords(l) {
return (l.reasons ?? [])
.map((r) => {
switch (r) {
case "master_owner":
return "you invited them as the master owner";
case "invite":
return l.status === "pending"
? "you invited them; they haven't accepted yet"
: "accepted your co-writer invite";
case "claim":
return "claimed their writer profile";
case "agreement":
return "signed a split sheet or agreement with you";
default:
return "you shared it with them";
}
})
.join(" · ");
}
/** The panel's words for a line (WhoHasAccess.tsx who + sideLine), so both read alike. */
export function lineWords(l) {
const account = l.granteeOrgName ?? l.pendingEmail ?? "someone who hasn't joined yet";
const who = l.personName ? `${l.personName} (${account})` : account;
const side = l.side === "both"
? "writing and master"
: l.side === "composition"
? "writing"
: l.recordingTitle
? `master · ${l.recordingTitle}`
: "master";
const can = l.canDo === "look_after_master"
? "can look after the master details"
: l.status === "pending"
? "can view once they accept"
: "can view";
const why = reasonWords(l);
return `${who} — ${side} · ${can}${why ? ` (${why})` : ""}`;
}
function failure(text) {
return { content: [{ type: "text", text }], isError: true };
}
export class SongAccessTools {
pica;
constructor(pica) {
this.pica = pica;
}
getTools() {
return [
{
definition: {
name: "pica_works_access_query",
scope: "read:catalog",
audiences: ["stdio", "http"],
tier: "read",
description: "Use when the user asks: 'who has access to this song?', 'who can see my song?', 'who did I share this with?'. " +
"Lists everyone outside your catalogue who can see one of your works: one line per organisation or invited address (with the person in your catalogue behind it when known, and why they have access: co-writer invite, claimed profile, signed agreement, master owner, or shared), the side they see (writing; master and which recording; or both for an old share), and what they can do — view, or look after the master details. " +
"Pending lines are invitations not yet accepted. A line with wider_arrangement is part of a relationship covering other recordings too: change it from people & access, not with pica_works_access_remove. " +
"Only your own works; another catalogue's work is not found. " +
"→ then: pica_works_access_remove (end a line, after the user confirms)",
workflows: "infrastructure",
vernacular_kind: "creator-entry",
inputSchema: {
type: "object",
properties: {
work_id: {
type: "string",
description: "UUID of one of your works (works).",
},
},
required: ["work_id"],
},
nextSteps: [
{
tool: "pica_works_access_remove",
reason: "End one line's access, using its key, once the user confirms.",
when: "on_success",
},
],
},
executor: this.query.bind(this),
},
{
definition: {
name: "pica_works_access_remove",
scope: "write:catalog",
audiences: ["stdio", "http"],
tier: "destructive",
description: "End one line of access to one of your works, by the key pica_works_access_query returned. " +
"Ends every share behind the line, and a master owner's edit too (edit first, so a failure never leaves edit without view). " +
"If still_shared comes back true, they can still see the work: tell the user and offer to try again (a retry touches only what is still live). " +
"If kept_reason is set, they still look after this master through a wider arrangement: point the user to people & access. " +
"Owners and admins only. Sends no email.",
workflows: "infrastructure",
vernacular_kind: "specialist",
vernacular_reason: "Destructive; invoked by exact name after the user confirms which line to end.",
inputSchema: {
type: "object",
properties: {
work_id: {
type: "string",
description: "UUID of the work.",
},
key: {
type: "string",
description: "The line's key, exactly as pica_works_access_query returned it.",
},
},
required: ["work_id", "key"],
},
nextSteps: [
{
tool: "pica_works_access_query",
reason: "Read the lines again to confirm what is left.",
when: "on_success",
},
],
},
executor: this.remove.bind(this),
},
];
}
async query(args) {
const workId = typeof args.work_id === "string" ? args.work_id : "";
if (!workId)
return failure("work_id is required.");
try {
const lines = (await this.pica.songAccess.list(workId));
const summary = lines.length === 0
? "Only your catalogue can see this work."
: `${lines.length} ${lines.length === 1 ? "line" : "lines"} of access:\n` +
lines.map((l) => `- ${lineWords(l)}`).join("\n");
return formatSuccess(summary, {
lines: lines.map((l) => ({
key: l.key,
who: l.granteeOrgName ?? l.pendingEmail,
person: l.personName ?? null,
reasons: l.reasons ?? [],
side: l.side,
recording_title: l.recordingTitle,
status: l.status,
can_do: l.canDo,
wider_arrangement: l.widerArrangement,
words: lineWords(l),
})),
});
}
catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (/404|not found/i.test(msg))
return failure("That work isn't in your catalogue, so its access can't be listed.");
return failure(`Couldn't read who has access: ${msg}`);
}
}
async remove(args) {
const workId = typeof args.work_id === "string" ? args.work_id : "";
const key = typeof args.key === "string" ? args.key : "";
if (!workId || !key)
return failure("work_id and key are required.");
try {
const r = await this.pica.songAccess.remove(workId, key);
const text = r.still_shared
? "Removal didn't finish: they can still see this work. Offer to try again."
: r.kept_reason
? "Removed their share of this work, but they still look after this master through a wider arrangement — change that on people & access."
: "Removed. They can no longer see this work.";
return formatSuccess(text, r);
}
catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (/ACCESS_NOT_REMOVED/.test(msg))
return failure("Access was not removed: they can still see this work. Try again.");
if (/403|restricted to owners and admins/i.test(msg))
return failure("Only the catalogue's owners and admins can remove access.");
if (/404|not found/i.test(msg))
return failure("That work isn't in your catalogue.");
return failure(`Couldn't remove access: ${msg}`);
}
}
}
//# sourceMappingURL=song-access.js.map