Faisalaffan Blog
|
🇮🇩
Faisalaffan Blog
Rekayasa Perangkat Lunak10 menit baca

MCP: Protokol yang Bikin AI Bisa Ngobrol Langsung dengan Database, Firebase, dan Grafana Anda

Model Context Protocol (MCP) adalah standar terbuka yang menghubungkan LLM dengan data dan tools eksternal — seperti USB-C untuk AI. Pelajari arsitektur, cara kerja, dan real-world setup saya: 11 MCP server dari MySQL, Firebase, Grafana LGTM, hingga Lighthouse.

Faisal Affan
Faisal Affan
Diterbitkan
Galeri
1 / 3

MCP: "USB-C" untuk AI

"The best interface is one that disappears." — Don Norman

TL;DR

Model Context Protocol (MCP) adalah open protocol buatan Anthropic yang menstandardisasi cara AI terhubung ke data dan tools eksternal. Bayangkan seperti USB-C untuk AI — satu standar koneksi untuk semua.


Masalah yang Diselesaikan MCP

Sebelum MCP, setiap integrasi AI dengan tools eksternal harus dibuat custom satu per satu. Mau koneksi ke MySQL? Bikin sendiri. Mau akses Firebase? Bikin lagi. Grafana? Satu lagi.

Hasilnya? M x N integration problem — di mana M adalah jumlah AI apps dan N adalah jumlah tools.

graph LR
    A[Claude Code] -->|Custom API| D[MySQL]
    A -->|Custom API| E[Firebase]
    A -->|Custom API| F[Grafana]
    B[Gemini CLI] -->|Custom API| D
    B -->|Custom API| E
    B -->|Custom API| F
    C[Cursor] -->|Custom API| D
    C -->|Custom API| E
    C -->|Custom API| F
    style A fill:#7c3aed,color:#fff
    style B fill:#4285f4,color:#fff
    style C fill:#0ea5e9,color:#fff

Dengan MCP, masalah M x N menjadi M + N — setiap AI app hanya perlu satu MCP client, dan setiap tool hanya perlu satu MCP server.

graph LR
    A[Claude Code] -->|MCP| G[MCP Protocol]
    B[Gemini CLI] -->|MCP| G
    C[Cursor] -->|MCP| G
    G -->|MCP| D[MySQL]
    G -->|MCP| E[Firebase]
    G -->|MCP| F[Grafana LGTM]
    G -->|MCP| H[Lighthouse]
    style A fill:#7c3aed,color:#fff
    style B fill:#4285f4,color:#fff
    style C fill:#0ea5e9,color:#fff
    style G fill:#f59e0b,color:#000

Arsitektur MCP

MCP mengikuti arsitektur client-server yang terinspirasi dari Language Server Protocol (LSP). Tiga komponen utamanya:

graph TB
    subgraph Host["MCP Host (Gemini CLI / Claude Code)"]
      C1[MCP Client 1]
      C2[MCP Client 2]
      C3[MCP Client 3]
      C4[MCP Client 4]
      C5[MCP Client 5]
    end
    C1 <-->|stdio| S1[Firebase MCP]
    C2 <-->|stdio| S2[MySQL dbhub]
    C3 <-->|stdio| S3[LGTM Stack]
    C4 <-->|SSE| S4[Context7]
    C5 <-->|stdio| S5[Lighthouse]
    S1 <--> FB[(Firebase)]
    S2 <--> DB[(MySQL)]
    S3 <--> GR[(Grafana/Loki/Tempo)]
    S4 <--> DOCS[(Documentation)]
    S5 <--> WEB[(Web Pages)]
    style Host fill:#1e1b4b,color:#fff
    style S1 fill:#059669,color:#fff
    style S2 fill:#059669,color:#fff
    style S3 fill:#059669,color:#fff
    style S4 fill:#d97706,color:#fff
    style S5 fill:#059669,color:#fff

Tiga Primitif Utama

MCP server mengekspos tiga jenis kemampuan:

PropertyTypeDescription
Tools Function Fungsi yang bisa dipanggil LLM untuk melakukan aksi. Contoh: query database, create issue, send message.
Resources Data Source Sumber data yang bisa diakses LLM (read-only). Mirip GET endpoint di REST API. Contoh: file content, database schema.
Prompts Template Template yang sudah dioptimasi untuk menggunakan tools dan resources secara efektif.

Analogi Sederhana

MCP Primitive Analogi REST API Contoh
Tools POST /action Kirim pesan Slack, buat GitHub issue
Resources GET /data Baca file, lihat schema database
Prompts Swagger/OpenAPI docs Template cara optimal gunakan tools

Transport Layer

MCP mendukung dua metode transport:

Standard I/O — untuk MCP server yang jalan di mesin yang sama.

  • Komunikasi via stdin/stdout
  • Cepat dan synchronous
  • Cocok untuk: Firebase, MySQL, Lighthouse, custom LGTM stack
JSON
{
  "mcpServers": {
    "firebase": {
      "command": "npx",
      "args": ["-y", "firebase-tools@latest", "mcp"]
    },
    "mysql": {
      "command": "npx",
      "args": ["-y", "@bytebase/dbhub", "--transport", "stdio",
               "--dsn", "mysql://user:[email protected]:3306/mydb"]
    },
    "lighthouse": {
      "command": "npx",
      "args": ["lighthouse-mcp"]
    }
  }
}

Lifecycle: Dari Handshake ke Operasi

Initialization

Client mengirim initialize request dengan protocol version dan capabilities. Server merespons dengan capabilities yang didukung.

JSON
// Client -> Server
{
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-11-25",
    "capabilities": { "roots": { "listChanged": true } }
  }
}

Discovery

Client meminta daftar tools, resources, dan prompts yang tersedia.

JSON
// Client -> Server
{ "method": "tools/list" }

// Server -> Client
{
  "tools": [
    {
      "name": "query_database",
      "description": "Execute SQL query",
      "inputSchema": { "type": "object", "properties": { "sql": { "type": "string" } } }
    }
  ]
}

Operation

LLM memanggil tools berdasarkan konteks percakapan.

JSON
// Client -> Server
{
  "method": "tools/call",
  "params": {
    "name": "query_database",
    "arguments": { "sql": "SELECT COUNT(*) FROM users WHERE active = true" }
  }
}

Membuat MCP Server Sendiri

Berikut contoh minimal MCP server menggunakan TypeScript dan Python:

Terminal
npm init -y
npm install @modelcontextprotocol/sdk zod
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "weather-server",
  version: "1.0.0",
});

// Definisikan tool
server.tool(
  "get_weather",
  "Get current weather for a city",
  { city: z.string().describe("City name") },
  async ({ city }) => {
    // Panggil weather API
    const weather = await fetch(
      `https://api.weather.example.com/${city}`
    ).then((r) => r.json());

    return {
      content: [
        {
          type: "text",
          text: `Weather in ${city}: ${weather.temp}°C, ${weather.condition}`,
        },
      ],
    };
  }
);

// Jalankan server via stdio
const transport = new StdioServerTransport();
await server.connect(transport);
Jangan Pakai console.log!

Untuk server berbasis stdio, jangan gunakan console.log() karena akan menulis ke stdout dan merusak JSON-RPC messages. Gunakan console.error() atau logging library yang menulis ke stderr.


Real-World Setup: 11 MCP Server Saya

Ini bukan teori — berikut konfigurasi MCP yang saya pakai sehari-hari di Gemini CLI dan Claude Code:

graph TB
    subgraph STDIO["stdio (Local)"]
      S1[Firebase]
      S2[MySQL - dbhub]
      S3[LGTM - Grafana Stack]
      S4[Memory]
      S5[Sequential Thinking]
      S6[Serena - Code Understanding]
      S7[Lighthouse]
      S8[Word Document]
    end
    subgraph REMOTE["SSE / Remote"]
      R1[Mintlify Docs]
      R2[Context7]
      R3[Google Stitch]
    end
    style STDIO fill:#1e3a5f,color:#fff
    style REMOTE fill:#5f1e3a,color:#fff
Firebase — Deploy, Firestore, Auth langsung dari AI

Menggunakan firebase-tools official MCP. AI bisa langsung deploy, manage Firestore rules, inspect Auth users, dan Cloud Functions — tanpa buka Firebase Console.

JSON
{
  "firebase": {
    "command": "npx",
    "args": ["-y", "firebase-tools@latest", "mcp"]
  }
}
MySQL (Bytebase dbhub) — Query database langsung

Pakai @bytebase/dbhub untuk akses MySQL. AI bisa inspect schema, jalankan query, dan analisis data langsung dari percakapan.

JSON
{
  "mysql": {
    "command": "npx",
    "args": ["-y", "@bytebase/dbhub", "--transport", "stdio",
             "--dsn", "mysql://user:[email protected]:3306/mydb"]
  }
}
LGTM Stack — Grafana, Loki, Tempo, Mimir (Custom)

MCP server custom-built untuk observability stack. AI bisa query logs dari Loki, trace dari Tempo, metrics dari Mimir, dan visualisasi dari Grafana — semua dari satu percakapan.

JSON
{
  "lgtm": {
    "command": "node",
    "args": ["/path/to/mcp-lgtm/dist/index.js"],
    "env": {
      "GRAFANA_URL": "http://localhost:3000",
      "LOKI_URL": "http://localhost:3100",
      "TEMPO_URL": "http://localhost:3200",
      "MIMIR_URL": "http://localhost:9009"
    }
  }
}
Memory — AI yang bisa 'mengingat' antar sesi

Persistent knowledge graph. AI menyimpan konteks penting ke file JSONL, sehingga sesi berikutnya tidak mulai dari nol.

JSON
{
  "memory": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-memory"],
    "env": {
      "MEMORY_FILE_PATH": "/path/to/memory.jsonl"
    }
  }
}
Context7 & Mintlify — Dokumentasi real-time

Context7 menyediakan konteks dokumentasi library terbaru langsung ke AI, jadi tidak perlu khawatir knowledge cutoff. Mintlify menghubungkan dokumentasi API yang kamu host sendiri.

JSON
{
  "context7": {
    "serverUrl": "https://mcp.context7.com/mcp"
  },
  "mintlify": {
    "serverUrl": "https://docs.yourdomain.com/mcp"
  }
}
Lighthouse — Audit performa web otomatis

AI bisa menjalankan Lighthouse audit dan langsung menganalisis hasilnya. Performance score, accessibility issues, SEO recommendations — semua dalam satu percakapan.

JSON
{
  "lighthouse": {
    "command": "npx",
    "args": ["lighthouse-mcp"]
  }
}
Sequential Thinking & Serena — AI yang berpikir lebih dalam

Sequential Thinking memaksa AI memecah reasoning jadi langkah-langkah terstruktur. Serena memberikan deep code understanding — AI bisa navigasi codebase dengan konteks yang lebih kaya dari sekadar grep.

JSON
{
  "sequential-thinking": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
  },
  "serena": {
    "command": "uvx",
    "args": ["--from", "git+https://github.com/oraios/serena",
             "serena", "start-mcp-server"]
  }
}
Google Stitch & Word — Koneksi ke Google dan Office

Google Stitch menghubungkan ke ekosistem Google API. Word Document Server memungkinkan AI membuat dan mengedit dokumen Word — berguna untuk generate laporan otomatis.

JSON
{
  "stitch": {
    "serverUrl": "https://stitch.googleapis.com/mcp",
    "headers": { "X-Goog-Api-Key": "YOUR_KEY" }
  },
  "word-document-server": {
    "command": "uvx",
    "args": ["--from", "office-word-mcp-server", "word_mcp_server"]
  }
}
Pelajaran dari Setup Ini

Perhatikan pola-nya: ada 3 tipe transport yang saya pakai:

  • npx/uvx via stdio — untuk tools yang jalan lokal (Firebase, MySQL, Lighthouse)
  • node custom script — untuk MCP server yang saya build sendiri (LGTM)
  • Remote serverUrl — untuk SaaS services (Context7, Mintlify, Google Stitch)

Ketiganya bisa jalan bersamaan di satu AI host. Itulah kekuatan standar MCP.


Siapa yang Sudah Adopsi?

MCP bukan hanya standar Anthropic — ini sudah jadi industri standard:

Company Adopsi
Anthropic Creator, Claude Desktop & Claude Code native support
OpenAI Adopsi resmi Maret 2025, terintegrasi di ChatGPT Desktop
Cursor IDE AI pertama yang full support MCP
Block Goose AI agent dengan MCP apps
Linux Foundation MCP didonasikan ke Agentic AI Foundation (AAIF)
97 Juta Downloads

Per Desember 2025, MCP SDK sudah mencapai 97 juta monthly downloads di semua bahasa pemrograman. Ini bukan eksperimen — ini production-grade protocol.


Kapan Harus Pakai MCP?


Security Considerations

Keamanan MCP

MCP bukan berarti "buka semua akses". Beberapa prinsip keamanan penting:

  • Principle of Least Privilege — Hanya expose tools yang benar-benar dibutuhkan
  • Input Validation — Selalu validasi input dari LLM sebelum eksekusi
  • Access Control — Batasi direktori, database, dan API yang bisa diakses
  • User Confirmation — Untuk aksi destructive, minta konfirmasi user
  • Audit Logging — Catat semua tool calls untuk accountability

Kesimpulan

MCP mengubah cara kita mengintegrasikan AI dengan dunia nyata. Dari yang sebelumnya harus membuat custom integration untuk setiap kombinasi AI app dan tool, sekarang cukup satu standar protokol.

Sebagai engineer, ini adalah momen yang mirip dengan kemunculan REST API — standar yang membuat ekosistem berkembang jauh lebih cepat karena semua berbicara dalam bahasa yang sama.

MCP bukan tentang membuat AI lebih pintar — tapi membuat AI lebih berguna.


Referensi

Topik:#AI

Artikel terkait

Rekayasa Perangkat Lunak

Search & Catalog 15k SKU Q-Commerce: Relevan + In-Stock Real-time

System design search dan catalog untuk quick commerce dengan 15.000+ SKU. Elasticsearch full-text search dengan multi-match query dan typo tolerance (fuzziness), filter ketersediaan per-hub via Redis pipeline query-time filtering, ranking berbasis relevansi, ketersediaan, margin, dan popularitas, index update via Kafka streaming, dan autocomplete handler. Implementasi Golang lengkap dengan worker concurrency pattern untuk index sync.
Faisal Affan
Faisal Affan
Diterbitkan

Real-time Order Tracking Q-Commerce: Driver Bergerak di Peta Live

System design real-time order tracking untuk quick commerce. Driver GPS ingestion via WebSocket dengan throttling dan validasi, Kalman filter untuk position smoothing, Redis pub/sub fan-out by order ID untuk scale ribuan driver concurrent, dan Server-Sent Events (SSE) push ke user client. Implementasi Golang dengan pattern WebSocket goroutine pool, pub/sub broker, dan concurrent connection management.
Faisal Affan
Faisal Affan
Diterbitkan
Rekayasa Perangkat Lunak
Real-time Inventory Dark Store: Cegah Oversell di Q-Commerce

Real-time Inventory Dark Store: Cegah Oversell di Q-Commerce

Desain inventory per-hub untuk Astro (instant grocery). Reservation pattern dengan Redis DECRBY atomic + TTL, async sync ke Postgres, stock partitioning untuk hot SKU, reaper job untuk reservation leak, dan cycle counting untuk stok fisik vs sistem. Implementasi Golang lengkap.
Faisal Affan
Faisal Affan
Diterbitkan

Promo & Voucher Engine Q-Commerce: Rule Engine Anti-Abuse

System design promo engine untuk quick commerce. Rule engine dengan kondisi komposable (min transaksi, first-N-order, area, kategori) ke efek (discount, free ongkir), atomic counter untuk limit penggunaan Redis Lua, anti-fraud device fingerprinting, stackable vs eksklusif promo resolution, dan budget cap. Implementasi Golang lengkap dengan composable condition interface, AND/OR composite tree, concurrent-safe redeem, serta Kafka event streaming untuk audit trail.
Faisal Affan
Faisal Affan
Diterbitkan