Explorer

definy.mcp-with-account

description
Run then with the MCP account, creating the account on the server first when it is not created yet
type
Fn(then: Fn(account: @definy.mcp-account) -> @definy.service-io) -> @definy.service-io
expression
fn(then$0) =>
  #read_mcp_account<@definy.service-io>({
    then: fn(account$1) =>
      match $1 {
        #none(_) =>
          @definy.mcp-text-error(
            text: "Writing is disabled on this server: set the secrets DEFINY_MCP_ACCOUNT_SECRET_KEY and DEFINY_MCP_ACCOUNT_NAME (docs/mcp.md)"
          ),
        #some(found$2) =>
          @definy.read-account-created(
            account_id: $2.account_id,
            offset: 0,
            then: fn(created$3) =>
              match $3 {
                true =>
                  $0(account: $2),
                false =>
                  @definy.mcp-submit-content(
                    account: $2,
                    content: #create_account<@core.event-content>({account_name: $2.account_name}),
                    after_time_ms: 0,
                    then: fn(accepted$4, text$5) =>
                      match $4 {
                        true =>
                          $0(account: $2),
                        false =>
                          @definy.mcp-text-error(text: @core.string-concat(left: "Could not create the MCP account: ", right: $5))
                      }
                  )
              }
          )
      }
  })
visibility
public
definy.mcp-with-account (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: Z_3c8dHn3EAWZB-DJOrNmdUiCFRyKF-Z9Qzpdsqypks
content hash: 1BEVOG4GXOTeE3U0qB21_0x3fadhHy_DgBTP9Fh0AEU