← Semua tutorial · Kerfwise

Tutorial 7 dari 21

Otomatisasi Kerfwise dengan API dan MCP

Mahir 15 mnt

Panggil mesin Kerfwise dari skrip dan agen AI — pembuat kabinet, daftar potong, nesting lembaran, dan G-code CNC sebagai JSON API dan tool MCP, dengan contoh request dan response nyata.

Workspace dan API menjalankan kode mesin yang sama. Empat tool tersedia di setiap host usefulweb.site sebagai JSON API (POST /api/v1/tools/<id>/calculate), di dokumen OpenAPI, dan sebagai tool MCP (POST /mcp, nama tool memakai garis bawah).

Id toolNama MCPFungsinya
kerfwise-cabinet-builderkerfwise_cabinet_builderparameter → komponen, ukuran potong, jumlah pengeboran, hardware, SVG depan/samping, DXF, JSON proyek
kerfwise-cut-listkerfwise_cut_listkabinet atau proyek → daftar potong terkelompok, banding, hardware, lembaran per material, estimasi biaya, CSV
kerfwise-sheet-nestingkerfwise_sheet_nestingkomponen (juga bentuk L, sudut terpotong, seperempat lingkaran) + lembaran + kerf → tata letak, rendemen, batas bawah + selisih, sisa potongan, panjang potong, SVG + DXF
kerfwise-cnc-gcodekerfwise_cnc_gcodekomponen + lubang + lembaran + pisau → lembaran tertata, G-code (GRBL / LinuxCNC / gaya Fanuc), SVG jalur pahat, DXF, waktu permesinan

Semua panjang dalam milimeter. Contoh di bawah dijalankan pada server sungguhan; angkanya disalin dari response.

1. Tata komponen pada lembaran

POST /api/v1/tools/kerfwise-sheet-nesting/calculate
Content-Type: application/json

{"parts":[{"name":"Side","length":720,"width":559,"qty":4,"grain":true},
           {"name":"Shelf","length":562,"width":515,"qty":4,"grain":true}],
 "sheetLength":2800,"sheetWidth":2070,"kerf":4,"trim":10,
 "method":"guillotine","grainedMaterial":true,"sheetPrice":148}

Response (diringkas):

{
  "summary": "8 of 8 parts fit on 1 sheet of 2800 × 2070 mm with 47.8 % yield (guillotine).",
  "result": {
    "method": "guillotine",
    "strategy": "guillotine BSSF/LLAS, sorted by area",
    "sheetCount": 1,
    "yieldPct": 47.8,
    "offcutAreaM2": 2.75,
    "cutLengthM": 22.2,
    "cost": 148,
    "sheets": [{
      "index": 1,
      "placements": [
        {"name": "Side", "label": "1.1", "x": 10, "y": 10, "w": 720, "h": 559, "rotated": false},
        {"name": "Side", "label": "1.2", "x": 734, "y": 10, "w": 720, "h": 559, "rotated": false}
      ],
      "offcuts": [{"x": 10, "y": 1136, "w": 2780, "h": 924}, {"x": 2432, "y": 573, "w": 358, "h": 519}]
    }]
  }
}

Perhatikan kerf-nya: sisi samping kedua dimulai di x = 10 + 720 + 4 = 734. Bagian presentation dari response juga berisi SVG setiap lembaran dan unduhan DXF.

Hasil Kerfwise Sheet Nesting Optimizer dengan 16 komponen pada satu lembar dengan rendemen 82,8 persen

2. Buat kabinet

POST /api/v1/tools/kerfwise-cabinet-builder/calculate
Content-Type: application/json

{"type":"base","width":600,"height":870,"depth":560,"backType":"groove","grooveDepth":8,
 "plinthType":"legs","plinthHeight":150,"doorCount":1,"shelfCount":1,"topType":"rails"}
{
  "summary": "Base cabinet 600 × 870 × 560 mm: 9 parts, 47 hardware items, 2 hinges per door, side height 720 mm.",
  "result": {
    "dimensions": {"sideHeight": 720, "innerWidth": 564, "innerDepth": 536, "backSize": "710 × 580", "doorSize": "717 × 597", "hingesPerDoor": 2},
    "parts": [
      {"label": "A7", "name": "Back panel (grooved)", "L": 710, "W": 580, "T": 8, "cutL": 710, "cutW": 580, "material": "HDF 8 mm (backs, grooved)"}
    ],
    "totals": {"parts": 9, "holes": 112, "areaM2": 2.45, "bandingM": 6.4},
    "openInApp": "https://kerfwise.usefulweb.site/app#project=eyJmb3…"
  }
}

openInApp membuka kabinet di workspace; project berisi proyek yang sama dalam bentuk JSON.

Hasil Kerfwise Cabinet Builder dengan dimensi utama dan tabel komponen

3. Daftar potong dan biaya untuk beberapa kabinet

POST /api/v1/tools/kerfwise-cut-list/calculate
Content-Type: application/json

{"cabinets":[{"type":"base","width":600,"doors":1,"shelves":1},
             {"type":"drawer","width":600,"drawers":3},
             {"type":"wall","width":800,"doors":2}],
 "currency":"EUR","labourRate":45}
{
  "summary": "Cut list: 44 parts in 19 cut-list rows on 4 sheets (yield 44.1 %), 26 m edge banding — estimated total 868.78 EUR.",
  "result": {
    "cost": {"materials": 499, "banding": 19.05, "hardware": 164.2, "labour": 186.53, "labourMinutes": 248.7, "subtotal": 868.78, "total": 868.78, "currency": "EUR"},
    "totals": {"cabinets": 3, "partRows": 19, "pieces": 44, "holes": 266, "sheets": 4, "sheetYieldPct": 44.1, "bandingM": 26}
  }
}

Sebagai ganti tabel cabinets, kamu bisa mengirim seluruh proyek sebagai string di project (file .kerfwise.json — skemanya dipublikasikan di halaman landing Kerfwise dan di dokumen OpenAPI). Pengaturan di dalam proyek (kerf, harga, tenaga kerja) lebih diutamakan daripada field formulir.

4. Hal yang sama lewat MCP

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"kerfwise_sheet_nesting",
   "arguments":{"parts":[{"name":"Panel","length":600,"width":500,"qty":16}],
     "sheetLength":2800,"sheetWidth":2070,"kerf":4,"trim":10,"method":"guillotine","grainedMaterial":false}}}

Konten teks jawabannya dimulai dengan 16 of 16 parts fit on 1 sheet of 2800 × 2070 mm with 82.8 % yield (guillotine). dan structuredContent memuat objek result yang sama dengan API.

5. Serahkan proyek ke manusia

Buat JSON proyek (lihat skema proyek), encode dengan base64url, lalu tambahkan ke URL aplikasi:

https://kerfwise.usefulweb.site/app#project=<base64url of the JSON>

Fragmen ini tidak pernah sampai ke server; aplikasi men-decode-nya, membuka proyek, lalu menghapusnya dari bilah alamat.

Siap mencobanya?

Buka Kerfwise →