UNPKG

@withpica/mcp-server

Version:

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

85 lines • 5.03 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. export function buildWrappedArgsMissingEnvelope(params) { const { toolName, required, missingRequired, requiredOneOf, args, knownProps, aliasesApplied, } = params; const allMissing = Object.keys(args).length === 0; const unrecognisedFields = Object.keys(args).filter((k) => !knownProps.includes(k)); const hasOneOf = Array.isArray(requiredOneOf) && requiredOneOf.length > 0; const unmetGroup = hasOneOf ? requiredOneOf.find((group) => Array.isArray(group) && group.length > 0 && !group.some((f) => f in args)) : undefined; // What the empty-args ("received none") message names as required — the // plain list, or (for a oneOf-only tool, whose `required` is `[]`) the // unmet group's members. const requirementLabel = required.length > 0 ? required.join(", ") : (unmetGroup ?? []).join(", "); const stubArgs = required.length > 0 ? Object.fromEntries(required.map((f) => [f, "<value>"])) : unmetGroup ? { [unmetGroup[0]]: "<value>" } : {}; // The exact call to send next (ops 2026-11-03: agents kept retrying the // same wrong shape): every field sent that the tool recognises, as // "<as sent>", plus every missing required field (or the unmet one-of // group's first member) as "<value>". Names only, never the caller's // values: this text lands in agent_events and Sentry, and a value may be // a note body or an email address (Release, 2026-11-04). Unrecognised // fields are left out; `accepted_fields` lists the names the tool takes, // so a misnamed key can be mapped without another pica_tool_details call. const keptNames = Object.keys(args).filter((k) => knownProps.includes(k)); const suggestedArgs = { ...Object.fromEntries(keptNames.map((k) => [k, "<as sent>"])), ...Object.fromEntries((missingRequired.length > 0 ? missingRequired : Object.keys(stubArgs)) .filter((f) => !keptNames.includes(f)) .map((f) => [f, "<value>"])), }; const sendThis = `pica_execute({ tool: "${toolName}", args: ${JSON.stringify(suggestedArgs)} })`; // Empty args really is a transport question — there is nothing else an // empty resolved-args object could be — so this branch keeps asserting // that, verbatim, for both guards. // // A NON-empty args object still missing what it needs is NOT necessarily // transport loss: it was wrong in all 36 logged cases since July (the // caller sent the tool's own id under a plausible name that per-tool // aliasing resolves when unambiguous, or a misspelled/foreign key that // aliasing correctly leaves alone). Neither guard can tell "transport // loss" apart from "wrong key sent" from here, so both name what // pica_execute actually saw instead of asserting a cause they can't know. const message = allMissing ? `${toolName} requires arguments [${requirementLabel}] but pica_execute received none. Pass them as \`args: {...}\` (canonical) or as top-level keys (FLAT). Do NOT pass them under \`arguments:\` — claude.ai web silently strips that field as a wire-protocol token, which is why the wrapped tool sees nothing.` : unmetGroup ? `${toolName} requires one of [${unmetGroup.join(", ")}] but none was present in the resolved args. Unrecognised fields sent: [${unrecognisedFields.join(", ") || "none"}]. It accepts: [${knownProps.join(", ")}]. Send: ${sendThis}. Field types: pica_tool_details({ tool: "${toolName}" }).` : `${toolName} requires [${required.join(", ")}] — missing: [${missingRequired.join(", ")}]. Unrecognised fields sent: [${unrecognisedFields.join(", ") || "none"}]. It accepts: [${knownProps.join(", ")}]. Send: ${sendThis}. Field types: pica_tool_details({ tool: "${toolName}" }).`; const shared = { error_code: "WRAPPED_ARGS_MISSING", tool: toolName, required_fields: required, missing_required_fields: missingRequired, ...(hasOneOf ? { required_one_of: requiredOneOf } : {}), unrecognised_fields: unrecognisedFields, accepted_fields: knownProps, aliases_applied: aliasesApplied, next_tool: "pica_tool_details", retry_eligible: false, }; const exampleCallShapes = { canonical: { tool: toolName, args: stubArgs }, flat: { tool: toolName, ...stubArgs }, // The canonical shape, carrying what was sent that the tool recognises. with_your_args: { tool: toolName, args: suggestedArgs }, }; const envelope = { ...shared, message, example_call_shapes: exampleCallShapes, }; return { text: JSON.stringify(envelope, null, 2), structuredContent: { ...shared, error_message: message, example_call_shapes: exampleCallShapes, }, }; } //# sourceMappingURL=wrapped-args-envelope.js.map