@withpica/mcp-server
Version:
MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog
102 lines • 4.37 kB
JavaScript
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved.
import { typedError } from "./error-envelope.js";
import { parseApiErrorBody } from "./api-error-body.js";
import { viewUrl, viewUrlLine } from "../lib/view-url.js";
/** e1's words, 2026-11-23 (ADR-362 slice 3), pinned by view-links.test.ts. */
export const VIEW_CREATE_DESCRIPTION = "Makes a link that opens a set of works, recordings or people from this catalogue in pica, with an optional note. " +
"It changes nothing in the catalogue. Pass kind (works, recordings or people), 1 to 200 ids from this catalogue, " +
"and an optional note of up to 200 characters. The note is shown only to the person you're working for, so write it to them. " +
"Returns view_url: share it exactly as returned and never build a pica link yourself. " +
"The link opens only for signed-in members of this catalogue and lasts 90 days. " +
"Answer in chat as well; the link is an extra.";
const NOUN = {
works: ["work", "works"],
recordings: ["recording", "recordings"],
people: ["person", "people"],
};
/** e1's success line (2026-11-23), before the "open it in pica:" line. */
export function viewCreatedLine(n, kind) {
const noun = NOUN[kind][n === 1 ? 0 : 1];
return `Made a link to ${n} ${noun}. It opens only for members of this catalogue and lasts 90 days.`;
}
/** The route's refusal codes, passed through with its words. */
const REFUSALS = new Set([
"VALIDATION_ERROR",
"NOT_IN_CATALOGUE",
"RATE_LIMITED",
"UNAVAILABLE",
]);
export class ViewLinkTools {
pica;
constructor(pica) {
this.pica = pica;
}
getTools() {
return [
{
definition: {
name: "pica_view_create",
scope: "read:catalog",
audiences: ["stdio", "http", "public"],
tier: "write",
description: VIEW_CREATE_DESCRIPTION,
workflows: "infrastructure",
vernacular_kind: "specialist",
vernacular_reason: "Called by the AI to hand over a list it built; people ask for the list, not for the tool.",
inputSchema: {
type: "object",
properties: {
kind: {
type: "string",
enum: ["works", "recordings", "people"],
description: "What the ids are",
},
ids: {
type: "array",
items: { type: "string" },
minItems: 1,
maxItems: 200,
description: "1 to 200 ids from this catalogue",
},
note: {
type: "string",
maxLength: 200,
description: "Optional, up to 200 characters, shown only to the person you're working for",
},
},
required: ["kind", "ids"],
},
},
executor: this.create.bind(this),
},
];
}
async create(args) {
let created;
try {
created = await this.pica.viewLinks.create({
kind: args.kind,
ids: args.ids,
...(typeof args.note === "string" ? { note: args.note } : {}),
});
}
catch (err) {
const body = parseApiErrorBody(err);
if (body.code && REFUSALS.has(body.code) && body.message)
return typedError(body.code, body.message);
throw err;
}
const url = viewUrl({ saved_view_id: created.id });
const kind = args.kind;
const text = `${viewCreatedLine(created.count, kind)}\n\n${viewUrlLine(url)}`;
return {
content: [{ type: "text", text }],
structuredContent: {
view_url: url,
count: created.count,
expires_at: created.expires_at,
},
};
}
}
//# sourceMappingURL=view-links.js.map