UNPKG

@receiz/mcp-server

Version:

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

159 lines • 11.8 kB
import { createReceizSdkMutationConsent } from "./v127SdkOperations.js"; import { assertReceizMarketplaceNonfinancialTool } from "./marketplaceNonfinancialPolicy.js"; import { assertReceizMarketplaceToolCall } from "./marketplaceExecutionPolicy.js"; const text = { type: "string" }; const nonemptyText = { type: "string", minLength: 1 }; const object = (properties, required = []) => ({ type: "object", additionalProperties: false, properties, required }); const worldFields = { action: text, message: text, visitorKey: text, threadKey: text, allowBrowserVoiceFallback: { type: "boolean" }, clientContext: { type: "object", additionalProperties: true }, clientUserMessageId: text, clientAssistantMessageId: text, clientOperationId: text, quoteExpiresAt: text, slotStartAt: text, name: text, email: text, notes: text, timezone: text, questions: {}, }; const omit = (value, ...keys) => Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key))); const consentField = { confirmation: { type: "string", minLength: 1, description: "Exact single-use confirmationDigest from this operation's preview with identical arguments." } }; const worldSchema = (fields, mutation, bodyRequired = true) => object({ username: nonemptyText, ...(mutation ? { body: object(fields), ...consentField } : { query: object({ visitorKey: text, threadKey: text }) }), }, ["username", ...(mutation && bodyRequired ? ["body"] : [])]); const authority = "MCP is not authority. MCP transport and consent are not proof authority. Sealed Receiz proof objects and verified append-only history remain stronger truth. Public observation and World Twin responses are projections, not proof admission or canonical events."; const definitions = [ { name: "receiz_public_proof_observe", sdkMethod: "publicProof.observe", mutation: true, description: "Observe the selected public source through the current SDK observer after exact confirmation. The observed public record is a projection beneath sealed Receiz proof; observation does not establish ownership, identity, or proof admission.", inputSchema: object({ body: object({ sourceUrl: nonemptyText, sourceType: { type: "string", enum: ["youtube", "website", "social_post", "github", "podcast", "image", "video", "music", "article", "pdf", "book", "dataset", "other"] } }, ["sourceUrl"]), ...consentField }, ["body"]), invoke: (client, args) => client.publicProof.observe(args.body) }, { name: "receiz_world_profile", sdkMethod: "world.profile", mutation: false, description: "Read the selected current public World profile through the SDK. This explicit remote invocation may record a guest view; it does not replace settled verified local truth.", inputSchema: worldSchema({}, false), invoke: (client, args) => client.world.profile(args.username, (args.query ?? {})) }, { name: "receiz_world_message", sdkMethod: "world.message", mutation: true, description: "Send the exact selected World Twin request after confirmation, preserving SDK action, visitor, thread, operation identity, and quoted usage fields. A provider reply remains non-authoritative speech; this tool does not admit a world event.", inputSchema: worldSchema(worldFields, true), invoke: (client, args) => client.world.message(args.username, args.body) }, { name: "receiz_world_welcome", sdkMethod: "world.welcome", mutation: true, description: "Request one selected World Twin welcome after exact confirmation. Existing guest/session and usage admission remain binding; no canonical world event is created by model speech.", inputSchema: worldSchema(omit(worldFields, "action", "message"), true, false), invoke: (client, args) => client.world.welcome(args.username, (args.body ?? {})) }, { name: "receiz_world_book", sdkMethod: "world.book", mutation: true, description: "Request the selected World appointment through the current SDK booking primitive after exact confirmation. Recipient, slot, contact fields, questions and existing route admission remain binding.", inputSchema: worldSchema(omit(worldFields, "action"), true), invoke: (client, args) => client.world.book(args.username, args.body) }, { name: "receiz_world_stream_profile", sdkMethod: "world.streamProfile", mutation: true, description: "Collect one current SDK World Twin reply stream after exact confirmation, with a fixed 4096-event/4-MiB projection limit and explicit reply_done/done completion. Errors, truncation, and missing terminal completion fail; no automatic retry or canonical event admission occurs.", inputSchema: worldSchema(worldFields, true), invoke: (client, args) => collectWorldReply(client.world.streamProfile(args.username, args.body)) }, { name: "receiz_sports_conformance_history", sdkMethod: "sports.conformanceHistory", mutation: false, description: "Read the current sports conformance history through the SDK. A diagnostic report is not artifact proof authority.", inputSchema: object({}), invoke: client => client.sports.conformanceHistory() }, { name: "receiz_sports_conformance_rollups", sdkMethod: "sports.conformanceRollups", mutation: false, description: "Read current sports conformance rollups with the SDK's selected days query. Diagnostics do not replace artifact verification.", inputSchema: object({ query: object({ days: { type: "number" } }) }), invoke: (client, args) => client.sports.conformanceRollups((args.query ?? {})) }, { name: "receiz_sports_badge", sdkMethod: "sports.badge", mutation: false, description: "Read the current sports conformance badge through the SDK; badge projection is not artifact proof authority.", inputSchema: object({}), invoke: client => client.sports.badge() }, { name: "receiz_verification_conformance", sdkMethod: "verification.conformance", mutation: false, description: "Read the current verification-conformance service report through the SDK. This report does not verify a selected file; use canonical artifact verification for its proof verdict.", inputSchema: object({}), invoke: client => client.verification.conformance() }, ]; async function collectWorldReply(stream) { const events = []; let bytes = 0; let replyComplete = false; // The current route performs exactly one provider reply, sends reply_done and // done, then closes. This is a finite invocation, not follow/poll subscription. for await (const event of stream) { bytes += Buffer.byteLength(JSON.stringify(event), "utf8"); if (events.length >= 4096 || bytes > 4 * 1024 * 1024) throw new Error("receiz_world_stream_projection_limit_outcome_unknown"); if (event.type === "error") throw new Error("receiz_world_stream_failed_outcome_unknown"); events.push(event); if (event.type === "reply_done") replyComplete = true; if (event.type === "done") { if (!replyComplete) throw new Error("receiz_world_stream_completion_missing_outcome_unknown"); return { events, complete: true, canonicalEventAdmission: false, sourceBoundary: "one finite SDK World profile reply; provider speech is non-authoritative" }; } } throw new Error("receiz_world_stream_completion_missing_outcome_unknown"); } function freeze(value) { if (value && typeof value === "object") { for (const child of Object.values(value)) freeze(child); Object.freeze(value); } return value; } export const RECEIZ_CURRENT_SOURCE_OPERATION_MAP = freeze(Object.fromEntries(definitions.map(definition => [definition.name, definition]))); export const RECEIZ_CURRENT_SOURCE_TOOLS = freeze(definitions.map(definition => ({ name: definition.name, description: `${definition.description} ${authority}`, inputSchema: definition.inputSchema, outputSchema: { type: "object", additionalProperties: true }, annotations: { // World profile GET appends a guest view even though its SDK response is read. readOnlyHint: !definition.mutation && definition.sdkMethod !== "world.profile", destructiveHint: definition.mutation, openWorldHint: true, }, }))); function assertJson(value) { if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) return; if (Array.isArray(value)) { value.forEach(assertJson); return; } if (value && typeof value === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(value))) { Object.values(value).forEach(assertJson); return; } throw new TypeError("receiz_current_source_json_required"); } function validate(value, schema) { if (schema.type === "object") { if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("receiz_current_source_object_required"); const properties = (schema.properties ?? {}); for (const key of (schema.required ?? [])) if (!Object.hasOwn(value, key)) throw new TypeError(`receiz_current_source_required:${key}`); for (const [key, child] of Object.entries(value)) { if (schema.additionalProperties === false && !Object.hasOwn(properties, key)) throw new TypeError(`receiz_current_source_unknown_argument:${key}`); if (Object.hasOwn(properties, key)) validate(child, properties[key]); } } if (schema.type === "string" && (typeof value !== "string" || schema.minLength === 1 && !value.trim())) throw new TypeError("receiz_current_source_text_required"); if (schema.type === "number" && (typeof value !== "number" || !Number.isFinite(value))) throw new TypeError("receiz_current_source_number_required"); if (schema.type === "boolean" && typeof value !== "boolean") throw new TypeError("receiz_current_source_boolean_required"); if (Array.isArray(schema.enum) && !schema.enum.includes(value)) throw new TypeError("receiz_current_source_enum_invalid"); } /** Fixed current SDK adapters only. No caller-selected property, URL or invoke. */ export function createReceizCurrentSourceOperations(input) { const profile = input.executionProfile; const consent = createReceizSdkMutationConsent(); return Object.freeze({ async call(name, raw = {}) { if (profile === "marketplace-nonfinancial") assertReceizMarketplaceNonfinancialTool(name); if (profile === "marketplace-phi") assertReceizMarketplaceToolCall(name, raw); if (!Object.hasOwn(RECEIZ_CURRENT_SOURCE_OPERATION_MAP, name)) throw new Error("receiz_current_source_operation_unknown"); const definition = RECEIZ_CURRENT_SOURCE_OPERATION_MAP[name]; assertJson(raw); validate(raw, definition.inputSchema); const args = structuredClone(raw); const confirmation = args.confirmation; delete args.confirmation; if (definition.mutation) { const preview = consent(definition.sdkMethod, args, confirmation); if (preview) return preview; } const result = await definition.invoke(input.client, args); if (result && typeof result === "object" && "ok" in result && result.ok === false) throw new Error("receiz_current_source_sdk_rejected"); return definition.mutation ? { schema: "receiz.mcp.current-source-result.v129", operation: definition.sdkMethod, result, authority } : result; }, }); } //# sourceMappingURL=currentSourceOperations.js.map