UNPKG

@withpica/mcp-server

Version:

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

194 lines • 10.6 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. import { formatSuccess } from "@withpica/mcp-utils"; import { typedError } from "./error-envelope.js"; export class DirectoryTools { pica; constructor(pica) { this.pica = pica; } getTools() { return [ { definition: { name: "pica_directory_settings", scope: "admin", audiences: ["stdio", "http", "public"], tier: "read", description: "See your catalogue's directory settings: how many works are listed " + "on the PICA public directory (listing is per work) and what listings " + "show (audio previews, splits, publishers, agreements, stems, " + "licensing enquiries). Read-only. To change them, use " + "pica_directory_settings_update.", workflows: "infrastructure", vernacular_kind: "specialist", vernacular_reason: "Specialist context; not yet covered by the Creator Question Atlas — pending telemetry-driven addition per ADR-226 Phase 4 substrate writes.", inputSchema: { type: "object", properties: { action: { type: "string", enum: ["get"], description: "Optional; 'get' is the only action. Changing settings is pica_directory_settings_update.", }, }, }, }, executor: this.directorySettings.bind(this), }, { definition: { name: "pica_directory_settings_update", scope: "admin", audiences: ["stdio", "http", "public"], tier: "write", // Everything this changes is public (the directory is open to // anyone, people and agents), so every change waits for a yes. previewMode: "two_step_token", description: "Change what your catalogue shows on the PICA public directory, which " + "anyone can read: list every ready work at once (opted_in: true), and " + "whether listings show audio previews, splits, publishers, agreements " + "or stems, and take licensing enquiries. Every change is public, so " + "the first call saves nothing: it answers confirmation_required with " + "what would change. Tell the user, and only if they agree call again " + "with the same arguments plus confirmation_token. " + "→ before: pica_directory_settings (see the current settings)", workflows: "infrastructure", vernacular_kind: "specialist", vernacular_reason: "Specialist context; not yet covered by the Creator Question Atlas — pending telemetry-driven addition per ADR-226 Phase 4 substrate writes.", inputSchema: { type: "object", properties: { opted_in: { type: "boolean", description: "Listing is per work. true = list every work that is ready " + "(has an artist, an industry code, a credit and a recording) " + "and not hidden, publicly. false = decline: takes every work " + "this catalogue listed off the directory (back to ready, not " + "listed; opting in again lists them again). A work a " + "confirmed writer listed themselves stays listed.", }, show_audio_preview: { type: "boolean", description: "Allow a short preview clip on directory listings. " + "A clip is cut when a work's audio is analysed; a work " + "without one shows no player. The full uploaded file is " + "never served.", }, show_splits: { type: "boolean", description: "Show credit split percentages in directory.", }, show_publishers: { type: "boolean", description: "Show publisher information in directory.", }, show_agreements: { type: "boolean", description: "Show agreement details in directory.", }, show_stems: { type: "boolean", description: "Show stems/instrumentals in directory.", }, contact_enabled: { type: "boolean", description: "Allow licensing enquiries from the directory. On by default; " + "set false to switch enquiries off for every listed work.", }, }, }, }, executor: this.updateDirectorySettings.bind(this), }, ]; } async directorySettings(args) { // Changing settings moved to pica_directory_settings_update (write tier, // confirm first): an older caller still sending action "update" is told // where it went rather than silently given a read. if (args.action !== undefined && args.action !== "get") { return typedError("USE_DIRECTORY_SETTINGS_UPDATE", "Nothing was changed: pica_directory_settings only reads now. Change directory settings with pica_directory_settings_update.", { next_tool: "pica_directory_settings_update" }); } const result = await this.pica.directory.getSettings(); const s = result.settings; // Listing is per song (2026-10-05): report songs, not the old flag. const listing = result.listing; const summary = [ listing ? `Works listed: ${listing.listed} · ready but not listed: ${listing.ready} · hidden: ${listing.hidden} · not ready: ${listing.notReady}` : "Works listed: couldn't check", s.show_audio_preview ? "Audio preview: on (30-second clips)" : "Audio preview: off", s.contact_enabled ? "Enquiries: on" : "Enquiries: off", s.show_splits ? "Splits: visible" : "Splits: hidden", s.show_publishers ? "Publishers: visible" : "Publishers: hidden", ].join("\n"); return { content: [{ type: "text", text: summary }], structuredContent: result, }; } async updateDirectorySettings(args) { const updates = {}; const boolFields = [ "opted_in", "show_audio_preview", "show_splits", "show_publishers", "show_agreements", "show_stems", "contact_enabled", ]; // Only a real boolean is accepted. `Boolean("false")` is true, so the text // "false" used to switch a setting ON: for opted_in, that lists every ready // work on the public directory (#3848 / #2918). const invalid = []; for (const field of boolFields) { const value = args[field]; if (value === undefined) continue; if (typeof value === "boolean") updates[field] = value; else invalid.push(field); } if (invalid.length > 0) { return typedError("VALIDATION_ERROR", `Nothing was changed: ${invalid.join(", ")} must be true or false.`, { fields: invalid }); } if (Object.keys(updates).length === 0) { // typedError, not formatAsText({error}): the latter has no `isError`, so // the dispatcher and the client read a refusal as a SUCCESS whose payload // happens to contain the word "error", and mcp_audit_log.error_code is // NULL. See ./error-envelope.ts. return typedError("VALIDATION_ERROR", "No settings to update. Provide at least one setting field."); } const result = await this.pica.directory.updateSettings(updates); const listing = result.listing; const message = updates.opted_in === true && listing ? `Listed ${listing.listed} ready works on the directory. ${listing.notReady} aren't ready yet; each work's page says what it needs.` : updates.opted_in === false ? withdrawnMessage(result.withdrawn, result .writer_listed) : "Directory settings updated."; return formatSuccess(message, result); } } /** What declining did (ADR-306 amendment 2026-11-20), only as far as it is true. */ function withdrawnMessage(withdrawn, writerListed) { const stay = typeof writerListed === "number" && writerListed > 0 ? ` ${writerListed} ${writerListed === 1 ? "work" : "works"} a confirmed writer listed themselves ${writerListed === 1 ? "stays" : "stay"} listed.` : ""; if (typeof withdrawn !== "number") { return "Recorded that you declined the directory." + stay; } if (withdrawn === 0) { return ("Recorded that you declined the directory. This catalogue had nothing of its own listed." + stay); } return (`Took ${withdrawn} ${withdrawn === 1 ? "work" : "works"} off the directory: ` + `${withdrawn === 1 ? "it's" : "they're"} ready but not listed, and opting ` + "in again lists them again." + (stay || " A work a confirmed writer listed themselves stays listed.")); } //# sourceMappingURL=directory.js.map