spinny:~/writing $ less mcp-model-context-protocol-guide.md
12Ang **Model Context Protocol (MCP)** ay isang bukas na pamantayan na ginawa ng Anthropic na tumutukoy kung paano nakikipag-usap ang mga AI model sa mga panlabas na tool, data source, at serbisyo. Isipin ito bilang "USB-C ng AI" - isang unibersal na connector na nagpapahintulot sa anumang AI agent na makipag-usap sa anumang tool sa pamamagitan ng isang standardized na interface.34Mula nang ilunsad, ang MCP ay lumampas sa **97 milyong buwanang SDK download** at pinagtibay ng bawat pangunahing AI provider: Anthropic, OpenAI, Google, Microsoft, at Amazon. Sa gabay na ito, tutuklasin natin ang lahat ng kailangan mong malaman para gumawa gamit ang MCP.56## Bakit Umiiral ang MCP78Bago ang MCP, bawat AI application ay kailangang gumawa ng custom na integration para sa bawat tool na gusto nitong gamitin. Gusto mo bang magbasa ng mga file ang iyong AI? Magsulat ng custom na code. Mag-query ng database? Higit pang custom na code. Mag-post sa Slack? Isa pang integration.910Lumikha ito ng **problemang N×M**: N na AI application na bawat isa ay nangangailangan ng M na custom integration, na humahantong sa doble na pagsisikap at pira-pirasong mga ecosystem.1112```mermaid13graph TD14 subgraph "Before MCP (N×M)"15 A1[AI App 1] --> T1[GitHub Integration]16 A1 --> T2[Slack Integration]17 A1 --> T3[DB Integration]18 A2[AI App 2] --> T4[GitHub Integration]19 A2 --> T5[Slack Integration]20 A2 --> T6[DB Integration]21 end22```2324Nilulutas ito ng MCP gamit ang **iisang protokol** na maaaring gamitin ng anumang AI client upang makipag-usap sa anumang MCP server:2526```mermaid27graph TD28 subgraph "With MCP (N+M)"29 A1[AI App 1] --> MCP[MCP Protocol]30 A2[AI App 2] --> MCP31 MCP --> S1[GitHub Server]32 MCP --> S2[Slack Server]33 MCP --> S3[DB Server]34 end35```3637## Mga Pangunahing Konsepto3839Ang MCP ay may tatlong pangunahing primitive:4041### 1. Mga Tool42Ang mga tool ay mga function na maaaring tawagin ng AI. Kumakatawan ang mga ito sa mga aksyon tulad ng "gumawa ng file", "mag-query ng database", o "magpadala ng mensahe". Bawat tool ay may pangalan, paglalarawan, at JSON Schema para sa mga parameter nito.4344```typescript45{46 name: "create_issue",47 description: "Create a new GitHub issue",48 inputSchema: {49 type: "object",50 properties: {51 title: { type: "string", description: "Issue title" },52 body: { type: "string", description: "Issue body" },53 repo: { type: "string", description: "Repository name" }54 },55 required: ["title", "repo"]56 }57}58```5960### 2. Mga Resource61Ang mga resource ay data na maaaring basahin ng AI. Kumakatawan ang mga ito sa mga file, database record, API response, o anumang iba pang data source. Ang mga resource ay kinikilala sa pamamagitan ng mga URI.6263```typescript64{65 uri: "file:///Users/dev/project/README.md",66 name: "Project README",67 mimeType: "text/markdown"68}69```7071### 3. Mga Prompt72Ang mga prompt ay reusable na template na tumutulong sa pag-structure ng mga interaksyon. Maaari silang magsama ng mga dynamic na parameter at kapaki-pakinabang para sa pag-standardize ng mga karaniwang workflow.7374```typescript75{76 name: "code_review",77 description: "Review code changes for quality and security",78 arguments: [79 { name: "diff", description: "The code diff to review", required: true }80 ]81}82```8384## Arkitektura8586Sumusunod ang MCP sa isang client-server na arkitektura:8788```mermaid89graph LR90 subgraph "Host Application"91 Client[MCP Client]92 end9394 subgraph "MCP Server"95 Server[Server Process]96 Server --> Tools[Tools]97 Server --> Resources[Resources]98 Server --> Prompts[Prompts]99 end100101 Client -- "JSON-RPC 2.0\n(stdio or SSE)" --> Server102```103104- **Host**: Ang AI application (Claude Desktop, Cursor, ang iyong custom na app)105- **Client**: Nagpapanatili ng 1:1 na koneksyon sa isang MCP server106- **Server**: Nag-expose ng mga tool, resource, at prompt sa client107- **Transport**: Nangyayari ang komunikasyon sa pamamagitan ng JSON-RPC 2.0 sa stdio (lokal) o Server-Sent Events (remote)108109## Pagbuo ng MCP Server110111Gumawa tayo ng praktikal na MCP server na nakikipag-ugnayan sa isang todo list na naka-store sa JSON file.112113### Setup114115```bash116mkdir mcp-todo-server && cd mcp-todo-server117npm init -y118npm install @modelcontextprotocol/sdk zod119```120121### Server Implementation122123```typescript124// src/index.ts125import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";126import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";127import { z } from "zod";128import fs from "fs";129130const TODO_FILE = "./todos.json";131132function readTodos(): { id: number; text: string; done: boolean }[] {133 if (!fs.existsSync(TODO_FILE)) return [];134 return JSON.parse(fs.readFileSync(TODO_FILE, "utf-8"));135}136137function writeTodos(todos: { id: number; text: string; done: boolean }[]) {138 fs.writeFileSync(TODO_FILE, JSON.stringify(todos, null, 2));139}140141const server = new McpServer({142 name: "todo-server",143 version: "1.0.0",144});145146// Tool: Add a todo147server.tool(148 "add_todo",149 "Add a new todo item",150 { text: z.string().describe("The todo text") },151 async ({ text }) => {152 const todos = readTodos();153 const newTodo = { id: Date.now(), text, done: false };154 todos.push(newTodo);155 writeTodos(todos);156 return { content: [{ type: "text", text: `Added: "${text}"` }] };157 }158);159160// Tool: List todos161server.tool(162 "list_todos",163 "List all todo items",164 {},165 async () => {166 const todos = readTodos();167 const list = todos168 .map((t) => `${t.done ? "✅" : "⬜"} [${t.id}] ${t.text}`)169 .join("\n");170 return { content: [{ type: "text", text: list || "No todos yet." }] };171 }172);173174// Tool: Complete a todo175server.tool(176 "complete_todo",177 "Mark a todo as completed",178 { id: z.number().describe("The todo ID to complete") },179 async ({ id }) => {180 const todos = readTodos();181 const todo = todos.find((t) => t.id === id);182 if (!todo) return { content: [{ type: "text", text: "Todo not found." }] };183 todo.done = true;184 writeTodos(todos);185 return { content: [{ type: "text", text: `Completed: "${todo.text}"` }] };186 }187);188189// Resource: Current todos as a readable resource190server.resource(191 "todos://list",192 "Current todo list",193 async () => ({194 contents: [{195 uri: "todos://list",196 mimeType: "application/json",197 text: JSON.stringify(readTodos(), null, 2),198 }],199 })200);201202// Start the server203const transport = new StdioServerTransport();204await server.connect(transport);205```206207### Configuration208209Para magamit ang server na ito sa Claude Desktop, idagdag ito sa iyong config:210211```json212{213 "mcpServers": {214 "todo": {215 "command": "npx",216 "args": ["tsx", "/path/to/mcp-todo-server/src/index.ts"]217 }218 }219}220```221222## Pagbuo ng MCP Client223224Maaari ka ring gumawa ng custom na client na kumokonekta sa anumang MCP server:225226```typescript227import { Client } from "@modelcontextprotocol/sdk/client/index.js";228import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";229230const transport = new StdioClientTransport({231 command: "npx",232 args: ["tsx", "./src/index.ts"],233});234235const client = new Client({ name: "my-client", version: "1.0.0" });236await client.connect(transport);237238// List available tools239const { tools } = await client.listTools();240console.log("Available tools:", tools.map((t) => t.name));241242// Call a tool243const result = await client.callTool({244 name: "add_todo",245 arguments: { text: "Write MCP blog post" },246});247console.log(result);248```249250## Mga Sikat na MCP Server251252Mabilis na lumago ang MCP ecosystem. Narito ang ilan sa mga pinakasikat na server:253254| Server | Paglalarawan | Gamit |255|--------|-------------|-------|256| **GitHub** | Gumawa ng issue, PR, pamahalaan ang repo | Mga workflow ng development |257| **Slack** | Magpadala ng mensahe, pamahalaan ang channel | Komunikasyon ng team |258| **PostgreSQL** | Mag-query at pamahalaan ang database | Access sa data |259| **Filesystem** | Magbasa, magsulat, at maghanap ng file | Lokal na development |260| **Puppeteer** | Browser automation at scraping | Web testing |261| **Sentry** | Error monitoring at debugging | Production support |262| **Supabase** | Database, auth, storage | Backend operation |263264## MCP vs A2A (Agent-to-Agent)265266Habang ang MCP ang namamahala sa komunikasyong **agent-to-tool**, ang **A2A (Agent-to-Agent)** protocol ng Google ang namamahala sa komunikasyong **agent-to-agent**. Magkakatuwang sila:267268```mermaid269graph TD270 Agent1[Agent 1] -- "A2A Protocol" --> Agent2[Agent 2]271 Agent1 -- "MCP Protocol" --> Tool1[GitHub MCP Server]272 Agent2 -- "MCP Protocol" --> Tool2[Database MCP Server]273```274275- **MCP**: Paano gumagamit ng tool ang AI agent (vertical integration)276- **A2A**: Paano nagtutulungan ang mga AI agent (horizontal integration)277278## Mga Pinakamahusay na Gawi2792801. **Panatilihing focused ang mga server**: Isang server bawat domain (GitHub server, Slack server, atbp.). Huwag gumawa ng monolithic na server.2812. **I-validate ang input gamit ang Zod**: Laging i-validate ang tool input gamit ang tamang schema.2823. **Hawakan ang mga error nang maayos**: Magbalik ng makabuluhang error message, hindi stack trace.2834. **Gumamit ng resource para sa read-only na data**: Kung kailangan lang ng AI na magbasa ng data, i-expose ito bilang resource sa halip na tool.2845. **Magdagdag ng wastong paglalarawan**: Ang magandang paglalarawan ng tool at parameter ay tumutulong sa AI na maunawaan kung kailan at paano gamitin ang bawat tool.2856. **Mag-test gamit ang MCP Inspector**: Gamitin ang `npx @modelcontextprotocol/inspector` para i-test ang iyong server nang interactive.286287## Magsimula288289```bash290# Create a new MCP server from template291npx @modelcontextprotocol/create-server my-server292293# Test with the MCP Inspector294npx @modelcontextprotocol/inspector npx tsx ./src/index.ts295```296297## Konklusyon298299Ang MCP ay naging de facto na pamantayan para sa paggamit ng AI tool noong 2026. Gumagawa ka man ng custom na AI agent, pinapalawak ang Claude Code, o gumagawa ng integration para sa mga umiiral na platform, ang pag-unawa sa MCP ay mahalaga. Ang protokol ay sapat na simple para matutunan sa isang hapon ngunit sapat na malakas para bumuo ng production-grade na AI workflow.300301**Mga susunod na hakbang:**302- Tuklasin ang [MCP Specification](https://spec.modelcontextprotocol.io/)303- I-browse ang [mga umiiral na MCP server](https://github.com/modelcontextprotocol/servers) para sa inspirasyon304- Buuin ang iyong unang server gamit ang TypeScript o Python SDK305- I-test ito gamit ang Claude Desktop o MCP Inspector306
:MCP (Model Context Protocol): Ang Kumpletong Gabay para sa mga Developerlines 1-306 (END) — press q to close