Explorer

definy.mcp-submit-content

description
Sign the event content with the MCP account (sign_mcp_account) and submit it the same way as SubmitEvent (definy.submit-event). The event time is at least 1 second after after_time_ms (the time of the parent snapshot), because of two snapshots in the same second the earlier one stays the latest (docs/event.md). then gets whether it was accepted and the response text
type
Fn(
  account: @definy.mcp-account,
  content: @core.event-content,
  after_time_ms: Number,
  then: Fn(accepted: Boolean, text: 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(accepted: false, text: "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(
                    accepted: false,
                    text: "The MCP account could not sign (DEFINY_MCP_ACCOUNT_SECRET_KEY is not set)"
                  ),
                #some(bytes$7) =>
                  @definy.service-io-then-respond(
                    io: @definy.submit-event(
                      request: #object<@definy.json>([
                        {
                          key: "signedEventBytes",
                          value: #string<@definy.json>(@std.bytes-to-base64(bytes: @cbor.encode(item: @definy.signed-event-cbor(signature: $7, event_binary: $5))))
                        }
                      ])
                    ),
                    respond: fn(response$8) =>
                      $2(accepted: @core.equal(left: $8.status, right: 200), text: @definy.http-body-text(body: $8.body))
                  )
              }
          })
      })
  }
visibility
public
definy.mcp-submit-content (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: fKnH46Gn3b_WlYjwVwnh6XcTvp8opkPqw6ejN2yh0jQ
content hash: ICX8Lwn4tORM2CVBMikb4QI3BeAowZIb8RqfWVAlWjg