ออกแบบ MCP Tool Contract ให้ค้นพบและควบคุมได้
เรียนรู้ ออกแบบ MCP Tool Contract ให้ค้นพบและควบคุมได้ เพื่อสร้าง AI Harness สำหรับงานในประเทศไทย
เป้าหมาย: ออกแบบ contract, runtime และ evaluation ที่เปลี่ยนโมเดลให้เป็นระบบดูแลได้ · ใช้เวลาประมาณ 18 นาที
Contract → Runtime → Evidence → Improvement
Harness เปลี่ยนโมเดลทั่วไปให้ทำงานเฉพาะอย่างควบคุมได้
Contract
MCP ทำให้ client เชื่อม tool/resource/prompt ผ่าน contract ร่วมกัน แต่ server ยังต้องมี authentication, least privilege, input/output schema, timeout, audit และ human approval; description ต้องบอกผลกระทบจริง
Runtime
จัด message/context/tool/state/retry/timeout โดยไม่ซ่อน side effect
Evidence
เก็บ trace ที่ลดข้อมูลและ eval แยก failure layer
Improvement
แก้ prompt/retrieval/tool/code ตามสาเหตุและรัน regression ก่อน release
Artifact ของ Harness
MCP
ระบุ MCP ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
tool schema
ระบุ tool schema ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
resource
ระบุ resource ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
approval
ระบุ approval ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
Harness ที่ดูฉลาดแต่เปราะ
รวม policy, data และ output ใน string เดียว
debug/provenance/cache ยาก
แยก role และ structured contract
stream หรือ tool call แล้วถือว่าสำเร็จ
ข้อมูลอาจไม่ครบหรือ side effect ผิด
validate final state และ business outcome
วัดเฉพาะคำตอบสวย
ไม่เห็น retrieval/tool/cost/safety failure
layered evaluation และ trace
ทำ Harness Specification
ทีมเพิ่ม MCP tool ลบสินค้าแต่ description เขียนเพียง manage catalog
ระบุ messages, Markdown/schema, context/cache, tool/MCP, skill, state/stream และ evaluation
ดูคำตอบตัวอย่าง
แยก system policy ที่เสถียรจาก user/data dynamic ใช้ Markdown ให้คนอ่านและ JSON Schema สำหรับเครื่อง ระบุ untrusted provenance กับ permission ให้ MCP/tool ใช้ least privilege และ approval ห่อ workflow ซ้ำเป็น Skill ที่มี version/test แยก partial streaming จาก committed result จัด stable prefix เพื่อ cache โดยไม่ใส่ timestamp และสร้าง evaluation set ภาษาไทยวัด answer/retrieval/tool argument/side effect/latency/cost/escalation
- message/provenance
- human + machine format
- tool/permission contract
- skill/version
- stream/cache states
- layered Thai eval
บันทึกช่วยจำ
- ตรวจ API และ MCP specification ตาม version ที่ใช้จริง
- trace และ cache ต้องไม่เก็บ secret หรือข้อมูลส่วนบุคคลเกินวัตถุประสงค์
สรุปบทเรียนนี้
- contracts before orchestration
- validate committed result
- evaluate every layer