Lộ trình học›Claude API›Building with the Claude API Mở bản đồ

6.68 · MCP review — Tổng kết pattern

Bài viếtTrung cấp → Nâng15 phút đọc
Sau bài này, bạn sẽ
  1. Review toàn bộ MCP architecture
  2. Decision framework: khi nào MCP vs tool use vs API
  3. Production checklist
  4. Resource để continue learning

MCP architecture summary

┌───────────────────────────────────────────────┐
│                                               │
│   YOUR APP                                    │
│   ├─ Anthropic client (Claude)                │
│   └─ MCP client(s)                            │
│       │                                       │
│       ├─ Connect via stdio/HTTP/WS            │
│       ▼                                       │
│   MCP server(s)                               │
│       ├─ Tools (actions)                      │
│       ├─ Prompts (templates)                  │
│       └─ Resources (read-only data)           │
│           │                                   │
│           ▼                                   │
│       External services / data                │
│                                               │
└───────────────────────────────────────────────┘

3 primitives

ToolsPromptsResources
PurposeActionsTemplatesData
Read/writeExecuteGenerate messagesRead only
URINoNoYes
Claude invokesYesIndirectly (user triggers)Via prompt mention
SDK@mcp.tool@mcp.prompt@mcp.resource

Decision framework

Build MCP server when:

  • > 5 integrations planned
  • Share tools across multiple apps
  • Want community to use (open-source)
  • Long-term maintenance
  • Service provider exposing for AI use

Build MCP client when:

  • Connect to existing MCP servers
  • Enterprise integrating multiple systems
  • Cross-app tool access needed

Skip MCP (use plain tool use):

  • Simple app, 1-3 custom tools
  • Proof of concept, MVP
  • Tools deeply tied to app logic
  • Short-term project

Skip API direct (use MCP):

  • Slack/GitHub/etc. provide MCP → use MCP (less maintenance)
  • You expose service to AI clients → MCP standard

Production checklist

Server side

  • Tools have descriptive names + rich descriptions
  • Pydantic Field descriptions cho mỗi param
  • Error handling với raise ValueError("message")
  • Auth/permission checks if sensitive
  • Rate limiting if external API backend
  • Logging qua log_level
  • Tested qua Inspector + pytest
  • Resource URIs follow consistent scheme
  • Prompts well-crafted (expert-level)

Client side

  • Reuse sessions (not per-request)
  • Handle isError from tool calls
  • Timeout on tool calls
  • Tool name namespacing (if multi-server)
  • Error recovery / retry
  • UX for slash commands (prompts)
  • Resource caching
  • Monitor: tool call volume, success rate, latency

Integration with Claude

  • MCP tools converted correctly to Anthropic schema
  • Multi-turn loop with max_turns safety
  • Tool results formatted correctly back to Claude
  • Conversation history managed

Common mistakes

1. MCP server with side effects in resources

Violates contract. Debug hell.

Fix: Resources = read only. Side effects = tools.

2. Tool name collision between servers

Multiple servers → same tool name → ambiguity.

Fix: Namespace github:get_user, slack:get_user.

3. Not handling disconnection

Server crashes → client hangs.

Fix: Heartbeat, auto-reconnect.

4. Exposing too much

All DB tables as resources → security risk, confusion.

Fix: Curated views only.

5. Per-tool manual schema

Manually maintain JSON schemas → drift from code.

Fix: Use @mcp.tool + type hints.

Ecosystem resources

Official servers (curated list)

github.com/modelcontextprotocol/servers

Includes:

  • Filesystem
  • GitHub
  • PostgreSQL
  • Brave Search
  • Google Drive
  • Slack
  • Memory
  • Sequential thinking
  • Many more

Community

Claude Desktop

Native MCP integration. Install MCP servers, use directly trong Desktop chat.

Config: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/you/docs"]
    }
  }
}

Advanced topics (not covered in course)

  • Authentication/OAuth — MCP 2.0+ spec
  • Streaming responses — large data streams
  • Logging / observability — structured MCP logs
  • Compression — cho large resource content
  • Federated MCP — one server aggregating others
  • Security model — sandboxing untrusted servers

Anthropic docs có chi tiết.

When MCP không fit

  • Latency critical (< 50ms) — MCP adds overhead
  • Simple 1-tool integration — plain tool use simpler
  • Ephemeral tools — tạo cho 1 conversation rồi bỏ

Review code: Full MCP chatbot

Bạn đã build:

  • mcp_server.py — FastMCP với tools, prompts, resources
  • mcp_client.py — Python client wrapper
  • main.py — chatbot với Claude + MCP integration
  • Inspector testing workflow
  • Slash commands
  • @mention resources

Production-ready skeleton. Real apps add:

  • Auth
  • Persistent storage
  • UI (web, desktop)
  • Deployment (containerize MCP server)

Áp dụng ngay

Bài tập 1: Evaluate your project (20 phút)

Review your MCP implementation:

  • Production checklist pass?
  • Any anti-patterns present?
  • Performance acceptable?

Bài tập 2: Explore ecosystem (30 phút)

Visit github.com/modelcontextprotocol/servers. Try 1 official server (filesystem, sqlite, memory).

Connect qua your MCP client. Test.

Tóm tắt bài học

Những điều cốt lõi
  • MCP = open standard cho AI-tool integration. Gaining adoption 2025-2026.
  • 3 primitives: Tools (actions), Prompts (templates), Resources (data).
  • Build server if exposing service. Build client if consuming.
  • Production checklist ensures robust implementation.
  • Ecosystem growing fast — check registry regularly.
Bạn đã hoàn thành bài này chưa?Tiến độ lưu trên trình duyệt của bạn.