1. WebMCP คืออะไร
WebMCP (Web Model Context Protocol) เป็น proposed web standard จาก Google และ Microsoft ที่เปิดตัวใน Early Preview เมื่อวันที่ 10 กุมภาพันธ์ 2026 บน Chrome 146
WebMCP ช่วยให้เว็บไซต์สามารถเปิดเผย structured tools ให้ AI agents ที่ทำงานใน browser เรียกใช้ได้โดยตรง โดยไม่ต้อง screen-scraping หรือ DOM parsing
Key Concept: "Publish tools, not pixels" - เว็บไซต์กำหนดว่า AI สามารถทำอะไรได้บ้าง แทนที่จะให้ AI เดาจาก UI
Key Takeaways:
- Discovery - AI รู้ว่ามี tools อะไรบ้างบนหน้าเว็บ
- Schemas - กำหนด input/output format ชัดเจน (JSON Schema)
- State - แชร์ state ปัจจุบันระหว่างเว็บและ AI
- Two APIs - รองรับทั้ง Declarative (HTML) และ Imperative (JavaScript)
2. ปัญหาที่ WebMCP แก้
ลองนึกภาพ AI Agent พยายาม "ใช้" เว็บไซต์แบบเดิม:
วิธีเดิมที่ AI Agents ทำอยู่:
- • 📸 Screenshot - ถ่ายภาพหน้าจอและวิเคราะห์ pixel by pixel
- • 🎯 Guess buttons - เดาว่าปุ่มสีฟ้าไหนคือ "Submit"
- • 🔍 DOM scraping - ดึงข้อมูลจาก DOM แล้วหวังว่ามันไม่เปลี่ยน
- • 🖱️ Click & pray - คลิกไปเรื่อยๆ จนกว่าจะได้ผล
วิธีใหม่ด้วย WebMCP:
- • 📋 Structured Tools - เรียกใช้ฟังก์ชันที่กำหนดไว้ชัดเจน
- • 📝 JSON Schemas - รู้ input/output format แน่นอน
- • ⚡ Direct Execution - ไม่ต้องผ่าน UI manipulation
- • 🔒 Controlled Access - เว็บไซต์กำหนดว่าอนุญาตอะไรได้บ้าง
// Old way: Click around until something works
agent.click("#submit-button")
agent.waitFor(".success-message")
agent.scrapeText(".result")
// New way: Call structured tool
agent.callTool("book_flight", {
origin: "BKK",
destination: "LAX",
outboundDate: "2026-03-15",
passengers: 2
})
สถิติ: Bots คิดเป็น 51% ของ web traffic ทั้งหมด! เว็บควรมีมาตรฐานที่ดีกว่า agents ที่ต้อง "เพ่งมอง pixels"
3. Declarative vs Imperative API
WebMCP มี 2 APIs สำหรับเปิดเผย tools ให้ AI agents:
| Feature | Declarative API | Imperative API |
|---|---|---|
| Use Case | Simple forms | Dynamic interactions |
| Implementation | HTML attributes | JavaScript |
| Learning Curve | Low | Medium |
| Flexibility | Limited | High |
Declarative API (HTML Forms)
เพียงเพิ่ม attributes ใน HTML form:
<!-- แปลง HTML form เป็น AI tool -->
<form toolname="search_flights"
tooldescription="Search for available flights">
<label>
Origin:
<input name="origin" type="text" required />
</label>
<label>
Destination:
<input name="destination" type="text" required />
</label>
<label>
Date:
<input name="date" type="date" required />
</label>
<button type="submit">Search Flights</button>
</form>
Imperative API (JavaScript)
ลงทะเบียน tools ด้วย JavaScript:
// Register a tool with JavaScript
navigator.modelContext.registerTool({
name: "add_to_cart",
description: "Add a product to the shopping cart",
inputSchema: {
type: "object",
properties: {
productId: {
type: "string",
description: "Product ID to add"
},
quantity: {
type: "number",
description: "Quantity to add",
default: 1
}
},
required: ["productId"]
},
execute: async (params) => {
const { productId, quantity } = params;
// Your business logic here
const result = await addToCart(productId, quantity);
return {
success: true,
cartTotal: result.total,
message: `Added ${quantity} item(s) to cart`
};
}
});
// Other methods:
// - navigator.modelContext.unregisterTool("tool_name")
// - navigator.modelContext.provideContext([...tools])
// - navigator.modelContext.clearContext()
Pro Tip: Declarative API เหมาะสำหรับ forms ที่มีอยู่แล้ว เพียงเพิ่ม attributes ไม่ต้องเขียน JavaScript เพิ่ม!
4. วิธีลองใช้งาน WebMCP
WebMCP อยู่ใน Early Preview ต้องเปิดใช้งานผ่าน Chrome flags:
Step 1: Enable Chrome Flag
chrome://flags
# ค้นหา: WebMCP for testing
# เปิด: Enabled
# แล้ว: Relaunch Chrome
ต้องใช้ Chrome 146+ (Canary Channel)
Step 2: Install Inspector Extension
ติดตั้ง Model Context Tool Inspector Extension เพื่อ:
- • ดู registered tools บนหน้าเว็บ
- • Execute tools แบบ manual
- • Test กับ Gemini API integration
Step 3: Try Live Demo
ทดลองกับ travel booking demo:
https://travel-demo.bandarra.me/
# ทดลอง:
# 1. เปิดหน้าเว็บ
# 2. เปิด Inspector Extension
# 3. ดู "searchFlights" tool
# 4. Execute แบบ manual หรือผ่าน natural language
Quick Start: ใช้เวลาประมาณ 5 นาทีในการ setup และทดลองใช้งาน WebMCP ครั้งแรก!
5. ตัวอย่างการใช้งานจริง
E-commerce: Checkout Flow
<!-- Declarative checkout form -->
<form toolname="checkout"
tooldescription="Complete the purchase checkout"
toolautosubmit="false">
<input name="email" type="email" required />
<input name="shipping_address" required />
<select name="payment_method">
<option value="credit_card">Credit Card</option>
<option value="paypal">PayPal</option>
</select>
<button type="submit">Place Order</button>
</form>
<script>
// Handle agent-initiated checkout
document.querySelector('form').addEventListener('submit', (e) => {
if (e.agentInvoked) {
e.preventDefault();
// Process checkout
const result = await processCheckout(new FormData(e.target));
// Return structured response to AI
e.respondWith(Promise.resolve({
orderId: result.id,
status: 'completed',
estimatedDelivery: result.deliveryDate
}));
}
});
</script>
SaaS: Create Report
// Imperative API for report generation
navigator.modelContext.registerTool({
name: "generate_report",
description: "Generate a business report for a specific date range",
inputSchema: {
type: "object",
properties: {
reportType: {
type: "string",
enum: ["sales", "traffic", "inventory"],
description: "Type of report to generate"
},
startDate: {
type: "string",
format: "date",
description: "Report start date"
},
endDate: {
type: "string",
format: "date",
description: "Report end date"
},
format: {
type: "string",
enum: ["pdf", "csv", "json"],
default: "pdf"
}
},
required: ["reportType", "startDate", "endDate"]
},
execute: async (params) => {
const report = await generateReport(params);
return {
downloadUrl: report.url,
fileSize: report.size,
generatedAt: new Date().toISOString()
};
}
});
Travel Booking
Flight search, hotel booking, car rental
E-commerce
Product search, checkout, order tracking
Customer Support
Create tickets, check status, escalate
Appointments
Book appointments, reschedule, cancel
6. Events & CSS Pseudo-classes
Agent-Aware Events
// Detect when AI invokes a form
form.addEventListener('submit', (e) => {
// Check if invoked by AI agent
if (e.agentInvoked) {
console.log('Form submitted by AI agent!');
e.preventDefault();
// Return structured response to AI
const result = await processForm(new FormData(e.target));
e.respondWith(Promise.resolve(result));
}
});
// Tool activation events
form.addEventListener('toolactivated', (e) => {
console.log('Fields pre-filled by AI:', e.filledFields);
// Show visual indicator to user
});
form.addEventListener('toolcancel', (e) => {
console.log('AI cancelled the tool invocation');
// Reset form state
});
CSS Pseudo-classes
/* Visual feedback when AI is using form */
form:tool-form-active {
border: 2px solid #f59e0b;
background: rgba(245, 158, 11, 0.1);
}
/* Highlight submit button during AI operation */
button:tool-submit-active {
animation: pulse 1s infinite;
box-shadow: 0 0 20px rgba(245, 158, 11, 0.5);
}
/* Chrome provides default placeholder styles */
input::placeholder {
color: #94a3b8;
}
UX Bonus: Browser จะ focus และ pre-fill form fields ให้ user เห็น และ user ยังต้อง click submit เอง (เว้นแต่จะเปิด toolautosubmit)
7. Best Practices
1. Name Tools Precisely
ใช้ verbs ที่บอก action ชัดเจน แยกระหว่าง "executing" vs "initiating UI flow"
// Good
"create-event" vs "start-event-creation-process"
// Bad
"do-stuff" or "handle-form"
2. Reduce "Model Math"
ถ้า user พูดว่า "11:00 to 15:00" ให้รับ string ไม่ต้องบังคับให้ model คำนวณ minutes-from-midnight
3. Validate Strictly, Schema Loosely
Schema ไม่สามารถป้องกันทุกอย่างได้ ให้ return descriptive errors เพื่อให้ model retry ได้ถูกต้อง
4. Make Tools Atomic & Composable
หลีกเลี่ยง overlapping tools เยอะๆ ใช้ parameters แทนการสร้าง tools ที่คล้ายกัน 10 ตัว
8. ข้อจำกัดของ WebMCP
WebMCP ยังอยู่ใน Early Preview มีข้อจำกัดสำคัญ:
No Headless Mode
Tool calls ต้องการ visible browsing context (tab/webview) ไม่สามารถทำงาน background ได้
UI Must Stay in Sync
App ต้อง reflect state updates ไม่ว่าจะมาจาก human หรือ agent
Complex Apps May Need Refactors
แอปที่ซับซ้อนอาจต้องปรับโครงสร้างให้ tool-driven UI updates ทำงานได้ clean
Discoverability Not Solved
ไม่มี built-in way ให้ clients รู้ว่าไหน support tools โดยไม่ต้อง visit ก่อน
Important: WebMCP ไม่ใช่ magic wand เป็นเพียง contract - คุณยังต้อง implement contract ให้ดี!
9. ปัญหาและการแก้ไข
ปัญหาที่พบบ่อยและวิธีแก้
ปัญหา: Tools ไม่แสดงใน Inspector
// รอให้ DOM ready ก่อน register
document.addEventListener('DOMContentLoaded', () => {
navigator.modelContext.registerTool({...});
});
// หรือใช้ defer script
<script src="app.js" defer></script>
ปัญหา: Form validation ไม่ทำงานกับ agent
execute: async (params) => {
// Manual validation
if (!params.email || !isValidEmail(params.email)) {
return {
error: "Invalid email format",
field: "email",
suggestion: "Please provide a valid email"
};
}
// Process...
}
ปัญหา: AI hallucinates tool parameters
inputSchema: {
type: "object",
properties: {
date: {
type: "string",
format: "date",
description: "Booking date in YYYY-MM-DD format",
examples: ["2026-03-15", "2026-04-01"]
}
}
}
ปัญหา: Tool state ไม่ sync กับ UI
execute: async (params) => {
// Update state (will reflect in UI)
appState.cart.add(params.productId);
// Trigger re-render if needed
renderCart();
return { success: true };
}
Need Help? สามารถ report bugs และขอ features ได้ที่ WICG/webmcp GitHub
สรุป
WebMCP เป็นมาตรฐานใหม่ที่น่าสนใจสำหรับการสร้าง "AI-first" web applications โดยมีจุดเด่น:
- เปลี่ยน websites เป็น structured AI tools
- 2 APIs: Declarative (HTML) + Imperative (JavaScript)
- Eliminates brittle UI scraping
- Agent-aware events และ CSS pseudo-classes
- Backed by Google & Microsoft (W3C proposal)