UNPKG

@receiz/mcp-server

Version:

MCP server for agents building and verifying Receiz proof-native applications through the canonical Receiz SDK rails.

161 lines • 9.08 kB
const text = (description) => ({ type: "string", description }); const strictObject = (properties, required) => ({ type: "object", additionalProperties: false, properties, required: [...required], }); const digest = (binds) => strictObject({ algorithm: { const: "sha-256" }, binds: { const: binds }, value: text("Lowercase SHA-256 digest."), }, ["algorithm", "binds", "value"]); const artifactId = strictObject({ scheme: { const: "receiz-artifact.v1" }, value: text("Stable artifact identity.") }, ["scheme", "value"]); const historyDigest = digest("verified-proof-history"); const expectedHead = { oneOf: [ strictObject({ status: { const: "unaccepted" } }, ["status"]), strictObject({ status: { const: "accepted" }, head: historyDigest }, ["status", "head"]), ], }; const exactArtifact = { artifactBase64: text("Base64 encoding of the complete sealed artifact bytes."), filename: text("Exact artifact filename."), mimeType: text("Exact artifact MIME type."), }; export const RECEIZ_V113_GLOBAL_RECONCILIATION_TOOL_NAMES = Object.freeze([ "receiz_artifact_global_resolve", "receiz_artifact_reconcile_plan", "receiz_artifact_reconcile_stage", "receiz_artifact_reconcile_commit", ]); export const RECEIZ_V113_GLOBAL_RECONCILIATION_TOOLS = Object.freeze([ { name: "receiz_artifact_global_resolve", description: "Read one named Receiz coordination domain and independently reverify its exact accepted artifact. This tool is read-only and MCP is not authority.", inputSchema: strictObject({ artifactId, knownHead: historyDigest }, ["artifactId"]), outputSchema: { type: "object", additionalProperties: false }, }, { name: "receiz_artifact_reconcile_plan", description: "Plan offline-to-global reconciliation from exact sealed artifact bytes without staging or accepting anything. MCP is not authority.", inputSchema: strictObject({ artifactId, issuerKeyId: text("Admitted Identity Seal key identifier; never caller key material."), expectedAcceptedHead: expectedHead, ...exactArtifact, idempotencyKey: text("Caller-retained retry identity; never returned."), }, ["artifactId", "issuerKeyId", "expectedAcceptedHead", "artifactBase64", "filename", "mimeType", "idempotencyKey"]), outputSchema: { type: "object", additionalProperties: false }, }, { name: "receiz_artifact_reconcile_stage", description: "Stage the exact planned artifact as neutral immutable bytes after separate Identity Seal capability signing; no head advances. MCP is not authority.", inputSchema: strictObject({ planDigest: text("Exact reconciliation plan digest returned by the plan tool."), signedCapability: strictObject({ schema: { const: "receiz.signed-capability.v113.reconciliation" }, payload: { type: "object", additionalProperties: false }, alg: { enum: ["Ed25519", "P-256"] }, signatureB64u: text("Identity Seal signature over the exact capability payload."), }, ["schema", "payload", "alg", "signatureB64u"]), }, ["planDigest", "signedCapability"]), outputSchema: { type: "object", additionalProperties: false }, }, { name: "receiz_artifact_reconcile_commit", description: "Commit one exact staged reconciliation using a distinct digest-bound confirmation and the same production adapter. MCP is not authority.", inputSchema: strictObject({ planDigest: text("Exact reconciliation plan digest."), stagedReferenceDigest: text("Exact staged-reference digest returned by stage."), confirmationDigest: text("Exact distinct commit-confirmation digest returned by stage."), }, ["planDigest", "stagedReferenceDigest", "confirmationDigest"]), outputSchema: { type: "object", additionalProperties: false }, }, ]); function object(value) { if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("receiz_mcp_reconciliation_input_invalid"); return value; } function exactKeys(value, keys) { if (Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw new Error("receiz_mcp_reconciliation_input_invalid"); } function requiredString(value, key) { const result = value[key]; if (typeof result !== "string" || !result) throw new Error("receiz_mcp_reconciliation_input_invalid"); return result; } export function createReceizMcpGlobalReconciliationOperations(domain) { const plans = new Map(); const stages = new Map(); return Object.freeze({ has(name) { return RECEIZ_V113_GLOBAL_RECONCILIATION_TOOL_NAMES.includes(name); }, async call(name, raw) { if (!domain) throw new Error("receiz_mcp_global_coordination_requires_programmatic_connect_token"); if (name === "receiz_artifact_global_resolve") { const keys = Object.hasOwn(raw, "knownHead") ? ["artifactId", "knownHead"] : ["artifactId"]; exactKeys(raw, keys); return domain.resolveAcceptedHead({ artifactId: object(raw.artifactId), ...(raw.knownHead ? { knownHead: object(raw.knownHead) } : {}) }); } if (name === "receiz_artifact_reconcile_plan") { exactKeys(raw, ["artifactId", "issuerKeyId", "expectedAcceptedHead", "artifactBase64", "filename", "mimeType", "idempotencyKey"]); const bytes = Buffer.from(requiredString(raw, "artifactBase64"), "base64"); if (!bytes.byteLength) throw new Error("receiz_mcp_reconciliation_input_invalid"); const filename = requiredString(raw, "filename"); const mimeType = requiredString(raw, "mimeType"); const artifact = typeof File !== "undefined" ? new File([bytes], filename, { type: mimeType }) : new Blob([bytes], { type: mimeType }); const result = await domain.planOfflineReconciliation({ artifactId: object(raw.artifactId), issuerKeyId: requiredString(raw, "issuerKeyId"), expectedAcceptedHead: object(raw.expectedAcceptedHead), sealedArtifact: artifact, idempotencyKey: requiredString(raw, "idempotencyKey"), }); if (result.status === "planned") plans.set(result.plan.planDigest.value, { prepared: result, artifact }); return result; } if (name === "receiz_artifact_reconcile_stage") { exactKeys(raw, ["planDigest", "signedCapability"]); const planDigest = requiredString(raw, "planDigest"); const retained = plans.get(planDigest); if (!retained) throw new Error("receiz_mcp_reconciliation_plan_invalid"); const signedCapability = object(raw.signedCapability); const result = await domain.stageOfflineReconciliation({ plan: retained.prepared.plan, signedCapability, sealedArtifact: retained.artifact, confirmation: retained.prepared.stageConfirmation, }); if (result.status === "staged") stages.set(planDigest, { signedCapability, reference: result, commitConfirmation: result.commitConfirmation }); return result; } if (name === "receiz_artifact_reconcile_commit") { exactKeys(raw, ["planDigest", "stagedReferenceDigest", "confirmationDigest"]); const planDigest = requiredString(raw, "planDigest"); const retained = plans.get(planDigest); const stage = stages.get(planDigest); if (!retained || !stage || stage.reference.status !== "staged") throw new Error("receiz_mcp_reconciliation_stage_invalid"); const confirmation = stage.reference.commitConfirmation; if (requiredString(raw, "stagedReferenceDigest") !== confirmation.stagedReferenceDigest.value || requiredString(raw, "confirmationDigest") !== confirmation.confirmationDigest.value) { throw new Error("receiz_mcp_reconciliation_confirmation_invalid"); } stages.delete(planDigest); return domain.commitOfflineReconciliation({ plan: retained.prepared.plan, signedCapability: stage.signedCapability, stagedReference: stage.reference.reference, confirmation, }); } throw new Error("receiz_mcp_reconciliation_tool_unknown"); }, }); } //# sourceMappingURL=globalReconciliationOperations.js.map