Explorer

definy.mcp-check-content

description
Sign the event content with the MCP account like definy.mcp-submit-content, but only type-check it (definy.check-snapshot) and pass the reasons the server would reject it to then (empty if none). Nothing is stored except the contents. The rules of core.check-event (the parent is the latest snapshot, the creator of the branch) are not checked
type
Fn(
  account: @definy.mcp-account,
  content: @core.event-content,
  after_time_ms: Number,
  then: Fn(errors: List<String>) -> @definy.service-io
) -> @definy.service-io
expression
fn(account$0, content$1, after_time_ms$9, then$2) =>
  match @std.base64-to-bytes(text: $0.account_id) {
    #none(_) =>
      $2(errors: ["The account id of the MCP account is not Base64"]),
    #some(account_id_bytes$3) =>
      #read_time<@definy.service-io>({
        then: fn(now_ms$4) =>
          let inner$5 = @cbor.encode(
              item: @definy.event-inner-cbor(
                account_id_bytes: $3,
                time_seconds: @std.max(
                  a: @core.divide(left: $4, right: 1000),
                  b: @core.plus(left: @core.divide(left: $9, right: 1000), right: 1)
                ),
                content: $1
              )
            );
          #sign_mcp_account<@definy.service-io>({
            message: $5,
            then: fn(signature$6) =>
              match $6 {
                #none(_) =>
                  $2(errors: ["The MCP account could not sign (DEFINY_MCP_ACCOUNT_SECRET_KEY is not set)"]),
                #some(bytes$7) =>
                  @definy.check-snapshot(
                    signed_event_bytes: @std.bytes-to-base64(bytes: @cbor.encode(item: @definy.signed-event-cbor(signature: $7, event_binary: $5))),
                    then: fn(errors$8, commit$10) =>
                      $2(errors: $8)
                  )
              }
          })
      })
  }
visibility
public
definy.mcp-check-content (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: CiTco-2RioqeukuKkbE7O8gxm2yJxsvyhk8C1FONqz4
content hash: jE-6YAFLvNy0863eIAXzbbQaF4Fg_5xGmcSGje7aUic