← 모든 튜토리얼 · Threadsmith

튜토리얼 6 / 10

API와 MCP로 Threadsmith 자동화하기

고급 15분

스크립트와 AI 에이전트에서 텍스트, 도형, SVG 또는 프로젝트 전체를 디지타이징하고, DST, PES, JEF, EXP 파일을 만들고, 자수 파일을 분석해요. 실제 요청과 응답 예시도 함께 볼 수 있어요.

Threadsmith의 스티치 엔진은 앱과 서버에서 똑같은 TypeScript 코드로 돌아가요. 엔진 도구 다섯 개를 JSON API와 MCP 도구로 쓸 수 있어서, 스크립트와 AI 에이전트가 디자인을 만든 뒤 사람에게 넘기면 그 사람이 앱에서 열 수 있어요.

작은 로봇이 자수기를 돌려 꽃 배지를 수놓는 일러스트

도구APIMCP 도구 이름
threadsmith-digitizePOST /api/v1/tools/threadsmith-digitize/calculatethreadsmith_digitize
threadsmith-stitch-filePOST /api/v1/tools/threadsmith-stitch-file/calculatethreadsmith_stitch_file
threadsmith-design-statsPOST /api/v1/tools/threadsmith-design-stats/calculatethreadsmith_design_stats
threadsmith-sequence-optimizerPOST /api/v1/tools/threadsmith-sequence-optimizer/calculatethreadsmith_sequence_optimizer
threadsmith-path-booleanPOST /api/v1/tools/threadsmith-path-boolean/calculatethreadsmith_path_boolean

API는 https://threadsmith.usefulweb.site(메인 사이트에서도)에서 돌아가요. 프로젝트 파일 형식은 /project.schema.json에 공개되어 있고, MCP 엔드포인트는 /mcp예요.

모든 좌표 단위는 밀리미터예요. x는 오른쪽, y는 아래쪽으로 커지고, (0, 0)은 후프 중심이에요.

1. 글자 디지타이징

POST /api/v1/tools/threadsmith-digitize/calculate
Content-Type: application/json

{
  "source": "text",
  "text": "Ada",
  "textSize": 14,
  "stitchType": "satin",
  "satinWidth": 2,
  "color": "navy",
  "includeStitches": true
}

응답(줄인 것이지만 값은 실제 값이에요):

{
  "summary": "394 stitches in 1 colour(s), 39.2 × 16.4 mm, 9 trim(s), about 1 min 12 s at 700 stitches/min.",
  "result": {
    "stitches": 394, "jumps": 10, "trims": 9, "colorChanges": 0,
    "widthMm": 39.2, "heightMm": 16.4, "sewingTime": "1 min 12 s",
    "topThreadM": 1.23, "bobbinThreadM": 0.3,
    "hoop": { "id": "130x180", "fits": true, "overflowMm": 0 },
    "density": { "maxLayers": 2.12, "areaOverMm2": 0, "threshold": 2.6 },
    "colors": [{ "name": "Navy", "hex": "#1d2a52", "stitches": 394, "topThreadM": 1.23 }],
    "stitchList": [[-7.28, 7, "jump"], [-7.28, 7, "stitch"], [-7.54, 6.35, "stitch"], [-7.28, 7, "stitch"], "…"],
    "project": { "format": "threadsmith", "version": 1, "objects": ["…"] },
    "openInApp": "https://threadsmith.usefulweb.site/app#project=eyJmb3JtYXQiOi…"
  }
}
  • openInApp에는 프로젝트 전체가 URL 프래그먼트에 담겨 있어요(서버로는 전송되지 않아요). 이 링크를 다른 사람에게 주면 그 사람의 브라우저에서 디자인이 편집 가능한 사본으로 열려요.
  • stitchList(includeStitches: true일 때만 포함)는 기계가 실행할 전체 계획이에요. [x, y, type] 형식이고 type은 stitch, jump, trim, color, end 중 하나예요. 위의 첫 항목들은 첫 번째 점으로의 점프와 시작 매듭(tie-in)이에요.
  • presentation(위에는 생략)에는 실처럼 보이는 SVG 미리보기와 표가 들어 있어서 바로 화면에 보여 줄 수 있어요.

다른 source 값으로는 shape(ellipse, rect, star, hexagon, heart와 widthMm/heightMm), path (mm 단위 pathD), svg(SVG 마크업, 선택 항목 fitWidth), project가 있어요.

스티치 수, 실 자르기 횟수, 크기, 자수 시간, 실 사용량 예상치가 표시된 Threadsmith 디지타이저 결과 페이지

2. 프로젝트 전체 만들기

프로젝트를 JSON 텍스트로 보내요. 이 예시는 틸 색 타타미 배지에 아웃라인 글꼴 이니셜과 새틴 테두리를 넣은 디자인이에요:

{
  "source": "project",
  "project": "{\"name\":\"Agent badge\",\"hoop\":\"100x100\",\"objects\":[{\"kind\":\"ellipse\",\"cx\":0,\"cy\":0,\"rx\":30,\"ry\":30,\"color\":\"teal\",\"stitch\":{\"type\":\"tatami\",\"angle\":30}},{\"kind\":\"text\",\"text\":\"HI\",\"x\":0,\"y\":8,\"size\":18,\"font\":\"outline\",\"weight\":3,\"color\":\"gold\",\"stitch\":{\"type\":\"satin\"}},{\"kind\":\"ellipse\",\"cx\":0,\"cy\":0,\"rx\":30,\"ry\":30,\"color\":\"navy\",\"stitch\":{\"type\":\"satin\",\"mode\":\"border\",\"width\":3}}]}"
}

결과: "3,495 stitches in 3 colour(s), 63.4 × 63.4 mm, 3 trim(s), about 5 min 54 s at 700 stitches/min."(3색 3,495스티치, 63.4 × 63.4 mm, 실 자르기 3회, 분당 700스티치 기준 약 5분 54초) 그리고 자수 순서는 ["o1", "o2", "o3"], 색별 사용량은 Teal 2,637 / Old gold 228 / Navy 630스티치예요.

오브젝트 종류: path(d), rect(x y w h r), ellipse(cx cy rx ry), polygon(cx cy radius sides inner), text(text x y size font weight align spacing slant), stitches(points). 모든 오브젝트에는 color(팔레트 실 ID, ruby 같은 내장 실 ID 또는 #rrggbb)와 stitch가 있고, 선택 항목으로 underlay, start, end가 있어요. 빠진 값에는 적절한 기본값이 들어가고, 잘못된 값은 알기 쉬운 문장으로 오류를 알려 줘요. 예: Object 1: unknown kind "blob" (use path, rect, ellipse, polygon, text, stitches).(오브젝트 1: 알 수 없는 종류 "blob", path, rect, ellipse, polygon, text, stitches 중 하나를 쓰세요)

3. DST 파일 만들기

1단계에서 받은 스티치 목록을 JSON 문자열로 파일 작성기에 넘겨요:

{ "format": "dst", "label": "ADA", "stitches": "[[-7.28,7,\"jump\"],[-7.28,7,\"stitch\"],[-7.54,6.35,\"stitch\"], …]" }

실제 응답:

{
  "summary": "stitches.dst: 1,820 bytes, 394 stitch and 41 jump records, 0 colour change(s); round-trip verified.",
  "result": {
    "format": "dst", "bytes": 1820, "records": 436, "stitchRecords": 394, "jumpRecords": 41,
    "verified": true, "maxErrorMm": 0.07,
    "header": { "LA": "ADA", "ST": "435", "CO": "0", "+X": "197", "-X": "195", "+Y": "82", "-Y": "82",
                "AX": "+  197", "AY": "-   70", "MX": "+    0", "MY": "+    0", "PD": "******" },
    "firstRecords": [
      { "index": 1, "hex": "66 80 9b", "meaning": "jump", "dx": -73, "dy": -70 },
      { "index": 2, "hex": "00 00 03", "meaning": "stitch", "dx": 0, "dy": 0 },
      { "index": 3, "hex": "a1 42 03", "meaning": "stitch", "dx": -2, "dy": 7 }
    ],
    "artifactUrl": "https://threadsmith.usefulweb.site/artifacts/a40945972495e824e538c3e31da1e24e/stitches.dst",
    "base64": "TEE6QURBICAgICAgICAgICAgIA1TVDogICAgNDM1…"
  }
}

작성기는 만든 파일을 다시 디코딩해서 verified와 가장 큰 위치 차이(maxErrorMm, 대각선 방향으로 최대 0.1 mm 기계 단위의 절반)를 알려 줘요. 파일은 artifactUrl에서 내려받거나(약 2시간 동안 보관돼요) base64를 디코딩해서 얻을 수 있어요. 점프 수에는 실 자르기도 포함돼요. 실 자르기 하나는 합이 0인 점프 세 개로 기록되거든요. stitches 대신 "project": "…"를 보낼 수도 있고, "format": "pes"(Brother), "jef"(Janome), "exp"(Melco)도 쓸 수 있어요. PES와 JEF 결과에는 machineThreads가 추가돼요. 색 정지 지점마다 가장 가까운 Brother/Janome 실 차트 색을 골라 준 것으로, 예를 들어 잎 템플릿이라면 [{ "index": 54, "name": "Emerald Green", "hex": "#00673e" }, …](에메랄드 그린)처럼 나와요.

첫 번째 레코드 읽기: DST는 y를 위쪽 방향으로 저장하므로 (−7.28, 7) mm로의 점프는 0.1 mm 단위로 dx −73, dy −70이 돼요. 66 80 9b는 이 값들을 평형 3진법으로 인코딩한 것이고, 세 번째 바이트에 점프 플래그 0x80이 설정되어 있어요.

4. 기존 파일 분석하기

{
  "file": { "filename": "ada.dst", "contentBase64": "TEE6QURBICAgICAg…" },
  "spm": 800,
  "colors": ["#1d2a52"],
  "hoop": "100x100"
}

응답: DST "ADA": 394 stitches, 1 colour(s), 9 trim(s), 39.2 × 16.4 mm, about 1 min 6 s at 800 stitches/min, 1.23 m top thread.(1색 394스티치, 실 자르기 9회, 39.2 × 16.4 mm, 분당 800스티치 기준 약 1분 6초, 윗실 1.23 m) 디지타이저와 숫자가 똑같아서 파일이 손실 없이 정확히 왕복된다는 걸 확인할 수 있어요. 결과에는 밀도 한도를 넘는 hotspots 목록과 12.1 mm보다 길거나 0.3 mm보다 짧은 스티치에 대한 경고도 들어 있어요.

5. MCP로 똑같이 하기

MCP 클라이언트를 https://threadsmith.usefulweb.site/mcp(streamable HTTP)에 연결해요. tools/list가 세 가지 도구를 돌려주고, 같은 인수로 호출하면 돼요:

{ "jsonrpc": "2.0", "id": 2, "method": "tools/call",
  "params": { "name": "threadsmith_digitize",
              "arguments": { "source": "shape", "shape": "star", "widthMm": 50, "heightMm": 50, "stitchType": "contour", "color": "citrine" } } }

응답의 structuredContent.summary는 "323 stitches in 1 colour(s), 45.4 × 43.1 mm, 1 trim(s), about 30 s at 700 stitches/min."(1색 323스티치, 45.4 × 43.1 mm, 실 자르기 1회, 분당 700스티치 기준 약 30초)이고, structuredContent.result에는 API와 같은 필드가 들어 있어요.

좋은 에이전트 작업 흐름

  1. 사용자의 요청을 바탕으로 프로젝트 JSON을 만들어요(/project.schema.json 참고).
  2. source: "project"로 threadsmith_digitize를 호출하고 warnings, hoop.fits, density를 확인해요.
  3. 경고가 사라질 때까지 조정해요(크기 줄이기, 밀도 낮추기, 다른 스티치 종류 쓰기).
  4. 사용자가 검토하고 다듬을 수 있도록 openInApp 링크를 건네거나, DST가 필요하면 threadsmith_stitch_file을 호출해요(둘 다 해도 돼요).
  5. 시험 자수를 꼭 해 보라고 사용자에게 알려 줘요. 예상치는 계획용 수치일 뿐이고, DST/EXP 파일에는 실 색 정보가 없으며 PES/JEF에는 가장 가까운 기계 실 차트 색만 들어가요.

사용해 볼 준비가 되셨나요?

Threadsmith 실행 →