π Topik
Model Context Protocol (MCP): standar integrasi tools untuk AI agent
Fokus: MCP 2026-07-28, stateless protocol, tool calling, MRTR, caching, auth, dan deployment produksi.
π― Tujuan Belajar
Besok bisa:
- Menjelaskan MCP dibanding REST API biasa.
- Membuat MCP server TypeScript dengan SDK v2.
- Menjalankan server di balik load balancer tanpa sticky session.
- Menggunakan
tools/list,tools/call,server/discover. - Mendesain state eksplisit dan aman.
- Menangani konfirmasi user melalui Multi Round-Trip Requests (MRTR).
- Menghindari kebocoran credential, state tampering, dan tool over-permission.
π Ringkasan Singkat
MCP adalah protokol standar agar LLM host dapat menemukan dan menjalankan tools, membaca resources, serta memakai prompt dari sistem eksternal. Nilai utamanya bukan βAPI baruβ, melainkan kontrak interoperabilitas: client, server, gateway, authorization, observability, dan tool metadata memakai bentuk yang sama.
Versi terbaru terverifikasi: MCP 2026-07-28, dirilis 28 Juli 2026. Perubahan terbesar: protocol core menjadi stateless. initialize, notifications/initialized, dan Mcp-Session-Id tidak lagi menjadi bagian core request path. Setiap request membawa metadata sendiri, sehingga request bisa masuk ke instance mana pun.
π Temuan Utama
| Aspek | MCP lama | MCP 2026-07-28 |
|---|---|---|
| Handshake | initialize wajib |
Dihapus dari modern request path |
| Session | Mcp-Session-Id |
Dihapus dari protocol core |
| Load balancer | Sticky session atau shared session store | Round-robin biasa |
| Server-to-client request | Open stream | MRTR dengan retry |
| Tool catalog | Sering fetch ulang | Mendukung ttlMs dan cacheScope |
| Routing gateway | Parse JSON body | Baca Mcp-Method, Mcp-Name |
| Long-running operation | Connection/session bergantung | Tasks extension dengan polling |
| Legacy HTTP+SSE | Dipakai versi lama | Deprecated |
| SDK TypeScript | @modelcontextprotocol/sdk v1.x |
@modelcontextprotocol/server v2.x |
| State aplikasi | Tersembunyi di session | Handle eksplisit atau requestState |
MCP bukan pengganti seluruh API internal. MCP menjadi adapter standar untuk agent-facing API.
ποΈ Arsitektur & Alur Teknis
LLM Host
β
β MCP Client
β - discover tools
β - pilih tool
β - kirim arguments
β - tampilkan approval UI
β
βΌ
MCP Gateway / HTTP Load Balancer
β
β Mcp-Method: tools/call
β Mcp-Name: deploy
β
βΌ
MCP Server Instance A/B/C
β
βββ Tool handler
βββ Auth validation
βββ Input validation
βββ Business API / DB
βββ Audit log / tracing
Alur tools/call
1. Client mengirim tools/call
2. Gateway membaca Mcp-Method dan Mcp-Name
3. Load balancer memilih instance apa pun
4. Server memvalidasi:
- protocol version
- auth
- input schema
- authorization user
5. Tool menjalankan aksi
6. Server mengembalikan resultType: complete
Alur MRTR
Dipakai ketika tool perlu konfirmasi atau input tambahan.
Client ββ tools/call ββββββββββββββββΊ Server
Client ββ resultType: input_required β Server
Client ββ tampilkan form/approval ββββΊ User
Client ββ tools/call + inputResponses ββΊ Server
Client ββ resultType: complete ββββββββ Server
requestState harus:
- Opaque bagi client.
- Tidak dibaca atau diubah client.
- Memiliki integrity protection.
- Memiliki expiry.
- Terikat ke user, method, dan authorization context jika memengaruhi security.
π» Kode Nyata / Konfigurasi
Versi terverifikasi
Hasil registry pada 27 Oktober 2026:
Node.js: v22.23.1
@modelcontextprotocol/server: 2.4.0
@modelcontextprotocol/node: 2.1.2
@modelcontextprotocol/sdk: 1.32.2
Python package mcp: 2.3.0
Untuk MCP 2026-07-28, gunakan package v2. Package lama @modelcontextprotocol/sdk adalah maintenance line v1.
Instalasi
mkdir mcp-demo
cd mcp-demo
npm init -y
npm install @modelcontextprotocol/server@2.4.0 \
@modelcontextprotocol/node@2.1.2 \
zod@4
Tambahkan "type": "module" pada package.json.
MCP server TypeScript-compatible JavaScript
Simpan sebagai server.mjs:
import http from "node:http";
import { z } from "zod";
import {
McpServer,
createMcpHandler,
createRequestStateCodec,
} from "@modelcontextprotocol/server";
import { toNodeHandler } from "@modelcontextprotocol/node";
const stateCodec = createRequestStateCodec({
key: process.env.STATE_KEY ?? "replace-this-with-32-byte-secret-key",
ttlSeconds: 300,
});
function createServer() {
const server = new McpServer(
{ name: "deployment-mcp", version: "1.0.0" },
{
cacheHints: {
"tools/list": {
ttlMs: 60_000,
cacheScope: "public",
},
},
requestState: {
verify: stateCodec.verify,
},
},
);
server.registerTool(
"deploy",
{
description: "Deploy service after explicit user confirmation.",
inputSchema: z.object({
service: z.string().min(1).max(100),
}),
},
async ({ service }, context) => {
const state = context.mcpReq.requestState?.();
if (!state) {
return {
resultType: "input_required",
inputRequests: {
confirm_deploy: {
method: "elicitation/create",
params: {
mode: "form",
message: `Deploy ${service} to production?`,
requestedSchema: {
type: "object",
properties: {
ok: { type: "boolean" },
},
required: ["ok"],
},
},
},
},
requestState: await stateCodec.mint({ service }, context),
};
}
const confirmation = context.mcpReq.inputResponses?.confirm_deploy;
if (confirmation?.action !== "accept") {
return {
content: [{ type: "text", text: "Deployment cancelled." }],
};
}
// Replace with real deployment API call.
return {
content: [{
type: "text",
text: `Deployment started for ${state.service}.`,
}],
};
},
);
return server;
}
const handler = createMcpHandler(
() => createServer(),
{ legacy: "reject" },
);
http
.createServer(toNodeHandler(handler))
.listen(3000, "127.0.0.1", () => {
console.log("MCP server listening on http://127.0.0.1:3000/mcp");
});
Jalankan:
STATE_KEY="$(openssl rand -hex 32)" node server.mjs
Request modern
Modern request wajib membawa:
- Header
MCP-Protocol-Version. - Header
Mcp-Method. - Header
Mcp-Nameuntuk tool call. _meta.io.modelcontextprotocol/protocolVersion._meta.io.modelcontextprotocol/clientInfo._meta.io.modelcontextprotocol/clientCapabilities.
Contoh:
curl -s http://127.0.0.1:3000/mcp \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2026-07-28' \
-H 'Mcp-Method: tools/list' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "demo-client",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}'
Hasil penting:
{
"result": {
"tools": [
{
"name": "deploy",
"description": "Deploy service after explicit user confirmation.",
"inputSchema": {
"type": "object",
"properties": {
"service": {
"type": "string",
"minLength": 1,
"maxLength": 100
}
},
"required": ["service"]
}
}
],
"resultType": "complete",
"ttlMs": 60000,
"cacheScope": "public"
}
}
Header tool call
POST /mcp HTTP/1.1
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: deploy
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "deploy",
"arguments": {
"service": "billing-api"
},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "demo-client",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {
"elicitation": {}
}
}
}
}
Server mengembalikan:
{
"result": {
"resultType": "input_required",
"inputRequests": {
"confirm_deploy": {
"method": "elicitation/create",
"params": {
"mode": "form",
"message": "Deploy billing-api to production?"
}
}
},
"requestState": "v1.opaque-hmac-protected-value"
}
}
Client mengirim ulang request dengan:
{
"requestState": "v1.opaque-hmac-protected-value",
"inputResponses": {
"confirm_deploy": {
"action": "accept",
"content": {
"ok": true
}
}
}
}
Jangan menganggap requestState aman hanya karena namanya opaque. Tanpa HMAC/AEAD, model atau client berbahaya dapat memodifikasi state.
π Angka & Benchmark
Benchmark lokal
Benchmark dilakukan pada:
Node.js v22.23.1
MCP server lokal
localhost HTTP
Tool ping tanpa database/API eksternal
Concurrency: 64
Total request: 2.000
Hasil:
712 req/s
p50: 70.93 ms
p95: 185.97 ms
p99: 327.11 ms
Ini bukan benchmark MCP umum. Hasil hanya mengukur server lokal, HTTP, JSON parsing, schema handling, dan per-request server construction. Tidak mewakili production latency.
Angka ekosistem
Blog resmi MCP menyatakan bahwa pada Juli 2026:
- Tier 1 SDK mendekati setengah miliar download per bulan.
- SDK TypeScript dan Python masing-masing melewati 1 miliar total download.
Angka ini adalah klaim dari project maintainers, bukan audit independen.
βοΈ Trade-off & Alternatif
MCP vs REST API
| Aspek | MCP | REST |
|---|---|---|
| Target utama | LLM agent | Aplikasi dan service |
| Tool discovery | Built-in tools/list |
Perlu OpenAPI/docs |
| Schema input | Built-in | OpenAPI/JSON Schema opsional |
| Human approval | MRTR/elicitation | Buat sendiri |
| Client interoperability | Tinggi bila host mendukung MCP | Client harus dibuat per API |
| Observability | Metadata protocol standar | Bergantung implementasi |
| Cocok untuk | Agent-facing capability | Public/internal business API |
Rekomendasi:
- Pertahankan REST/gRPC sebagai core business API.
- Tambahkan MCP adapter sebagai agent-facing layer.
- Jangan expose database mentah sebagai MCP tool.
- Jangan memberi tool izin lebih besar daripada use case.
Stateless protocol
Kelebihan:
- Tidak perlu sticky session.
- Tidak perlu session store untuk protocol state.
- Cocok untuk Lambda, Workers, container autoscaling.
- Deploy dan rolling restart lebih sederhana.
- Gateway bisa route berdasarkan header.
- State eksplisit lebih mudah diaudit.
Kekurangan:
- Client harus menyimpan dan mengirim handle/state.
- Request dapat lebih besar.
- State perlu signed/encrypted.
- Retry menjadi tanggung jawab desain tool.
- Tool wajib idempotent atau memiliki idempotency key.
MRTR vs open stream
MRTR:
- Lebih cocok untuk serverless.
- Tidak membutuhkan connection panjang.
- Retry mudah diobservasi.
- Lebih tahan terhadap reconnect.
Open stream lama:
- Lebih natural untuk interaksi dua arah.
- Cocok untuk alur real-time lama.
- Lebih sulit di-load-balance.
- Membutuhkan session lifecycle dan stream recovery.
π Use Case Produksi & Failure Mode Umum
Use case
- Deployment tool dengan approval.
- Query database terkontrol.
- Pembuatan tiket Jira/GitHub.
- Pencarian knowledge base internal.
- Operasi cloud resource.
- CI/CD trigger.
- Monitoring dan incident response.
- Agent UI dengan MCP Apps.
- Job panjang melalui Tasks extension.
Failure mode
| Failure | Penyebab | Perbaikan |
|---|---|---|
400 Bad Request |
Header dan body method berbeda | Generate header dari RPC method |
-32022 Unsupported protocol version |
Client/server tidak sepakat versi | Version negotiation atau legacy lane |
| Tool tidak muncul | Schema invalid atau registration gagal | Test tools/list, validasi Zod |
| State diterima instance berbeda | State hanya tersimpan memory lokal | Gunakan signed state atau shared DB |
| Deployment ganda | Retry setelah timeout | Idempotency key dan deduplication |
| Credential bocor | Credential dimasukkan form biasa | Gunakan URL mode/OAuth, jangan form mode |
| DNS rebinding | Server bind 0.0.0.0 tanpa Origin validation |
Validasi Origin, bind localhost untuk local server |
| Cache data sensitif | cacheScope: public |
Gunakan private untuk user-specific response |
| Tool abuse | Tool punya permission terlalu besar | Least privilege, authorization per call |
| Session lama rusak setelah migrasi | Masih melayani client pre-2026 | Simpan legacy lane sampai traffic nol |
| State tampering | requestState dipercaya mentah |
HMAC/AEAD, expiry, binding ke principal |
MCP 2026-07-28 masih mempertahankan backward compatibility lane untuk client lama. Jangan menghapus sticky session dan session store sebelum traffic versi lama mencapai nol.
π Security Checklist
- Validasi
Origin; invalid origin harus mendapat HTTP403. - Untuk server lokal, bind ke
127.0.0.1, bukan0.0.0.0. - Autentikasi setiap connection.
- Validasi OAuth
isssesuai RFC 9207. - Jangan reuse credential lintas authorization server.
- Perlakukan tool arguments sebagai input tidak tepercaya.
- Terapkan authorization setelah authentication.
- Validasi semua
requestState. - Gunakan expiry pendek.
- Bind state ke:
- user/principal,
- method,
- tenant,
- resource target.
- Audit setiap
tools/call. - Tool destructive wajib approval eksplisit.
- Jangan memasukkan API key/password dalam elicitation
form. - Gunakan URL mode untuk sensitive credential flow.
- Rate-limit berdasarkan
Mcp-MethoddanMcp-Name. - Tambahkan W3C Trace Context/OpenTelemetry.
- Batasi body request, tool timeout, dan concurrency.
π οΈ Latihan Praktis Kecil
- Jalankan server contoh.
- Panggil
tools/list. - Panggil
deploy. - Ambil
requestState. - Kirim retry dengan
inputResponses. - Ubah satu karakter dalam
requestState. - Amati error:
{
"code": -32602,
"message": "Invalid or expired requestState",
"data": {
"reason": "invalid_request_state"
}
}
- Jalankan dua instance server di port berbeda.
- Letakkan reverse proxy round-robin di depan keduanya.
- Pastikan retry MRTR dapat diproses instance berbeda.
Tes tambahan:
curl -i http://127.0.0.1:3000/mcp \
-X POST \
-H 'Origin: https://evil.example' \
-H 'Content-Type: application/json' \
--data '{}'
Expected: 403 Forbidden setelah Origin validation diaktifkan pada deployment server.
β Cek Pemahaman
- Mengapa MCP
2026-07-28tidak membutuhkan sticky session untuk protocol state? - Mengapa
requestStateharus memiliki HMAC atau AEAD? - Kapan MCP sebaiknya menjadi adapter di depan REST API, bukan menggantikan REST API?
π Poin Kunci
- MCP menstandardisasi koneksi LLM β tools/resources/prompts.
- MCP
2026-07-28memakai stateless protocol core. initializedanMcp-Session-Idtidak dipakai pada modern request path.- State aplikasi tetap boleh ada; simpan lewat handle eksplisit.
- MRTR mengganti server-initiated request melalui retry.
Mcp-MethoddanMcp-Namemembantu routing, metering, dan WAF.ttlMsdancacheScopememungkinkan caching tool catalog.requestStateadalah input dari client; jangan percaya tanpa verifikasi.- MCP bukan alasan menghapus business API yang sudah ada.
- Production MCP perlu auth, authorization, idempotency, audit, rate limit, dan observability.
π Status Pengetahuan
DIKETAHUI
- MCP specification terbaru terverifikasi:
2026-07-28. - Stateless core, MRTR, cache hints, header routing, Tasks extension, dan deprecation policy tercantum pada dokumentasi resmi.
- SDK TypeScript v2 tersedia pada package terpisah.
- Contoh server telah dijalankan pada Node.js
v22.23.1. tools/list,tools/call, MRTR, cache hints, dan invalid state telah diuji lokal.
DIINFERENSI
- Stateless MCP mengurangi biaya operasional jika deployment sebelumnya memakai sticky routing dan shared session store.
- Explicit state lebih mudah diaudit daripada state tersembunyi di protocol session.
- Adapter MCP di depan REST/gRPC paling aman untuk sistem existing.
BELUM PASTI
- Tidak ada benchmark resmi lintas SDK, cloud, model host, dan transport yang cukup untuk menyimpulkan penghematan latency atau biaya secara universal.
- Dukungan MCP
2026-07-28pada setiap AI host belum seragam. Verifikasi compatibility matrix sebelum migrasi produksi.
π Sumber
-
Model Context Protocol. βThe 2026-07-28 Specification.β 28 Juli 2026.
https://blog.modelcontextprotocol.io/posts/2026-07-28/ -
Model Context Protocol. βStreamable HTTP β Specification
2026-07-28.β
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http -
Model Context Protocol. βMulti Round-Trip Requests β Specification
2026-07-28.β
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -
Model Context Protocol. βChangelog β Specification
2026-07-28.β
https://modelcontextprotocol.io/specification/2026-07-28/changelog -
Model Context Protocol TypeScript SDK. v2, main branch. Diakses 27 Oktober 2026.
https://github.com/modelcontextprotocol/typescript-sdk -
Cloudflare. βThe next generation of MCP.β 2026.
https://blog.cloudflare.com/mcp-v2 -
AWS Architecture Blog. βMCP went stateless: Is your AWS MCP server deployment well-architected?β 27 Agustus 2026.
https://aws.amazon.com/blogs/architecture/mcp-went-stateless-is-your-aws-mcp-server-deployment-well-architected/
β‘οΈ Eksplorasi Lanjut
- MCP Tasks untuk CI/CD dan deployment berdurasi panjang.
- MCP Apps dan sandboxed interactive UI.
- OAuth 2.0, Client ID Metadata Documents, dan Enterprise Managed Authorization.
- MCP conformance testing.
- Tool authorization berbasis tenant dan capability.
- Idempotency design untuk agent retry.
- MCP gateway: rate limiting, WAF, tracing, dan cost attribution.
- Perbandingan MCP, A2A, OpenAPI tool calling, dan function calling provider-specific.