π§ Context7 MCP & Custom Server Development β Deep Dive
Ringkasan satu-paragraf menjelaskan bahwa Context7 MCP adalah server Model Context Protocol (MCP) dari tim Upstash yang menyediakan dokumentasi kode up-to-date dan version-specific untuk LLM dan AI code editor. Panduan ini membahas cara membangun MCP server kustom untuk Digital Garden (Obsidian) dan mengadaptasi pola komponen seperti React Bits ke framework lain (Svelte) dengan memanfaatkan arsitektur MCP sebagai jembatan kontekstual antar ekosistem.
Hubungan ke Vault
Nota ini terkait dengan threat-modeling-deepdive untuk prinsip keamanan dalam arsitektur sistem, comprehensive-threat-directory untuk ancaman pada integrasi AI-agent, serta devops dan system-design untuk pipeline CI/CD dan arsitektur serverless.
Daftar Isi
Foundation
Apa Itu Context7 MCP?
Context7 adalah MCP server open-source yang dikembangkan oleh tim Upstash untuk mengatasi masalah fundamental LLM: training data cutoff dan hallucination pada API library yang sering berubah. Alih-alih mengandalkan pengetahuan statis model, Context7 menarik dokumentasi dan contoh kode real-time langsung dari repositori sumber, membersihkannya, dan menyuntikkannya ke context window LLM pada saat prompting.
Masalah yang dipecahkan:
| Tanpa Context7 | Dengan Context7 |
|---|---|
| Contoh kode outdated berdasarkan data latih tahunan | Dokumentasi version-specific dan up-to-date |
| API yang dihalusinasi (tidak ada di library) | Snippet kode nyata dari sumber resmi |
| Jawaban generik untuk versi lama | Informasi ringkas tanpa filler |
| Copy-paste manual page-by-page | Integrasi otomatis via MCP atau CLI |
Context7 beroperasi dalam dua mode: CLI + Skills (ctx7 commands) dan MCP (native tool invocation). Server MCP-nya tersedia sebagai npm package @upstash/context7-mcp dengan endpoint https://mcp.context7.com/mcp.
Apa Itu Model Context Protocol (MCP)?
MCP adalah standar open-source dari Anthropic (rilis November 2024) yang menstandardisasi koneksi antara aplikasi AI (host) dengan sistem eksternal (server). Analoginya seperti USB-C untuk AI: satu protokol universal untuk data, tools, dan workflows.
Arsitektur dasar:
βββββββββββββββ JSON-RPC 2.0 βββββββββββββββ
β MCP Host β ββββββββββββββββββββΊ β MCP Server β
β (Claude, β stdio / Streamable β (Tools, β
β Cursor, β HTTP β Resources, β
β VS Code) β β Prompts) β
βββββββββββββββ βββββββββββββββ
Tiga primitif utama yang diekspos server:
| Primitif | Kontrol | Fungsi | Analogi REST |
|---|---|---|---|
| Tools | Model (LLM) | Eksekusi aksi: query DB, call API, komputasi | POST/PUT/DELETE |
| Resources | Aplikasi | Data read-only: file, record, config | GET |
| Prompts | User | Template reusable untuk interaksi optimal | Template engine |
Digital Garden & Knowledge Base
Digital Garden adalah metode manajemen pengetahuan pribadi di mana catatan (notes) ditanam, dirawat, dan ditumbuhkan seiring waktuβberbeda dengan blog yang bersifat βpublish once, doneβ. Obsidian adalah platform paling populer untuk pendekatan ini, dengan fitur backlink, graph view, dan local-first Markdown storage.
Integrasi MCP dengan Digital Garden memungkinkan AI agent untuk:
- Membaca dan mencari vault secara semantik
- Membuat serta memperbarui catatan
- Menavigasi knowledge graph via wiki-links
- Mensintesis ide dari beberapa catatan terhubung
React Bits & Ekosistem Component Porting
React Bits adalah koleksi 130+ komponen React animasi yang berkembang pesat (37K+ stars, #2 JS Rising Stars 2025). Filosofinya: copy-paste ready, minimal dependencies, dan tidak memaksakan Framer Motionβmenggunakan CSS animations untuk sebagian besar komponen. Setiap komponen tersedia dalam 4 varian: JS-CSS, JS-Tailwind, TS-CSS, TS-Tailwind.
Porting ke Svelte:
React Bits memiliki port oficial ke Svelte bernama Svelte Bits (sveltebits.xyz). Porting ini mempertahankan perilaku animasi, shader, dan konfigurasi spring asli, namun mengadaptasi ke pola reaktivitas Svelte (derived, $effect) dan menghilangkan runtime React.
| Aspek | React Bits | Svelte Bits |
|---|---|---|
| Framework | React 19 | Svelte 5 |
| Reactivitas | Hooks (useState, useEffect) | Runes (effect) |
| Bundle | ~42β45 KB (React runtime) | ~2β5 KB (Svelte compiled) |
| RSC Compatible | Partial (CSS components) | Native (compile-time) |
| Install | npx shadcn add @react-bits/... | npx jsrepo add https://sveltebits.xyz/r/... |
| Dependencies | Optional GSAP/Three.js | Same optional deps |
Technical Deep-Dive
Langkah-Langkah Membangun MCP Server Kustom
Berikut adalah alur kerja lengkap untuk membangun MCP server untuk Digital Garden (Obsidian vault) dan cross-library documentation, mengikuti pola Context7:
1. Menyiapkan Project Scaffold (TypeScript)
mkdir garden-mcp && cd garden-mcp
npm init -y
npm install @modelcontextprotocol/sdk zod
npm install -D typescript @types/node tsx @modelcontextprotocol/inspector
npx tsc --initKonfigurasi package.json (ESM-only, bin executable):
{
"name": "@your-scope/garden-mcp",
"version": "0.1.0",
"type": "module",
"bin": { "garden-mcp": "./dist/index.js" },
"scripts": {
"build": "tsc",
"dev": "tsx watch src/index.ts",
"inspector": "npx @modelcontextprotocol/inspector tsx src/index.ts"
}
}Peringatan scaffold: Jangan lewatkan
"type": "module". MCP SDK adalah ESM-only; CommonJS akan gagal dengan errorrequire() of ES module.
2. Membuat Server Skeleton
#!/usr/bin/env node
// src/index.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
const server = new McpServer({
name: "garden-mcp",
version: "0.1.0",
})
async function main() {
const transport = new StdioServerTransport()
await server.connect(transport)
// stdout adalah channel protokol β jangan tulis apa pun ke sana
console.error("[garden-mcp] ready on stdio")
}
main().catch((err) => {
console.error("Fatal:", err)
process.exit(1)
})Aturan emas stdio: Jangan pernah menulis ke stdout kecuali framed JSON-RPC. Gunakan stderr untuk logging.
3. Mendaftarkan Tools untuk Digital Garden
Pola Tool 1: Semantic Vault Search
import { z } from "zod"
server.tool(
"search_vault",
"Search the Obsidian vault semantically using BM25 or vector embeddings. " +
"Use this when the user asks about concepts, topics, or specific content " +
"across their knowledge base.",
{
query: z.string().min(2).describe("Search query in natural language"),
limit: z.number().optional().default(10).describe("Max results to return"),
path_filter: z.string().optional().describe("Optional folder path to narrow search"),
},
async ({ query, limit, path_filter }) => {
// Implementasi: gunakan Obsidian CLI, Local REST API, atau file-system BM25
const results = await searchVault(query, { limit, path_filter })
return {
content: [
{
type: "text",
text: formatSearchResults(results),
},
],
}
},
)Pola Tool 2: Read Note dengan Frontmatter Parsing
server.tool(
"read_note",
"Read a specific note from the vault, parsing YAML frontmatter, content, " +
"and wikilinks. Use this when the user references a specific note title or path.",
{
path: z.string().describe("Relative path to note, e.g. 'Projects/AI-Research.md'"),
include_backlinks: z.boolean().optional().default(false),
},
async ({ path, include_backlinks }) => {
const note = await readNote(path)
const backlinks = include_backlinks ? await getBacklinks(path) : []
return {
content: [
{
type: "text",
text: JSON.stringify({ ...note, backlinks }, null, 2),
},
],
}
},
)Pola Tool 3: Write / Append Note
server.tool(
"write_note",
"Create or append content to a note. Use for capturing insights, " +
"synthesizing research, or updating project documentation.",
{
path: z.string().describe("Target note path"),
content: z.string().describe("Markdown content to write"),
mode: z.enum(["create", "append", "prepend"]).default("append"),
frontmatter: z.record(z.any()).optional().describe("YAML frontmatter object"),
},
async ({ path, content, mode, frontmatter }) => {
const result = await writeNote(path, content, { mode, frontmatter })
return {
content: [{ type: "text", text: `Note ${mode}ed: ${result.path}` }],
}
},
)4. Menambahkan Resources (Read-Only Data)
Resources berguna untuk menyediakan konteks statis yang sering diakses:
server.resource("vault-stats", "garden://stats", async (uri) => {
const stats = await getVaultStats()
return {
contents: [
{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify(stats, null, 2),
},
],
}
})
server.resource("tag-index", "garden://tags/{tag}", async (uri) => {
const tag = uri.pathname.replace("//", "")
const notes = await getNotesByTag(tag)
return {
contents: [
{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify(notes, null, 2),
},
],
}
})5. Menambahkan Prompts (Reusable Templates)
server.prompt(
"synthesize_research",
"Generate a synthesis note from multiple source notes. " +
"Use when the user wants to connect ideas across their knowledge graph.",
{
topic: z.string().describe("Synthesis topic or question"),
source_paths: z.array(z.string()).describe("List of note paths to synthesize"),
},
async ({ topic, source_paths }) => {
const sources = await Promise.all(source_paths.map(readNote))
return {
messages: [
{
role: "user",
content: {
type: "text",
text: `Synthesize the following notes on "${topic}":\n\n${sources
.map((s) => `--- ${s.path} ---\n${s.content}`)
.join("\n\n")}\n\nCreate a new note that connects these ideas with backlinks.`,
},
},
],
}
},
)6. Wire ke Claude Desktop / Cursor / VS Code
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"digital-garden": {
"command": "npx",
"args": ["-y", "@your-scope/garden-mcp"],
"env": {
"VAULT_PATH": "/Users/you/Obsidian/Vault",
"OBSIDIAN_API_KEY": "your-rest-api-key"
}
}
}
}Cursor (~/.cursor/mcp.json):
{
"mcpServers": {
"digital-garden": {
"command": "npx",
"args": ["-y", "@your-scope/garden-mcp"],
"env": { "VAULT_PATH": "/Users/you/Obsidian/Vault" }
}
}
}Contoh Artefak: Component Registry MCP untuk React Bits β Svelte
Berikut adalah konsep MCP server yang memetakan komponen React Bits ke Svelte Bits, memungkinkan AI agent untuk βmentranspilasiβ komponen antar framework:
Component Mapping Register
| Component ID | React Bits Path | Svelte Bits Path | Dependencies | Complexity |
|---|---|---|---|---|
blur-text | text-animations/BlurText | text-animations/BlurText | None (CSS) | Low |
aurora-bg | backgrounds/Aurora | backgrounds/Aurora | None (CSS) | Low |
particles | backgrounds/Particles | backgrounds/Particles | matter-js | Medium |
grid-distortion | backgrounds/GridDistortion | backgrounds/GridDistortion | three | High |
magnetic-button | components/MagneticButton | components/MagneticButton | None (CSS) | Low |
tilt-card | components/TiltCard | components/TiltCard | vanilla-tilt | Low |
Tool: port_component
server.tool(
"port_component",
"Port a React Bits component to Svelte. Returns the Svelte equivalent " +
"with reactivity patterns adapted (useState β $state, useEffect β $effect). " +
"Use when the user wants to use a React Bits component in a Svelte project.",
{
component_id: z.string().describe("Component ID from the registry, e.g. 'blur-text'"),
variant: z.enum(["css", "tailwind"]).default("tailwind"),
typescript: z.boolean().default(true),
},
async ({ component_id, variant, typescript }) => {
const mapping = await getComponentMapping(component_id)
const svelteCode = await fetchSvelteVariant(mapping.sveltePath, variant, typescript)
const reactCode = await fetchReactVariant(mapping.reactPath, variant, typescript)
return {
content: [
{
type: "text",
text:
`# ${mapping.name} β Svelte Port\n\n` +
`## Install\n\`\`\`bash\n` +
`npx jsrepo add https://sveltebits.xyz/r/${component_id}.json\n` +
`\`\`\`\n\n` +
`## Svelte Code (${variant}, ${typescript ? "TS" : "JS"})\n\`\`\`svelte\n${svelteCode}\n\`\`\`\n\n` +
`## React Original (for reference)\n\`\`\`tsx\n${reactCode}\n\`\`\`\n\n` +
`## Key Differences\n` +
`- React: \`useState\`, \`useEffect\` β Svelte: \`$state\`, \`$effect\`\n` +
`- React: Props via destructuring β Svelte: \`$props()\`\n` +
`- React: \`children\` β Svelte: \`{@render children()}\`\n` +
`- Bundle: ~${mapping.bundleDiff}KB smaller in Svelte\n`,
},
],
}
},
)Advanced
Toolchain dan Otomatisasi
| Alat | Fungsi | Integrasi | Catatan |
|---|---|---|---|
| mcp-inspector | Debug server, test tools, inspect JSON-RPC | npm run inspector | UI browser untuk iterasi cepat |
| ctx7 CLI | Setup Context7 tanpa MCP | npx ctx7 setup | OAuth + auto-config untuk Cursor/Claude |
| PyTM | Threat modeling as code | Python/CLI | Untuk security review MCP server |
| llms.txt | Routing layer untuk agentic web | Root domain | B2A infrastructure, diakses Cursor/Claude Code |
| jsrepo | Install Svelte Bits components | jsrepo add <url> | Direct HTTPS registry, no npm package |
Mengintegrasikan MCP ke dalam Workflow Digital Garden
Shift-Left Knowledge Capture:
Gunakan MCP server untuk menangkap konteks sebelum insight hilang:
- Hot Storage (Session Log): Setiap sesi Claude dengan MCP server menulis ke
Daily Notes/YYYY-MM-DD.md - Warm Storage (Synthesis): Akhir hari, agent merangkum session log menjadi decision records
- Cold Storage (Archive): Catatan lama dipindahkan ke
Archive/dengan backlink preserved
Deduplication Loop:
server.tool(
"capture_insight",
"Capture an insight to the vault with deduplication check. " +
"Searches existing notes before writing to prevent redundant entries.",
{
insight: z.string(),
topic: z.string(),
source_url: z.string().optional(),
},
async ({ insight, topic, source_url }) => {
const existing = await semanticSearch(`${topic} ${insight}`, { limit: 5 })
const similarity = await checkSimilarity(insight, existing)
if (similarity.max > 0.85) {
return {
content: [
{
type: "text",
text: `Similar note exists: ${similarity.bestMatch.path}. Appending instead.`,
},
],
isError: false,
}
}
const path = `Inbox/${slugify(topic)}-${Date.now()}.md`
await writeNote(
path,
`## ${topic}\n\n${insight}\n\n${source_url ? `Source: ${source_url}` : ""}`,
)
return { content: [{ type: "text", text: `Captured to ${path}` }] }
},
)Security & Sandboxing MCP Server
Berdasarkan OWASP MCP Security Cheat Sheet:
| Layer | Kontrol | Implementasi |
|---|---|---|
| Auth | OAuth 2.0 + PKCE untuk remote | MCP_AUTH_MODE=oauth |
| Sandboxing | Container/chroot untuk local | Docker, fs access scoped |
| Input Validation | JSON Schema strict, additionalProperties: false | Zod schema dengan .strict() |
| Path Policy | Prefix-based read/write gates | OBSIDIAN_READ_PATHS, OBSIDIAN_WRITE_PATHS |
| Output Sanitization | Strip instruction-like patterns | Regex filter pada text content |
| Tool Poisoning Guard | Hash schema definitions | Re-validate sebelum tools/call |
Case Studies
| Studi Kasus | Konteks | Metodologi | Temuan Kunci | Mitigasi yang Diimplementasi |
|---|---|---|---|---|
| Obsidian + Claude Desktop (2026) | Vault pribadi 5,000+ notes, MCP server via mcpvault | MCP (stdio) + BM25 search | 1. File-based access tanpa plugin dependency 2. Frontmatter corruption pada server lain 3. 70,000x token efficiency vs naive file reads | 1. Gunakan @bitbonsai/mcpvault (zero deps) 2. AST-aware YAML preservation 3. Scoped path permissions |
| React Bits β SvelteKit Landing Page (2026) | Porting 12 komponen animasi ke Svelte untuk performa | Component-by-component port + jsrepo registry | 1. Bundle berkurang ~38KB (React runtime dihapus) 2. RSC-compatible tanpa "use client" 3. Three.js peer deps tetap sama | 1. Gunakan Svelte Bits official port 2. $state untuk reactive props 3. {@render} untuk slot equivalent |
| Context7 + Custom Docs (2025) | Internal design system docs, tidak publik di Context7 | PASTA + llms.txt generation | 1. Private docs tidak terindex Context7 2. Butuh versioning untuk setiap release 3. Token bloat pada HTML docs | 1. Generate llms.txt internal via CI 2. Tag-based versioning di registry 3. Markdown-first docs dengan llms-full.txt companion |
| Project Synapse (2026) | Neo4j + Obsidian wiki untuk research compounding | TRIKE + Graph RAG | 1. Akses graph relationship lebih powerful dari flat search 2. Vector embeddings per node 3. Multi-hop traversal untuk hidden connections | 1. Neo4j 2026.x untuk graph storage 2. FAISS untuk vector index 3. wiki_fetch_url dengan defuddle untuk web clipping |
Koneksi ke Vault
- threat-modeling-deepdive β Prinsip STRIDE/PASTA untuk mengamankan surface area MCP server (spoofing, tampering, repudiation, information disclosure).
- comprehensive-threat-directory β Taksonomi ancaman spesifik untuk AI agent integrations (prompt injection, tool poisoning, context window attacks).
- network-security β Lapisan deteksi untuk MCP traffic anomaly (unusual tool invocation patterns, data exfiltration via resources).
- endpoint-security β Sandboxing dan isolation untuk MCP server processes (EDR, container escape detection).
- system-design β Arsitektur zero-trust untuk MCP: never trust, always verify antara host-client-server.
- devops β Integrasi MCP server ke CI/CD: automated testing dengan mcp-inspector, schema versioning, dan llms.txt generation pipeline.
- zero-trust-security β Konsep least-privilege untuk tool permissions: read-only default, scoped write paths, audit logging.
Referensi
- Upstash. Context7 Platform β Up-to-date Code Docs For Any Prompt. GitHub: upstash/context7. 2025. https://github.com/upstash/context7
- Anthropic. Introducing the Model Context Protocol. 2024. https://www.anthropic.com/news/model-context-protocol
- Model Context Protocol. What is MCP? https://modelcontextprotocol.io/docs/getting-started/intro
- Digital Applied. Build an MCP Server in TypeScript: From Scratch 2026. 2026. https://www.digitalapplied.com/blog/build-mcp-server-typescript-tutorial-from-scratch-2026
- Joe FRANCOIS. Supercharging Obsidian with AI using MCP. Medium, 2026. https://joemugen.medium.com/supercharging-obsidian-with-ai-using-mcp-319679a36c97
- DavidHDev. React Bits β Animated UI Components. GitHub, 2024. https://github.com/DavidHDev/react-bits
- DavidHDev. Svelte Bits β Svelte Port. GitHub, 2025. https://github.com/DavidHDev/svelte-bits
- Jeremy Howard / Answer.AI. llms.txt Specification. llmstxt.org, 2024. https://llmstxt.org/
- Limy.ai. LLMs.txt in 2026: The Full Guide. 2026. https://limy.ai/blog/llms.txt-in-2026-the-full-guide
- OWASP / WebFuse. MCP Cheat Sheet: Security Best Practices. 2026. https://www.webfuse.com/mcp-cheat-sheet
- cyanheads. Model Context Protocol Resources & Guides. GitHub, 2024. https://github.com/cyanheads/model-context-protocol-resources
- Build MVP Fast. Obsidian + Claude AI Knowledge Management Setup 2026. 2026. https://www.buildmvpfast.com/blog/obsidian-claude-ai-knowledge-management-system-2026
- PkgPulse. react-bits vs Aceternity UI vs Magic UI 2026. 2026. https://www.pkgpulse.com/guides/react-bits-animated-components-2026
- Tech Insider. Svelte vs React 2026: 14x Bundle Gap [Tested]. 2026. https://tech-insider.org/svelte-vs-react-2026-2/
Bottom Line
Context7 MCP menunjukkan arsitektur masa depan: context as a service. Bangun MCP server kustom untuk Digital Garden Anda dengan pola yang samaβparse, enrich, vectorize, rerank, cache. Porting komponen seperti React Bits ke Svelte bukan sekadar translasi kode, tapi adaptasi filosofi reaktivitas. Gabungkan keduanya, dan Anda mendapatkan knowledge system yang tidak hanya menyimpan informasi, tapi aktif berinteraksi dengan AI agent untuk mensintesis, menghubungkan, dan menumbuhkan pengetahuan secara otonom.