@receiz/mcp-server
Version:
MCP server for agents building and verifying Receiz proof-native applications through the canonical Receiz SDK rails.
123 lines • 9.97 kB
JavaScript
import * as sdk from "@receiz/sdk";
import { createReceizDeviceMaterialHost } from "./deviceMaterialHost.js";
export const RECEIZ_MCP_PROOF_VALUE_LIMITS = Object.freeze({ inputBytes: 64 * 1024 * 1024, argumentBytes: 256 * 1024, outputBytes: 8 * 1024 * 1024, samples: 256, saleRecoveries: 256 });
const reference = { type: "string", pattern: "^receiz:file:[a-f0-9]{64}:.+$", description: "Digest-bound exact local workspace file locator; the SDK verifies the enclosing proof before projection." };
const coordinate = { type: "string", pattern: "^(0|[1-9][0-9]*)$", maxLength: 128 };
const options = {
includeReplay: { type: "boolean", description: "Include the SDK's complete public replay package when valuation is available; no file is written." },
expectedProofDigest: { type: "string", pattern: "^[a-f0-9]{64}$" }, expectedHistoryHead: { type: "string", minLength: 1 },
policy: { type: "object", additionalProperties: false, properties: { algorithm: { type: "string" }, checksum: { type: "string" } }, required: ["algorithm", "checksum"] },
rarityPolicy: { type: "object", description: "Exact declared policy; the SDK requires its digest and operands in the verified sealed issuance." },
marketReferenceRule: { type: "string", enum: ["last-executed-sale-v129"] },
saleRecoveryReferences: { type: "array", maxItems: 256, uniqueItems: true, items: reference },
usdBasis: { type: "object", description: "Explicit reproducible USD display basis, independently checked by the SDK; no settlement effect." },
askingPricePhiMicro: coordinate,
};
const authority = "MCP is not authority. Only actual SDK-issued verification or portable-state admission supplies source custody. Explicit Kai coordinates are required; no implicit current time or model metadata is accepted. Intrinsic value, market reference, and executed sale remain distinct. No network, custody transition, settlement, payment, approval or file write occurs. Inputs are bounded to 64 MiB per referenced file, 256 KiB arguments, 256 samples/recoveries; output over 8 MiB fails without truncation.";
export const RECEIZ_PROOF_VALUE_TOOLS = Object.freeze([
{ name: "receiz_proof_value_inspect", description: `Inspect the selected exact local enclosing proof with SDK projectReceizProofValueV129 at the explicit valuationKaiUPulse. Return its complete source-bound projection and transaction/math trace or precise unavailable boundary. ${authority}`,
inputSchema: { type: "object", additionalProperties: false, properties: { artifactReference: reference, valuationKaiUPulse: coordinate, ...options }, required: ["artifactReference", "valuationKaiUPulse"] },
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } },
{ name: "receiz_proof_value_sample", description: `Recompute a bounded ordered list of model samples using SDK sampleReceizProofValueV129 on the same selected exact local proof and explicit valuationKaiUPulses. These are calculated samples, not measured historical prices. ${authority}`,
inputSchema: { type: "object", additionalProperties: false, properties: { artifactReference: reference, valuationKaiUPulses: { type: "array", minItems: 1, maxItems: 256, items: coordinate }, ...options }, required: ["artifactReference", "valuationKaiUPulses"] },
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } },
{ name: "receiz_proof_value_replay_verify", description: `Verify an exact local public proof-value replay package with SDK verifyReceizProofValueReplayV129. The SDK verifies every enclosing proof, source/history/policy/coordinate binding and recomputed expected projection. Return verified-replay or invalid-replay; a locator, checksum or model JSON alone grants no authority. ${authority}`,
inputSchema: { type: "object", additionalProperties: false, properties: { replayReference: reference }, required: ["replayReference"] },
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } },
]);
const plain = (value) => value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
const isReference = (value) => typeof value === "string" && /^receiz:file:[a-f0-9]{64}:.+$/u.test(value);
const isCoordinate = (value) => typeof value === "string" && value.length <= 128 && /^(0|[1-9][0-9]*)$/u.test(value);
function argumentsFor(name, raw) {
const fail = () => { throw Error("proof_value_arguments_invalid"); };
if (!plain(raw) || Object.values(Object.getOwnPropertyDescriptors(raw)).some(descriptor => !descriptor.enumerable || !("value" in descriptor)))
fail();
let args;
try {
const serialized = sdk.canonicalizeReceizV122(raw);
if (Buffer.byteLength(serialized, "utf8") > RECEIZ_MCP_PROOF_VALUE_LIMITS.argumentBytes)
fail();
args = JSON.parse(serialized);
}
catch {
return fail();
}
const replay = name === "receiz_proof_value_replay_verify";
const sample = name === "receiz_proof_value_sample";
if (Object.keys(args).some(key => !(replay ? ["replayReference"] : ["artifactReference", sample ? "valuationKaiUPulses" : "valuationKaiUPulse", ...Object.keys(options)]).includes(key)))
fail();
if (replay) {
if (!isReference(args.replayReference))
fail();
return args;
}
if (!isReference(args.artifactReference))
fail();
if (sample) {
if (!Array.isArray(args.valuationKaiUPulses) || !args.valuationKaiUPulses.length || args.valuationKaiUPulses.length > RECEIZ_MCP_PROOF_VALUE_LIMITS.samples || !args.valuationKaiUPulses.every(isCoordinate))
fail();
}
else if (!isCoordinate(args.valuationKaiUPulse))
fail();
if (args.expectedProofDigest !== undefined && (typeof args.expectedProofDigest !== "string" || !/^[a-f0-9]{64}$/u.test(args.expectedProofDigest)))
fail();
if (args.expectedHistoryHead !== undefined && (typeof args.expectedHistoryHead !== "string" || !args.expectedHistoryHead))
fail();
for (const key of ["policy", "rarityPolicy", "usdBasis"])
if (args[key] !== undefined && !plain(args[key]))
fail();
if (args.askingPricePhiMicro !== undefined && !isCoordinate(args.askingPricePhiMicro))
fail();
if (args.marketReferenceRule !== undefined && args.marketReferenceRule !== "last-executed-sale-v129")
fail();
if (args.includeReplay !== undefined && typeof args.includeReplay !== "boolean")
fail();
if (args.saleRecoveryReferences !== undefined && (!Array.isArray(args.saleRecoveryReferences) || args.saleRecoveryReferences.length > RECEIZ_MCP_PROOF_VALUE_LIMITS.saleRecoveries
|| !args.saleRecoveryReferences.every(isReference) || new Set(args.saleRecoveryReferences).size !== args.saleRecoveryReferences.length))
fail();
return args;
}
function boundedOutput(result) {
if (Buffer.byteLength(JSON.stringify(result, null, 2), "utf8") > RECEIZ_MCP_PROOF_VALUE_LIMITS.outputBytes)
throw Error("proof_value_output_limit_operational_denial");
return result;
}
export function createReceizProofValueOperations(input) {
const host = createReceizDeviceMaterialHost(input.workspace);
const readJson = async (reference) => {
const { exactBytes } = await host.resolveExactFileReference(reference, RECEIZ_MCP_PROOF_VALUE_LIMITS.inputBytes);
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(exactBytes));
};
return { async call(name, raw) {
if (!RECEIZ_PROOF_VALUE_TOOLS.some(tool => tool.name === name))
throw Error("proof_value_tool_unknown");
const args = argumentsFor(name, raw);
if (name === "receiz_proof_value_replay_verify")
return boundedOutput(await sdk.verifyReceizProofValueReplayV129(await readJson(args.replayReference)));
const retained = await host.resolveVerifiedProofReference(args.artifactReference, RECEIZ_MCP_PROOF_VALUE_LIMITS.inputBytes);
let source = retained.verification;
if (retained.verification.continuity.state === "verified" && retained.verification.continuity.carrier === "portable_asset") {
const admission = await sdk.createReceizArtifactAdmissionEngine()(retained.verification, { profile: "portable-state" });
if (admission.profile !== "portable-state" || (admission.verdict !== "bearer-recovery" && admission.verdict !== "foreign-owner")) {
throw Error(`proof_value_source_admission_${admission.error?.code ?? admission.verdict}`);
}
source = admission;
}
const sales = [];
for (const reference of (args.saleRecoveryReferences ?? []))
sales.push(await sdk.verifyReceizProofValueSaleRecoveryV129(await readJson(reference)));
const { artifactReference: _artifactReference, saleRecoveryReferences: _recoveries, includeReplay, ...options } = args;
const selected = { ...options, source, ...(sales.length ? { sales } : {}) };
const result = name === "receiz_proof_value_sample"
? await sdk.sampleReceizProofValueV129(selected)
: await sdk.projectReceizProofValueV129(selected);
if (includeReplay === true && ("samples" in result ? result.samples.every(sample => sample.status === "available") : result.status === "available")) {
const { valuationKaiUPulse, valuationKaiUPulses, ...basis } = selected;
const replay = await sdk.exportReceizProofValueReplayV129({ ...basis,
valuationKaiUPulses: (valuationKaiUPulses ?? [valuationKaiUPulse]) });
return boundedOutput({ projection: result, replay });
}
return boundedOutput(result);
} };
}
//# sourceMappingURL=proofValueOperations.js.map