UNPKG

@withpica/mcp-server

Version:

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

160 lines • 8.21 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. import { formatSuccess, formatValidationError } from "@withpica/mcp-utils"; import { webBaseUrl } from "../lib/view-url.js"; function foundPageUrl() { return `${webBaseUrl()}/inspect/found`; } function errorResult(text) { return { content: [{ type: "text", text: `Error: ${text}` }], isError: true }; } const idArgs = () => ({ type: "object", properties: { source_key: { type: "string", description: "The finding's group sourceKey, from pica_found_query (e.g. 'enrichment').", }, id: { type: "string", description: "The finding's id, from that group's items in pica_found_query.", }, }, required: ["source_key", "id"], }); export class FoundTools { pica; constructor(pica) { this.pica = pica; } getTools() { return [ { definition: { name: "pica_found_query", scope: "read:catalog", audiences: ["stdio", "http"], tier: "read", description: "Use when the user asks: 'what did PICA find', 'anything for me to review', 'what's waiting on the found page'. " + "The review queue on PICA's found page, exactly as the page shows it: findings grouped by source and confidence band (high or low), each group with its full `count`, and each finding with what accepting it would change and the evidence for it. " + "Each group lists up to items_per_group findings (default 10); `items_cut` says how many more it holds, so never say a group has only the ones listed. " + "When `incomplete` is set, the check for works spelled almost the same didn't finish on a very large catalogue: never tell the user there are no near-duplicates; say that check didn't finish. " + "Explain each finding in plain words and ask the user yes or no, then use pica_found_accept or pica_found_dismiss with the group's sourceKey and the finding's id. " + "Duplicates (people, works, recordings, releases) can be dismissed here but are merged only by the user on the found page.", workflows: "infrastructure", vernacular_kind: "specialist", vernacular_reason: "Specialist context; not yet covered by the Creator Question Atlas.", inputSchema: { type: "object", properties: { source_key: { type: "string", description: "Optional. Only this source's groups (a sourceKey from a previous answer).", }, items_per_group: { type: "number", minimum: 1, maximum: 100, description: "Optional. Findings listed per group. Default 10, max 100.", }, }, }, }, executor: this.query.bind(this), }, { definition: { name: "pica_found_accept", scope: "write:catalog", audiences: ["stdio", "http"], tier: "write", description: "Use when the user says yes to one finding from pica_found_query: 'yes, add that', 'that's right'. " + "Accepts one finding, as the found page's accept does, and saves what it proposes to the catalogue. Only after the user said yes to that finding. " + "A duplicate (merge) can't be accepted by an AI: it is refused with FOUND_MERGE_ON_PAGE and nothing is merged. Tell the user to merge it on the found page, or dismiss it with pica_found_dismiss if they're different. " + "The same goes for choosing which of two values to keep (sourceKey 'alternatives'): refused with FOUND_CHOICE_ON_PAGE, and the user chooses on the found page. " + "If PICA can't save it, the answer says why in words to pass on; nothing was saved.", workflows: "infrastructure", vernacular_kind: "specialist", vernacular_reason: "Specialist context; not yet covered by the Creator Question Atlas.", inputSchema: idArgs(), }, executor: this.accept.bind(this), }, { definition: { name: "pica_found_dismiss", scope: "write:catalog", audiences: ["stdio", "http"], tier: "write", description: "Use when the user says no to one finding from pica_found_query: 'no, that's wrong', 'they're different people'. " + "Dismisses one finding from any source, as the found page's dismiss does. For a duplicate it records that the two are different, so the pair isn't offered again. Only after the user said no to that finding.", workflows: "infrastructure", vernacular_kind: "specialist", vernacular_reason: "Specialist context; not yet covered by the Creator Question Atlas.", inputSchema: idArgs(), }, executor: this.dismiss.bind(this), }, ]; } async query(args) { const queue = await this.pica.found.query({ source_key: typeof args.source_key === "string" ? args.source_key : undefined, items_per_group: typeof args.items_per_group === "number" ? args.items_per_group : undefined, }); const summary = queue.total === 0 ? "nothing is waiting on the found page." : `${queue.total} waiting on the found page, in ${queue.groups.length} groups.`; return formatSuccess(summary, { ...queue, found_url: foundPageUrl() }); } async accept(args) { const bad = checkIdArgs(args); if (bad) return bad; const outcome = await this.pica.found.accept(args.source_key, args.id); return oneIdAnswer(outcome, args.id, "accepted."); } async dismiss(args) { const bad = checkIdArgs(args); if (bad) return bad; const outcome = await this.pica.found.dismiss(args.source_key, args.id); return oneIdAnswer(outcome, args.id, "dismissed."); } } function checkIdArgs(args) { if (typeof args.source_key !== "string" || args.source_key.trim() === "") { return formatValidationError({ source_key: "source_key is required (a group's sourceKey from pica_found_query)", }); } if (typeof args.id !== "string" || args.id.trim() === "") { return formatValidationError({ id: "id is required (a finding's id from pica_found_query)", }); } return null; } /** * The door answers per id (applied / failed / skipped). For one id that is * one answer: saved, not saved with the row's own words (another * catalogue's id reads "not found in this organisation", never whether it * exists elsewhere), or already decided. */ export function oneIdAnswer(outcome, id, done) { if (outcome.applied > 0) { return formatSuccess(done, { ...outcome, found_url: foundPageUrl() }); } const failed = outcome.failed?.find((f) => f.id === id); if (failed) return errorResult(`not saved: ${failed.error}`); if (outcome.skipped?.includes(id)) { const reason = outcome.skippedReasons?.[id]; return formatSuccess(reason ? `nothing to do: ${reason}` : "nothing to do: it was already decided.", { ...outcome, found_url: foundPageUrl() }); } return errorResult("not saved: PICA didn't report an answer for that finding."); } //# sourceMappingURL=found.js.map