Advanced

Setup MCP Server Claude Code dan Use Case Praktis

Panduan lengkap tentang kemampuan MCP server Claude Code. Pelajari cara menghubungkan tool eksternal, mengonfigurasi server, dan contoh integrasi dunia nyata.

Apa Itu MCP?

MCP (Model Context Protocol) adalah protokol terbuka untuk menghubungkan AI assistant dengan tool dan sumber data eksternal. Claude Code bertindak sebagai MCP client, memungkinkannya berinteraksi dengan database, API, dan berbagai layanan melalui MCP server.

Mengonfigurasi MCP Server

Pengaturan MCP server ditempatkan di .claude/settings.json atau ~/.claude/settings.json:

{
  "mcpServers": {
    "server-name": {
      "command": "executable-command",
      "args": ["arg1", "arg2"],
      "env": {
        "ENV_VAR": "value"
      }
    }
  }
}

Kamu juga bisa menambahkan server melalui CLI:

claude mcp add server-name -- command arg1 arg2

Contoh 1: Integrasi Database

Siapkan MCP server untuk menjalankan query langsung ke PostgreSQL:

claude mcp add postgres-server -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost:5432/mydb

Setelah dikonfigurasi, kamu bisa melakukan query database dari dalam sesi Claude Code:

> Count the new user registrations from the past week in the users table
> Show the daily trend in a table format

Claude Code otomatis menghasilkan dan mengeksekusi query SQL, lalu memformat hasilnya untukmu.

Contoh 2: Integrasi GitHub

MCP server GitHub memungkinkanmu mengelola issue dan PR langsung dari Claude Code:

claude mcp add github -- npx -y @modelcontextprotocol/server-github

Siapkan token melalui environment variable:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
      }
    }
  }
}

Berikut yang bisa kamu lakukan:

> List all open issues in the repository
> Look at Issue #42, create a fix branch, and implement the solution
> Once the fix is done, create a PR

Contoh 3: Ekstensi Filesystem

MCP server yang memberikan akses aman ke direktori tertentu:

claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/allowed/directory

Contoh 4: Web Scraping

MCP server Puppeteer memungkinkan pengambilan dan interaksi dengan halaman web:

claude mcp add puppeteer -- npx -y @modelcontextprotocol/server-puppeteer
> Read the API documentation at https://example.com/api/docs
> and create a client library for that API

Contoh 5: Integrasi Slack

MCP server Slack memungkinkanmu membaca pesan dari channel dan mengirim notifikasi:

{
  "mcpServers": {
    "slack": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-slack"],
      "env": {
        "SLACK_BOT_TOKEN": "xoxb-xxxxxxxxxxxx"
      }
    }
  }
}
> Check the latest messages in #dev
> Post today's progress update to #daily-report

Mengelola MCP Server

Lihat Daftar Server yang Terdaftar

claude mcp list

Hapus Server

claude mcp remove server-name

Mengatur Scope

Kamu bisa menentukan scope konfigurasi untuk MCP server:

# Project-local (default)
claude mcp add --scope project db-server -- command

# User-global
claude mcp add --scope user db-server -- command

Membuat MCP Server Kustom

Kamu juga bisa membuat tool khusus project sebagai MCP server kustom:

// my-mcp-server.ts
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: "my-project-tools",
  version: "1.0.0",
});

// Definisikan tool kustom
server.tool(
  "deploy-staging",
  "Deploy ke staging environment",
  { branch: z.string().describe("Nama branch yang akan di-deploy") },
  async ({ branch }) => {
    // Logic deployment
    return {
      content: [{ type: "text", text: `Deployed ${branch} to staging` }],
    };
  }
);

const transport = new StdioServerTransport();
await server.connect(transport);

Daftarkan seperti ini:

claude mcp add my-tools -- npx tsx my-mcp-server.ts

Pertimbangan Keamanan

1. Manajemen Credential

Token dan password di konfigurasi MCP server harus dikelola melalui environment variable atau file .env. Jangan pernah commit ke Git.

2. Batasi Scope Akses

Ikuti prinsip least privilege — misalnya, gunakan user database read-only untuk MCP server database-mu.

3. Gunakan Local Settings

Simpan konfigurasi yang berisi credential di .claude/settings.local.json dan tambahkan ke .gitignore.

Kesimpulan

MCP server memungkinkanmu memperluas kemampuan Claude Code ke seluruh ekosistem project. Dari query database hingga workflow GitHub hingga notifikasi Slack, kamu bisa menggunakan Claude Code sebagai hub sentral workflow development-mu. Mulai dengan MCP server resmi, lalu buat yang kustom sesuai kebutuhan.

#Claude Code #MCP #MCP server #integrations #extensions