MCP di Windows Opencode: Perbedaan antara revisi
(←Membuat halaman berisi '= Instalasi dan Konfigurasi MCP di Windows 11 (WSL2) = Dokumen ini menjelaskan langkah-langkah memasang dan mengonfigurasi '''Model Context Protocol (MCP) server''' untuk OpenCode pada mesin Windows 11 yang menjalankan '''WSL2 (Windows Subsystem for Linux)'''. Versi dokumen: 1.0 Tanggal: 19 November 2026 Kondisi terverifikasi: OpenCode v2.3.2, Context7 remote, status ''connected'' == Ringkasan == {| class="wikitable" style="width:100%" |- ! Item !! Nilai |- |...') |
Tidak ada ringkasan suntingan |
||
| (1 revisi perantara oleh pengguna yang sama tidak ditampilkan) | |||
| Baris 249: | Baris 249: | ||
query: "how to configure mcp servers" | query: "how to configure mcp servers" | ||
</pre> | </pre> | ||
== Pengujian dan Validasi (Testing) == | |||
Bagian ini berisi rangkaian pengujian untuk memastikan MCP berfungsi dengan benar — mulai dari pemeriksaan konfigurasi, konektivitas jaringan, hingga fungsionalitas tool melalui OpenCode. | |||
=== 6.1 Uji Konfigurasi (Static Check) === | |||
==== 6.1.1 Validasi file JSON ==== | |||
<pre> | |||
# Validasi sintaks JSON | |||
python3 -m json.tool /home/robie/.config/opencode/opencode.json > /dev/null && echo "JSON valid" | |||
</pre> | |||
Keluaran: <code>JSON valid</code> | |||
==== 6.1.2 Cek skema wajib ==== | |||
Skrip ini memverifikasi field <code>type</code> dan <code>url</code> ada pada setiap server: | |||
<pre> | |||
python3 <<'EOF' | |||
import json, sys | |||
with open("/home/robie/.config/opencode/opencode.json") as f: | |||
cfg = json.load(f) | |||
servers = cfg.get("mcp", {}).get("servers", {}) | |||
ok = True | |||
for name, srv in servers.items(): | |||
if srv.get("type") != "remote": | |||
print(f"[WARN] {name}: type bukan 'remote' (={srv.get('type')})") | |||
if not srv.get("url", "").startswith("https://"): | |||
print(f"[FAIL] {name}: url tidak valid atau bukan https") | |||
ok = False | |||
else: | |||
print(f"[OK] {name}: {srv['url']}") | |||
sys.exit(0 if ok else 1) | |||
EOF | |||
</pre> | |||
==== 6.1.3 Perbandingan config global vs project ==== | |||
<pre> | |||
echo "=== GLOBAL ==="; cat /home/robie/.config/opencode/opencode.json | python3 -m json.tool | |||
echo "=== PROJECT ==="; cat /mnt/c/Users/USER/.config/opencode/opencode.jsonc 2>/dev/null | python3 -m json.tool || echo "(tidak ada / kosong)" | |||
</pre> | |||
=== 6.2 Uji Konektivitas Jaringan (Network Reachability) === | |||
==== 6.2.1 DNS resolution ==== | |||
<pre> | |||
getent ahosts mcp.context7.com | |||
# atau | |||
dig +short mcp.context7.com | |||
</pre> | |||
==== 6.2.2 TCP handshake (port 443) ==== | |||
<pre> | |||
nc -zv mcp.context7.com 443 2>&1 | head -1 | |||
# atau | |||
timeout 5 bash -c "cat < /dev/null > /dev/tcp/mcp.context7.com/443" && echo "TCP OK" | |||
</pre> | |||
==== 6.2.3 TLS certificate & HTTP HEAD ==== | |||
<pre> | |||
curl -sI --max-time 10 https://mcp.context7.com/mcp | head -1 | |||
# diharapkan: HTTP/2 200 atau HTTP/1.1 200 | |||
</pre> | |||
==== 6.2.4 Full MCP initialize handshake ==== | |||
Ini replikasi permintaan yang OpenCode kirim saat startup: | |||
<pre> | |||
curl -s -X POST https://mcp.context7.com/mcp \ | |||
-H "Content-Type: application/json" \ | |||
-H "Accept: application/json, text/event-stream" \ | |||
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' \ | |||
| python3 -m json.tool | |||
</pre> | |||
Keluaran yang diharapkan mengandung: | |||
<pre> | |||
"result": { | |||
"protocolVersion": "2024-11-05", | |||
"capabilities": {...}, | |||
"serverInfo": {"name": "context7", "version": "..."} | |||
} | |||
</pre> | |||
==== 6.2.5 Uji tool listing (tools/list) ==== | |||
<pre> | |||
curl -s -X POST https://mcp.context7.com/mcp \ | |||
-H "Content-Type: application/json" \ | |||
-H "Accept: application/json, text/event-stream" \ | |||
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \ | |||
| python3 -m json.tool | |||
</pre> | |||
Diharapkan mengembalikan daftar tool seperti <code>resolve-library-id</code> dan <code>query-docs</code>. | |||
==== 6.2.6 Skrip pengujian gabungan (one-liner) ==== | |||
Simpan sebagai <code>test-context7.sh</code> dan jalankan: | |||
<pre> | |||
cat > /tmp/test-context7.sh <<'EOF' | |||
#!/usr/bin/env bash | |||
set -euo pipefail | |||
URL="https://mcp.context7.com/mcp" | |||
echo "1. DNS..."; getent ahosts mcp.context7.com | head -1 | |||
echo "2. TLS/HEAD..."; curl -sI --max-time 10 "$URL" | head -1 | |||
echo "3. Initialize..."; curl -s -X POST "$URL" -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | python3 -c "import sys,json; d=json.load(sys.stdin); print('OK' if d.get('result',{}).get('protocolVersion') else 'FAIL:', d.get('error'))" | |||
echo "4. Tools list..."; curl -s -X POST "$URL" -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | python3 -c "import sys,json; d=json.load(sys.stdin); tools=[t['name'] for t in d.get('result',{}).get('tools',[])]; print('Tools:', ', '.join(tools) if tools else 'KOSONG')" | |||
EOF | |||
chmod +x /tmp/test-context7.sh | |||
/tmp/test-context7.sh | |||
</pre> | |||
=== 6.3 Uji Fungsionalitas dari Dalam OpenCode (Runtime Test) === | |||
==== 6.3.1 Via CLI non-interaktif ==== | |||
OpenCode bisa dijalankan <code>--standalone</code> untuk sesi tanpa background service: | |||
<pre> | |||
# Tes resolve-library-id | |||
echo 'libraryName: "OpenCode"; query: "MCP server configuration"' | opencode --standalone run --agent main --input-format json 2>&1 | head -30 | |||
# Tes query-docs | |||
echo 'libraryId: "/anomalyco/opencode"; query: "how to configure mcp servers"' | opencode --standalone run --agent main --input-format json 2>&1 | head -30 | |||
</pre> | |||
<blockquote>Catatan: format <code>--input-format json</code> dan tool-calling spesifik tergantung versi OpenCode. Jika tidak didukung, gunakan metode TUI di bawah.</blockquote> | |||
==== 6.3.2 Via TUI (antarmuka interaktif) ==== | |||
Buka OpenCode: | |||
<pre> | |||
opencode | |||
</pre> | |||
Lalu di dalam TUI: | |||
<ol> | |||
<li>Tekan <code>Ctrl+P</code> → ketik <strong>MCP</strong> → pilih <strong>MCP Servers</strong> (atau jalankan <code>/mcps</code>) | |||
<ul> | |||
<li>Pastikan <code>context7</code> tampil <code>✓ connected</code></li> | |||
</ul> | |||
</li> | |||
<li>Gunakan tool langsung di prompt: | |||
<pre> | |||
> context7_resolve-library-id libraryName="OpenCode" query="MCP server configuration" | |||
</pre> | |||
</li> | |||
<li>Gunakan tool kedua: | |||
<pre> | |||
> context7_query-docs libraryId="/anomalyco/opencode" query="configure mcp servers" | |||
</pre> | |||
</li> | |||
<li>Periksa log server (debug): | |||
<pre> | |||
/log server | |||
</pre> | |||
Filter dengan <code>role=server</code> dan cari <code>context7</code>. | |||
</li> | |||
</ol> | |||
==== 6.3.3 Via API HTTP (untuk integrasi) ==== | |||
Jika OpenCode service berjalan: | |||
<pre> | |||
# Daftar server via API | |||
curl -s http://127.0.0.1:52817/api/mcp/servers | python3 -m json.tool | |||
# Info service | |||
curl -s http://127.0.0.1:52817/api/info | python3 -m json.tool | |||
</pre> | |||
<blockquote>Port default <code>52817</code>. Cek port aktual dengan <code>opencode service status</code>.</blockquote> | |||
=== 6.4 Uji Otomatis (CI/CD Style) ==== | |||
Buat file <code>test-mcp.yml</code> untuk GitHub Actions / GitLab CI: | |||
<syntaxhighlight lang="yaml"> | |||
name: Test MCP Context7 | |||
on: [push, pull_request] | |||
jobs: | |||
test-mcp: | |||
runs-on: ubuntu-latest | |||
steps: | |||
- uses: actions/checkout@v4 | |||
- name: Install OpenCode | |||
run: | | |||
curl -fsSL https://opencode.ai/install.sh | sh | |||
echo "$HOME/.opencode/bin" >> $GITHUB_PATH | |||
- name: Configure Context7 | |||
run: | | |||
opencode mcp add context7 --global --url https://mcp.context7.com/mcp | |||
- name: Wait for connection | |||
run: | | |||
for i in {1..10}; do | |||
if opencode mcp list | grep -q "context7.*connected"; then exit 0; fi | |||
sleep 3 | |||
done | |||
echo "Timeout waiting for MCP connection" && exit 1 | |||
- name: Test tool resolve-library-id | |||
run: | | |||
opencode run --agent main --print "context7_resolve-library-id libraryName='OpenCode' query='MCP config'" | |||
- name: Test tool query-docs | |||
run: | | |||
opencode run --agent main --print "context7_query-docs libraryId='/anomalyco/opencode' query='mcp servers'" | |||
</syntaxhighlight> | |||
=== 6.5 Checklist Pengujian Cepat (Quick Checklist) === | |||
Gunakan tabel ini sebagai daftar cek manual: | |||
{| class="wikitable" style="width:100%" | |||
|- | |||
! No !! Kategori !! Perintah / Aksi !! Diharapkan | |||
|- | |||
| 1 || Config || <code>opencode mcp list</code> || <code>✓ context7 connected</code> | |||
|- | |||
| 2 || Config || <code>cat ~/.config/opencode/opencode.json | python3 -m json.tool</code> || JSON valid, ada <code>type: remote</code>, <code>url: https://mcp.context7.com/mcp</code> | |||
|- | |||
| 3 || Network || <code>curl -sI --max-time 10 https://mcp.context7.com/mcp | head -1</code> || <code>HTTP/2 200</code> atau <code>HTTP/1.1 200</code> | |||
|- | |||
| 4 || Network || <code>curl -s -X POST .../initialize ... | python3 -c "import sys,json; d=json.load(sys.stdin); assert d.get('result',{}).get('protocolVersion')"</code> || Exit code 0 | |||
|- | |||
| 5 || Network || <code>curl -s -X POST .../tools/list ... | python3 -c "import sys,json; d=json.load(sys.stdin); print([t['name'] for t in d.get('result',{}).get('tools',[])])"</code> || Termasuk <code>resolve-library-id</code>, <code>query-docs</code> | |||
|- | |||
| 6 || Runtime || Di TUI: <code>/mcps</code> → pilih context7 || Status <code>connected</code> | |||
|- | |||
| 7 || Runtime || Di TUI: <code>context7_resolve-library-id libraryName="React" query="hooks"</code> || Mengembalikan library ID (mis. <code>/facebook/react</code>) | |||
|- | |||
| 8 || Runtime || Di TUI: <code>context7_query-docs libraryId="/facebook/react" query="useEffect cleanup"</code> || Mengembalikan dokumentasi + contoh kode | |||
|- | |||
| 9 || Service || <code>opencode service status</code> || <code>healthy</code> | |||
|- | |||
| 10 || Service || <code>curl -s http://127.0.0.1:52817/api/mcp/servers | python3 -m json.tool</code> || JSON berisi <code>context7</code> dengan <code>status: connected</code> | |||
|} | |||
=== 6.6 Penanganan Hasil Uji Gagal === | |||
{| class="wikitable" style="width:100%" | |||
|- | |||
! Gejala !! Kemungkinan Penyebab !! Tindakan | |||
|- | |||
| <code>opencode mcp list</code> → <code>pending</code> (lebih 30 detik) || Jaringan lambat / firewall || Cek <code>curl</code> Langkah 4.4; periksa proxy corporate | |||
|- | |||
| <code>curl initialize</code> → <code>HTTP 401/403</code> || Server butuh auth || Jalankan <code>/mcps</code> → sign in; atau set header API key jika disediakan | |||
|- | |||
| <code>tools/list</code> → array kosong || Versi protokol tidak cocok || Tambah <code>"protocol": "auto"</code> di config server | |||
|- | |||
| Tool di TUI → <code>tool not found</code> || MCP belum dimuat ulang || Jalankan <code>/reload</code> atau restart OpenCode | |||
|- | |||
| <code>opencode service status</code> → <code>unhealthy</code> || Service macet || <code>opencode service restart</code> | |||
|} | |||
== Konfigurasi Manual (Alternatif) == | == Konfigurasi Manual (Alternatif) == | ||
Revisi terkini sejak 19 November 2026 08.56
Instalasi dan Konfigurasi MCP di Windows 11 (WSL2)
Dokumen ini menjelaskan langkah-langkah memasang dan mengonfigurasi Model Context Protocol (MCP) server untuk OpenCode pada mesin Windows 11 yang menjalankan WSL2 (Windows Subsystem for Linux).
Versi dokumen: 1.0 Tanggal: 19 November 2026 Kondisi terverifikasi: OpenCode v2.3.2, Context7 remote, status connected
Ringkasan
| Item | Nilai |
|---|---|
| Sistem operasi | Ubuntu 26.04.1 LTS (Resolute Raccoon) |
| Platform | WSL2 — kernel 6.18.40.1-microsoft-standard-WSL2, x86_64
|
| User aktif | robie (uid 1000, grup sudo)
|
| OpenCode | v2.3.2 di ~/.opencode/bin/opencode
|
| MCP yang dipasang | Context7 (remote, global) |
| Status akhir | ✓ context7 connected
|
| Config global | /home/robie/.config/opencode/opencode.json
|
Prasyarat
Sebelum memulai, pastikan hal berikut terpenuhi:
- WSL2 terpasang di Windows 11 dan distribusi Linux sudah berjalan.
- Koneksi internet aktif — diperlukan untuk mengunduh paket dan terhubung ke server MCP remote.
- OpenCode terpasang dan bisa dijalankan dari terminal.
- Akun TIDAK memerlukan API key untuk Context7, sehingga langkah ini bisa dilewati.
Runtime yang tersedia
| Tool | Status | Keterangan |
|---|---|---|
| Python | ✅ 3.14.4 | Tersedia di /usr/bin/python3
|
| apt | ✅ 3.2.0 | Manajer paket Debian/Ubuntu |
| curl | ✅ 8.18.0 | Untuk unduhan dan pengecekan endpoint |
| git | ✅ 2.53.0 | Untuk instalasi dari sumber |
| Node.js / npm / npx | ❌ Tidak ada | Dibutuhkan untuk MCP lokal berbasis npx
|
| pip / ensurepip | ❌ Tidak ada | Modul pip tidak ikut terpasang |
| uv / uvx | ❌ Tidak ada | Dibutuhkan untuk MCP Python |
| Docker | ❌ Tidak ada | Dibutuhkan untuk MCP berbasis kontainer |
Konsekuensi penting
Karena Node.js, pip, uv, dan Docker tidak tersedia, setiap MCP server bertipe lokal yang perintahnya berupa
npx -y <paket>,uvx <paket>, ataudocker runtidak akan bisa dijalankan apa adanya.
Oleh karena itu, langkah utama pada dokumen ini memakai MCP remote (transport Streamable HTTP), yang tidak memerlukan runtime tambahan sama sekali.
Langkah 1: Cek Kondisi Sistem
Jalankan perintah berikut untuk memverifikasi kondisi mesin:
uname -a cat /etc/os-release node -v 2>/dev/null || echo "Node.js tidak ada" python3 --version opencode --version
Contoh keluaran yang diharapkan:
Linux DESKTOP-... 6.18.40.1-microsoft-standard-WSL2 #1 SMP ... x86_64 GNU/Linux PRETTY_NAME="Ubuntu 26.04.1 LTS" Node.js tidak ada Python 3.14.4 opencode v2.3.2
Langkah 2: Verifikasi Kondisi MCP Saat Ini
Cek apakah sudah ada MCP server yang terkonfigurasi:
opencode mcp list
Keluaran awal pada kondisi bersih:
No MCP servers configured
Pahami lokasi konfigurasi
OpenCode memisahkan dua jenis konfigurasi:
| Jenis | Lokasi | Dampak |
|---|---|---|
| Global | /home/robie/.config/opencode/opencode.json |
Berlaku untuk semua project |
| Project | opencode.json atau .opencode/opencode.json di direktori project |
Hanya berlaku untuk project tersebut |
Karena dokumen ini memilih instalasi global, perubahan akan ditulis ke file konfigurasi global.
Langkah 3: Pilih Jenis MCP Server
OpenCode mengenal dua tipe MCP server:
Tipe Remote (Streamable HTTP)
- URL absolut, misalnya
https://mcp.context7.com/mcp - Tidak butuh Node.js, Python, maupun Docker
- Mendukung OAuth secara default
- Dipilih untuk dokumen ini
Tipe Local (stdio)
- Berupa perintah yang dijalankan OpenCode, misalnya
["npx", "-y", "nama-paket"] - Butuh runtime terpasang (Node.js atau uv)
- Mendukung
cwd,environment, dantimeoutkhusus
Langkah 4: Instalasi MCP Context7 (Remote, Global)
4.1 Jalankan perintah tambah
opencode mcp add context7 --global --url https://mcp.context7.com/mcp
Penjelasan flag:
| Flag | Fungsi |
|---|---|
--global |
Menulis ke konfigurasi global sehingga tersedia di semua project |
--url |
Menentukan endpoint Streamable HTTP untuk server remote |
Keluaran yang diharapkan:
MCP server "context7" added to /home/robie/.config/opencode/opencode.json
4.2 Periksa isi konfigurasi
cat /home/robie/.config/opencode/opencode.json
Isi file setelah instalasi:
<syntaxhighlight lang="json"> {
"mcp": {
"servers": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp"
}
}
}
} </syntaxhighlight>
4.3 Verifikasi koneksi
opencode mcp list
Status akan bergerak sebagai berikut:
○ context7 pending
Tunggu beberapa detik lalu jalankan ulang:
sleep 8 opencode mcp list
Keluaran akhir yang diharapkan:
✓ context7 connected
4.4 Uji endpoint secara manual (opsional)
curl -s -o /dev/null -w "context7 mcp endpoint: %{http_code}\n" \
--max-time 15 \
-X POST https://mcp.context7.com/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}'
Keluaran yang diharapkan: context7 mcp endpoint: 200
Langkah 5: Verifikasi dari Dalam OpenCode
Setelah server terhubung, dua tool berikut tersedia:
| Tool | Fungsi |
|---|---|
context7_resolve-library-id |
Mencari ID library dari nama paket atau produk |
context7_query-docs |
Mengambil dokumentasi dan contoh kode terbaru dari library |
Contoh pemakaian
Untuk mencari ID library OpenCode:
libraryName: "OpenCode" query: "MCP server configuration"
Keluaran yang diharapkan mencakup baris seperti:
- Title: OpenCode - Context7-compatible library ID: /anomalyco/opencode - Code Snippets: 12272
Setelah itu, gunakan ID tersebut untuk mengambil dokumentasi:
libraryId: "/anomalyco/opencode" query: "how to configure mcp servers"
Pengujian dan Validasi (Testing)
Bagian ini berisi rangkaian pengujian untuk memastikan MCP berfungsi dengan benar — mulai dari pemeriksaan konfigurasi, konektivitas jaringan, hingga fungsionalitas tool melalui OpenCode.
6.1 Uji Konfigurasi (Static Check)
6.1.1 Validasi file JSON
# Validasi sintaks JSON python3 -m json.tool /home/robie/.config/opencode/opencode.json > /dev/null && echo "JSON valid"
Keluaran: JSON valid
6.1.2 Cek skema wajib
Skrip ini memverifikasi field type dan url ada pada setiap server:
python3 <<'EOF'
import json, sys
with open("/home/robie/.config/opencode/opencode.json") as f:
cfg = json.load(f)
servers = cfg.get("mcp", {}).get("servers", {})
ok = True
for name, srv in servers.items():
if srv.get("type") != "remote":
print(f"[WARN] {name}: type bukan 'remote' (={srv.get('type')})")
if not srv.get("url", "").startswith("https://"):
print(f"[FAIL] {name}: url tidak valid atau bukan https")
ok = False
else:
print(f"[OK] {name}: {srv['url']}")
sys.exit(0 if ok else 1)
EOF
6.1.3 Perbandingan config global vs project
echo "=== GLOBAL ==="; cat /home/robie/.config/opencode/opencode.json | python3 -m json.tool echo "=== PROJECT ==="; cat /mnt/c/Users/USER/.config/opencode/opencode.jsonc 2>/dev/null | python3 -m json.tool || echo "(tidak ada / kosong)"
6.2 Uji Konektivitas Jaringan (Network Reachability)
6.2.1 DNS resolution
getent ahosts mcp.context7.com # atau dig +short mcp.context7.com
6.2.2 TCP handshake (port 443)
nc -zv mcp.context7.com 443 2>&1 | head -1 # atau timeout 5 bash -c "cat < /dev/null > /dev/tcp/mcp.context7.com/443" && echo "TCP OK"
6.2.3 TLS certificate & HTTP HEAD
curl -sI --max-time 10 https://mcp.context7.com/mcp | head -1 # diharapkan: HTTP/2 200 atau HTTP/1.1 200
6.2.4 Full MCP initialize handshake
Ini replikasi permintaan yang OpenCode kirim saat startup:
curl -s -X POST https://mcp.context7.com/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' \
| python3 -m json.tool
Keluaran yang diharapkan mengandung:
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {...},
"serverInfo": {"name": "context7", "version": "..."}
}
6.2.5 Uji tool listing (tools/list)
curl -s -X POST https://mcp.context7.com/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' \
| python3 -m json.tool
Diharapkan mengembalikan daftar tool seperti resolve-library-id dan query-docs.
6.2.6 Skrip pengujian gabungan (one-liner)
Simpan sebagai test-context7.sh dan jalankan:
cat > /tmp/test-context7.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
URL="https://mcp.context7.com/mcp"
echo "1. DNS..."; getent ahosts mcp.context7.com | head -1
echo "2. TLS/HEAD..."; curl -sI --max-time 10 "$URL" | head -1
echo "3. Initialize..."; curl -s -X POST "$URL" -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | python3 -c "import sys,json; d=json.load(sys.stdin); print('OK' if d.get('result',{}).get('protocolVersion') else 'FAIL:', d.get('error'))"
echo "4. Tools list..."; curl -s -X POST "$URL" -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | python3 -c "import sys,json; d=json.load(sys.stdin); tools=[t['name'] for t in d.get('result',{}).get('tools',[])]; print('Tools:', ', '.join(tools) if tools else 'KOSONG')"
EOF
chmod +x /tmp/test-context7.sh
/tmp/test-context7.sh
6.3 Uji Fungsionalitas dari Dalam OpenCode (Runtime Test)
6.3.1 Via CLI non-interaktif
OpenCode bisa dijalankan --standalone untuk sesi tanpa background service:
# Tes resolve-library-id echo 'libraryName: "OpenCode"; query: "MCP server configuration"' | opencode --standalone run --agent main --input-format json 2>&1 | head -30 # Tes query-docs echo 'libraryId: "/anomalyco/opencode"; query: "how to configure mcp servers"' | opencode --standalone run --agent main --input-format json 2>&1 | head -30
Catatan: format
--input-format jsondan tool-calling spesifik tergantung versi OpenCode. Jika tidak didukung, gunakan metode TUI di bawah.
6.3.2 Via TUI (antarmuka interaktif)
Buka OpenCode:
opencode
Lalu di dalam TUI:
- Tekan
Ctrl+P→ ketik MCP → pilih MCP Servers (atau jalankan/mcps)- Pastikan
context7tampil✓ connected
- Pastikan
- Gunakan tool langsung di prompt:
> context7_resolve-library-id libraryName="OpenCode" query="MCP server configuration"
- Gunakan tool kedua:
> context7_query-docs libraryId="/anomalyco/opencode" query="configure mcp servers"
- Periksa log server (debug):
/log server
Filter dengan
role=serverdan caricontext7.
6.3.3 Via API HTTP (untuk integrasi)
Jika OpenCode service berjalan:
# Daftar server via API curl -s http://127.0.0.1:52817/api/mcp/servers | python3 -m json.tool # Info service curl -s http://127.0.0.1:52817/api/info | python3 -m json.tool
Port default
52817. Cek port aktual denganopencode service status.
6.4 Uji Otomatis (CI/CD Style) =
Buat file test-mcp.yml untuk GitHub Actions / GitLab CI:
<syntaxhighlight lang="yaml"> name: Test MCP Context7 on: [push, pull_request] jobs:
test-mcp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install OpenCode
run: |
curl -fsSL https://opencode.ai/install.sh | sh
echo "$HOME/.opencode/bin" >> $GITHUB_PATH
- name: Configure Context7
run: |
opencode mcp add context7 --global --url https://mcp.context7.com/mcp
- name: Wait for connection
run: |
for i in {1..10}; do
if opencode mcp list | grep -q "context7.*connected"; then exit 0; fi
sleep 3
done
echo "Timeout waiting for MCP connection" && exit 1
- name: Test tool resolve-library-id
run: |
opencode run --agent main --print "context7_resolve-library-id libraryName='OpenCode' query='MCP config'"
- name: Test tool query-docs
run: |
opencode run --agent main --print "context7_query-docs libraryId='/anomalyco/opencode' query='mcp servers'"
</syntaxhighlight>
6.5 Checklist Pengujian Cepat (Quick Checklist)
Gunakan tabel ini sebagai daftar cek manual:
| No | Kategori | Perintah / Aksi | Diharapkan |
|---|---|---|---|
| 1 | Config | opencode mcp list |
✓ context7 connected
|
| 2 | Config | python3 -m json.tool | JSON valid, ada type: remote, url: https://mcp.context7.com/mcp
|
| 3 | Network | head -1 | HTTP/2 200 atau HTTP/1.1 200
|
| 4 | Network | python3 -c "import sys,json; d=json.load(sys.stdin); assert d.get('result',{}).get('protocolVersion')" | Exit code 0 |
| 5 | Network | python3 -c "import sys,json; d=json.load(sys.stdin); print([t['name'] for t in d.get('result',{}).get('tools',[])])" | Termasuk resolve-library-id, query-docs
|
| 6 | Runtime | Di TUI: /mcps → pilih context7 |
Status connected
|
| 7 | Runtime | Di TUI: context7_resolve-library-id libraryName="React" query="hooks" |
Mengembalikan library ID (mis. /facebook/react)
|
| 8 | Runtime | Di TUI: context7_query-docs libraryId="/facebook/react" query="useEffect cleanup" |
Mengembalikan dokumentasi + contoh kode |
| 9 | Service | opencode service status |
healthy
|
| 10 | Service | python3 -m json.tool | JSON berisi context7 dengan status: connected
|
6.6 Penanganan Hasil Uji Gagal
| Gejala | Kemungkinan Penyebab | Tindakan |
|---|---|---|
opencode mcp list → pending (lebih 30 detik) |
Jaringan lambat / firewall | Cek curl Langkah 4.4; periksa proxy corporate
|
curl initialize → HTTP 401/403 |
Server butuh auth | Jalankan /mcps → sign in; atau set header API key jika disediakan
|
tools/list → array kosong |
Versi protokol tidak cocok | Tambah "protocol": "auto" di config server
|
Tool di TUI → tool not found |
MCP belum dimuat ulang | Jalankan /reload atau restart OpenCode
|
opencode service status → unhealthy |
Service macet | opencode service restart
|
Konfigurasi Manual (Alternatif)
Jika ingin menulis konfigurasi tanpa memakai CLI, edit langsung file opencode.json:
<syntaxhighlight lang="jsonc"> {
"$schema": "https://opencode.ai/config.json", "mcp": { "servers": { "context7": { "type": "remote", "url": "https://mcp.context7.com/mcp" } } }
} </syntaxhighlight>
Field tipe remote
| Field | Wajib | Keterangan |
|---|---|---|
type |
Ya | Harus "remote"
|
url |
Ya | Endpoint Streamable HTTP absolut |
headers |
Tidak | Header HTTP tambahan, mendukung substitusi {env:NAMA}
|
oauth |
Tidak | Objek OAuth, atau false untuk menonaktifkan
|
disabled |
Tidak | true agar terkonfigurasi tetapi tidak disambungkan
|
codemode |
Tidak | false untuk menampilkan tool langsung. Default true
|
timeout |
Tidak | Override timeout per server |
protocol |
Tidak | legacy (default), auto, atau 2026-07-28
|
pool |
Tidak | true untuk berbagi satu koneksi antar direktori
|
Menambah server remote kedua
opencode mcp add context7 --global --url https://mcp.context7.com/mcp --header 'CONTEXT7_API_KEY={env:CONTEXT7_API_KEY}'
Catatan: quote nilai
{env:NAMA}agar shell menuliskannya secara literal.
Penonaktifan dan Penghapusan
Menonaktifkan sementara
Tambahkan "disabled": true pada objek server:
<syntaxhighlight lang="jsonc"> {
"mcp": {
"servers": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp",
"disabled": true
}
}
}
} </syntaxhighlight>
Menghapus server
Pada OpenCode v2.3.2 tidak ada subcommand
opencode mcp remove. Penghapusan dilakukan dengan mengedit file konfigurasi secara manual.
Buka /home/robie/.config/opencode/opencode.json lalu kosongkan daftar server:
<syntaxhighlight lang="json"> {
"mcp": {
"servers": {}
}
} </syntaxhighlight>
Setelah penyimpanan, jalankan verifikasi:
opencode mcp list
Keluaran: No MCP servers configured
Pemulihan Konfigurasi
Jika konfigurasi rusak atau kosong, kembalikan ke kondisi terverifikasi:
cat > /home/robie/.config/opencode/opencode.json <<'EOF'
{
"mcp": {
"servers": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp"
}
}
}
}
EOF
opencode mcp list
Troubleshooting
Status terus pending
- Tunggu 5–10 detik, lalu jalankan ulang
opencode mcp list. - Cek endpoint dengan
curlseperti pada Langkah 4.4. Kode200berarti server jaringan sehat. - Pastikan tidak ada proxy atau firewall yang memblokir
mcp.context7.com.
Status failed: getaddrinfo ENOTFOUND ...
- Artinya URL salah atau DNS tidak bisa menyelesaikan nama host.
- Periksa ejaan URL pada file konfigurasi.
Status needs authentication
- Jalankan
/mcpsdi dalam OpenCode, pilih server, lalu selesaikan proses sign-in di browser. - Alternatif:
opencode mcp auth context7
Penting: jangan menjalankan
opencode mcp authmelalui tool shell dalam mode background — tautan otorisasi bisa tersembunyi dalam keluaran proses. Gunakan antarmuka/mcpsdi dalam OpenCode.
MCP lokal gagal dengan command not found: npx
- Penyebab: Node.js belum terpasang.
- Solusi sementara: pakai tipe remote, atau instal Node.js terlebih dahulu (lihat bagian berikutnya).
Perubahan config tidak terdeteksi
- Config di-watch otomatis, tidak perlu restart.
- Untuk memaksa muat ulang penuh, jalankan
/reloaddi dalam OpenCode. - Untuk memeriksa kesehatan service:
opencode service status
Instalasi MCP Lokal (Opsional)
Bagian ini diperlukan hanya jika ingin memakai MCP server bertipe lokal.
Opsi A: Node.js tanpa sudo
Node.js bisa dipasang ke direktori user tanpa hak admin:
mkdir -p ~/.local/node curl -fsSL https://nodejs.org/dist/v22.22.1/node-v22.22.1-linux-x64.tar.xz \ -o /tmp/node.tar.xz tar -xJf /tmp/node.tar.xz -C ~/.local/node --strip-components=1
Tambahkan ke PATH di ~/.bashrc:
export PATH="$HOME/.local/node/bin:$PATH"
Muat ulang dan verifikasi:
source ~/.bashrc node -v npm -v npx -v
Versi di atas adalah kandidat dari repositori apt Ubuntu 26.04 (22.22.1). Selalu cek versi terbaru di
https://nodejs.org/dist/index.jsonsebelum mengunduh.
Opsi B: Node.js via apt (butuh password sudo)
sudo apt update sudo apt install -y nodejs npm
Opsi C: uv (untuk MCP Python)
curl -LsSf https://astral.sh/uv/install.sh | sh source ~/.bashrc uv --version uvx --version
Opsi D: Docker
Docker memerlukan hak admin dan konfigurasi daemon, sehingga tidak direkomendasikan di WSL2 tanpa kebutuhan khusus.
Setelah runtime terpasang
Tambahkan MCP lokal dengan pola berikut:
opencode mcp add nama-server --global -- npx -y nama-paket
Dengan environment variable:
opencode mcp add nama-server --global --env LOG_LEVEL=info -- npx -y nama-paket
Referensi
- Dokumen resmi MCP servers OpenCode
- Panduan konfigurasi OpenCode
- Skema konfigurasi
- Situs resmi Model Context Protocol
- Context7
Riwayat Perubahan
| Versi | Tanggal | Perubahan |
|---|---|---|
| 1.0 | 19 November 2026 | Dokumen awal — instalasi Context7 remote global pada WSL2 Ubuntu 26.04.1 |