Explorer

definy.mcp-create-branch

description
The definy_create_branch MCP tool
type
Fn(arguments: @definy.json, request: @http.request) -> @definy.service-io
expression
fn(arguments$0, request$1) =>
  let project$2 = match @definy.json-get-string(value: $0, key: "project") {
      #some(text$3) =>
        $3,
      #none(_) =>
        ""
    };
  let branch$4 = match @definy.json-get-string(value: $0, key: "branch") {
      #some(text$5) =>
        $5,
      #none(_) =>
        ""
    };
  let from$6 = match @definy.json-get-string(value: $0, key: "fromBranch") {
      #some(text$7) =>
        $7,
      #none(_) =>
        "main"
    };
  let message$8 = match @definy.json-get-string(value: $0, key: "message") {
      #some(text$9) =>
        $9,
      #none(_) =>
        @core.string-concat(left: "Create branch ", right: $4)
    };
  match @core.or(left: @core.equal(left: $2, right: ""), right: @core.equal(left: $4, right: "")) {
    true =>
      @definy.mcp-text-error(text: "project and branch are required"),
    false =>
      @definy.mcp-with-account(
        then: fn(account$10) =>
          @definy.read-branch-snapshot(
            project: $2,
            branch: $4,
            then: fn(commit$11, commits$12) =>
              match $11 {
                #some(_) =>
                  @definy.mcp-text-error(text: @std.string-join(items: ["Branch ", $4, " already exists in project ", $2], separator: "")),
                #none(_) =>
                  @definy.read-branch-snapshot(
                    project: $2,
                    branch: $6,
                    then: fn(commit$13, commits$14) =>
                      match $13 {
                        #none(_) =>
                          @definy.mcp-text-error(
                            text: @std.string-join(items: ["Branch ", $6, " of project ", $2, " was not found"], separator: "")
                          ),
                        #some(found$15) =>
                          @definy.read-snapshot-content(
                            event_hash: $15.event_hash,
                            then: fn(commit$16) =>
                              match $16 {
                                #none(_) =>
                                  @definy.mcp-text-error(text: "The source snapshot could not be read"),
                                #some(content$17) =>
                                  @definy.mcp-submit-content(
                                    account: $10,
                                    after_time_ms: 0,
                                    content: #project_commit<@core.event-content>({
                                      project_name: $17.project_name,
                                      branch: $4,
                                      project_description: $17.project_description,
                                      message: $8,
                                      parent_commit_hash: #some($15.event_hash),
                                      merged_commit_hash: #none,
                                      modules: $17.modules
                                    }),
                                    then: fn(accepted$18, text$19) =>
                                      match $18 {
                                        true =>
                                          @definy.mcp-text(
                                            text: @std.string-join(
                                              items: [
                                                "Created branch ",
                                                $4,
                                                " of project ",
                                                $2,
                                                " from ",
                                                $6,
                                                " (owned by account ",
                                                $10.account_id,
                                                ")\n",
                                                $19
                                              ],
                                              separator: ""
                                            )
                                          ),
                                        false =>
                                          @definy.mcp-text-error(text: $19)
                                      }
                                  )
                              }
                          )
                      }
                  )
              }
          )
      )
  }
visibility
public
definy.mcp-create-branch (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: k7sxdaukrw-Rt9QWXe8l5jRO1OMr9uRznhSMvrza0XM
content hash: IYm_Y8UUesXr0VdAvpIi9Z3AKxiJ2MXfj93nhjo5g-0