MCP ও Tool Integration

লেসন ২৪ / ৪৬

🔌 MCP কী?

Model Context Protocol — Anthropic-এর open standard (2024 launch) LLM আর tool/data source-এর মধ্যে communication-এর জন্য। USB-C-র মতো standard।

🎯 MCP কেন দরকার?

  • Every LLM app-এ tool wiring boilerplate
  • Tool reuse নেই cross-platform
  • N×M problem (N apps × M tools)
  • Standard-ই solution (1 interface)

🏗️ MCP Architecture

┌──────────┐       ┌─────────────┐       ┌──────────┐
│ Client   │←─MCP─→│ MCP Server  │←─────→│ Data/API │
│ (Claude, │       │ (exposes    │       │ (DB,     │
│  Cursor) │       │  tools)     │       │  files)  │
└──────────┘       └─────────────┘       └──────────┘

Client = AI app (LLM consumer)
Server = Tool provider
Protocol = JSON-RPC over stdio/SSE

📦 MCP Primitive

  • Tools — callable function (get_weather)
  • Resources — readable data (file://path)
  • Prompts — reusable template
  • Sampling — LLM call from server

🛠️ Official MCP Server (পরিচিত)

  • Filesystem — local file read/write
  • Git — repo operation
  • GitHub — PR, issue
  • Postgres — DB query
  • Slack — message
  • Google Drive
  • Puppeteer — browser automate
  • Brave Search
  • Fetch — URL read

🧪 MCP Server Example (Python)

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("My Server")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@mcp.resource("config://app")
def get_config() -> str:
    return "App configuration data"

@mcp.prompt()
def review_code(code: str) -> str:
    return f"Please review:\n{code}"

if __name__ == "__main__":
    mcp.run()

🔗 Claude Desktop-এ MCP Configure

// ~/Library/Application Support/Claude/
// claude_desktop_config.json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem",
               "/Users/me/Documents"]
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres",
               "postgresql://localhost/mydb"]
    }
  }
}

💡 Use Case ⭐

  • Claude Desktop → local file read/edit
  • Cursor → database query
  • IDE → Jira ticket create
  • Chat → calendar access
  • Assistant → company CRM

🆚 MCP vs Function Calling

Function CallingMCP
Per-app definitionStandard protocol
Tied to LLM providerProvider-agnostic
JSON schemaJSON-RPC + schema
No resource conceptTools + Resources + Prompts
Client-sideSeparate server process

🌐 Other Tool Integration Approach

OpenAI Function Calling

Native OpenAI, JSON schema, simple।

LangChain Tools

Python/JS framework, lots of pre-built।

OpenAPI (Swagger)

REST API spec → LLM tool automatic।

ChatGPT Actions

OpenAPI-based, Custom GPT integration।

🔐 Security Consideration

  • MCP server sandboxed চালান
  • Permission scope minimum
  • User approval destructive action-এ
  • Audit log প্রতিটা call
  • Auth token rotate
  • Rate limit per client
  • Malicious prompt injection guard

🚀 Custom Integration Build

Step 1: Identify Use Case

আপনার daily tool — কোনটা AI-তে access করতে চান?

Step 2: API Exist?

  • হ্যাঁ → wrap as MCP server
  • না → scraping/automation বানান

Step 3: Tool Design

Small, composable tool। Big mega-function এড়ান।

Step 4: Error Handling

Clear error message, LLM retry/recover করতে পারে।

Step 5: Documentation

Tool description ভালো → LLM সঠিক use করবে।

📚 Resource

  • modelcontextprotocol.io — official
  • GitHub MCP servers registry
  • Claude Code MCP integration
  • Awesome-MCP (community)

🔮 Future of MCP

  • LLM ecosystem standard হবে
  • Enterprise tool catalog
  • Privacy-preserving local execution
  • Cross-platform agent marketplace
  • AI app = MCP client + config