Claude Code & MCP MasterclassModule 2

2.1What is MCP? — Model Context Protocol Explained Simply

25 min 7 code blocks Practice Lab Quiz (4Q)

What is MCP?

Model Context Protocol (MCP) is Anthropic's open standard for extending AI capabilities. Think of MCP as plugins for Claude. Instead of Claude being a closed system, MCP lets you build custom tools, data sources, and integrations that Claude can access. This lesson teaches MCP fundamentals and its power for Pakistani builders.

MCP in Plain English

Claude alone can: Read text, understand code, write prose, solve math. That's useful but limited.

Claude + MCP can: Read your SQL database in real-time, fetch data from external APIs, control smart devices, analyze files from cloud storage, all while Claude reasons about the results.

Example: You ask Claude "What was our revenue last month?" Claude (via MCP) queries your database, processes the data, returns answer with analysis. All in real-time.

Pakistan Example: A Karachi shopkeeper on Daraz asks Claude "Which products are losing money after shipping costs?" Claude (via MCP) pulls Daraz order data, calculates per-item margins after TCS/Leopards shipping fees, and flags unprofitable SKUs. No spreadsheet needed.

MCP Architecture:

code
+--------------------------------------------------+
|              Your Computer / Server               |
|                                                   |
|  +--------------------------------------------+  |
|  |         MCP Host (Claude Code, IDE)         |  |
|  |                                             |  |
|  |  +---------------------------------------+  |  |
|  |  |          MCP Servers (your tools)      |  |  |
|  |  |                                        |  |  |
|  |  |  +-- Database Server (PostgreSQL)      |  |  |
|  |  |  +-- API Server (external APIs)        |  |  |
|  |  |  +-- File Server (Google Drive, S3)    |  |  |
|  |  |  +-- Custom Server (your logic)        |  |  |
|  |  +---------------------------------------+  |  |
|  +--------------------------------------------+  |
+--------------------------------------------------+

Claude communicates with MCP servers. Each server provides "tools" (functions Claude can call). Example tools:

  • read_database: SELECT * FROM users WHERE date > '2026-01-01'
  • fetch_weather: Get current temperature in Karachi
  • send_email: Send email to customer
  • analyze_image: Parse invoice image for amounts

Pakistan-specific tool examples:

  • check_jazzcash_balance: Query JazzCash wallet balance via API
  • verify_cnic: Validate NADRA CNIC number format and status
  • track_shipment: Get TCS/Leopards courier tracking updates
  • fetch_zameen_listings: Pull property listings for a given area
  • send_whatsapp: Send WhatsApp message via WATI to a Pakistani number

Why MCP Matters in 2026

Before MCP: Integrations were hacky. You'd write SDK wrappers, manage API keys, handle timeouts. Complex and fragile.

After MCP: Build once, reuse everywhere. One MCP server for your database, use it in Claude Code, in your web app, in your mobile app. Consistent interface.

Here's the difference visually:

code
BEFORE MCP (fragile spaghetti):

  Claude Code ──── custom wrapper ──── JazzCash API
       |                                    |
       +──── different wrapper ──── Daraz API
       |                                    |
       +──── yet another wrapper ── NADRA API

  (Each wrapper = different auth, error handling, retry logic)


AFTER MCP (clean & unified):

  Claude Code ──── MCP Protocol ──── JazzCash MCP Server
       |                |                    |
       |                +──── Daraz MCP Server
       |                |                    |
       |                +──── NADRA MCP Server

  (One protocol, one interface, one way to handle everything)

For Pakistani builders: MCP enables local-first development. Build MCP server that talks to Zameen.pk API, JazzCash payment system, or NADRA database. Then use Claude to analyze data with AI intelligence. Example: "Analyze which Karachi neighborhoods have highest property appreciation" -> Claude queries Zameen.pk via MCP, runs analysis.

For Pakistani freelancers on Upwork/Fiverr: MCP is a gold mine. International clients pay $50-150/hour for developers who can build AI integrations. If you can build MCP servers, you're offering something most developers globally can't. The niche is fresh and the demand is exploding.

MCP Communication Protocol

MCP uses JSON-RPC (JSON Remote Procedure Call) over stdio (standard input/output). Simple:

code
REQUEST FLOW:
+------------------+    JSON-RPC     +------------------+
|   Claude Code    | -------------> |   MCP Server     |
|   (MCP Client)   | <------------- |   (Your Tool)    |
+------------------+    Response     +------------------+
     via stdio (stdin/stdout pipe)

Client sends:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "resources/read",
  "params": {
    "uri": "database://users"
  }
}

Server responds:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "contents": [
      {
        "uri": "database://users",
        "mimeType": "application/json",
        "text": "[{\"id\": 1, \"name\": \"Ahmed\"}, {\"id\": 2, \"name\": \"Fatima\"}]"
      }
    ]
  }
}

Don't memorize this. Tools abstract it away. You just call tools; the protocol is hidden.

MCP Capabilities

Every MCP server exposes capabilities (what it can do):

(1) Resources: Data sources Claude can read (databases, APIs, files)

  • Example: database://sales-2026 (current year sales data)
  • Example: api://weather (live weather data)
  • Pakistan Example: jazzcash://transactions/march-2026 (monthly JazzCash transaction log)

(2) Tools: Functions Claude can execute

  • Example: query_database(sql) - runs SQL query
  • Example: send_sms(phone, message) - sends SMS via Jazz/Zong
  • Example: create_invoice(items, customer) - generates invoice
  • Pakistan Example: check_daraz_reviews(seller_id) - fetch seller reviews from Daraz
  • Pakistan Example: nadra_cnic_lookup(cnic) - verify identity via NADRA API

(3) Prompts: Pre-built templates Claude can use

  • Example: analyze-financial-statements (template for analyzing business financials)
  • Example: write-cold-email (template for outreach)
  • Pakistan Example: write-daraz-listing (template for optimized Daraz product descriptions in Urdu + English)

(4) Sampling: Let Claude sample data (useful for training/analysis)

  • Example: sample_database(table, limit) - get random 100 rows from table

MCP in Pakistani Context

Example: Pakistani e-commerce platform (Daraz competitor) uses MCP:

MCP Server 1: Inventory System

  • Resources: inventory://products, inventory://warehouse-karachi, inventory://warehouse-lahore
  • Tools: check_stock(product_id, city), reorder_inventory(product_id, quantity), get_stockouts()

MCP Server 2: Customer Data

  • Resources: crm://customers, crm://orders, crm://returns
  • Tools: fetch_customer(id), get_purchase_history(customer_id), identify_vip_customers(revenue_threshold)

MCP Server 3: Payment System

  • Resources: payments://transactions, payments://refunds
  • Tools: process_payment(customer, amount, method), get_payment_status(transaction_id), refund(transaction_id)

Claude can now understand your business end-to-end:

  • "Show me customers who bought but never left a review, then draft personalized thank you emails"
  • Claude: Queries CRM -> identifies customers -> drafts emails via MCP tool

More Pakistani MCP server ideas:

MCP ServerResourcesToolsWho Needs It
Zameen.pk Propertyzameen://listings, zameen://pricessearch_properties(), price_trend()Real estate agents
JazzCash Paymentsjazzcash://balance, jazzcash://historysend_money(), check_status()E-commerce sellers
NADRA Verificationnadra://cnicverify_cnic(), check_expiry()HR departments, fintech
FBR Taxfbr://returns, fbr://ntncalculate_tax(), file_return()Accountants, businesses
Foodpanda Ordersfoodpanda://orders, foodpanda://menuupdate_menu(), track_rider()Restaurant owners

Pakistan Case Study: Karachi Developer Builds MCP for Local Business

Developer: Bilal, 24, freelance developer from Saddar, Karachi. Works on Upwork.

Client: "Taste of Karachi" — a restaurant chain with 3 branches (Clifton, Gulshan, Saddar). They manage orders via a custom PHP system, payments through JazzCash and bank transfer, and deliveries through their own riders.

Problem: The owner (Haris bhai) asks Bilal: "I want to ask AI questions about my business — like which branch is most profitable, which menu items are slow, which riders are late — but my data is in 3 different systems."

Solution: Bilal builds 3 MCP servers:

code
+--------------------------------------------------+
|              Claude Code (Haris bhai)             |
|                                                   |
|  "Which branch had most orders this week?"        |
|  "Show me riders with >30 min avg delivery time"  |
|  "Draft a promotion for slow-moving items"        |
|                                                   |
|          |              |              |           |
|    +-----+----+   +-----+----+   +----+-----+    |
|    | Orders   |   | Payments |   | Delivery |    |
|    | MCP      |   | MCP      |   | MCP      |    |
|    | Server   |   | Server   |   | Server   |    |
|    +-----+----+   +-----+----+   +----+-----+    |
|          |              |              |           |
+----------|--------------|--------------|----------+
           |              |              |
     PHP Order DB   JazzCash API   Rider GPS DB

MCP Server: Orders

  • Resources: orders://today, orders://branch/{branch_id}, menu://items
  • Tools: get_orders(branch, date_range), top_selling_items(branch), slow_items(threshold_days)

MCP Server: Payments

  • Resources: payments://daily, payments://method-split
  • Tools: revenue_by_branch(date), jazzcash_settlements(), pending_payments()

MCP Server: Delivery

  • Resources: riders://active, deliveries://today
  • Tools: avg_delivery_time(rider_id), late_deliveries(threshold_minutes), rider_performance_report()

Result: Haris bhai now opens Claude Code every morning and asks natural-language questions about his business. No dashboards to learn, no reports to generate. Just ask and get answers.

Bilal's Upwork impact: He packages this as "AI Business Intelligence via MCP" and charges $2,000 per setup. He's done 4 clients in 2 months. That's PKR 22 lakh+ from one skill.

MCP Standards & Best Practices

Naming Convention: Use snake_case for tools and resources. query_database not queryDatabase.

Error Handling: Every MCP server must handle errors gracefully.

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Database connection failed",
    "data": { "retry_in": 5 }
  }
}

Rate Limiting: Protect your MCP servers (especially if calling paid APIs like NADRA or JazzCash). Implement rate limiting. Pakistani APIs often have tight quotas — respect them or get banned.

Authentication: Secure your MCP servers. Use API keys or OAuth. Don't expose sensitive data. This is especially critical when dealing with CNIC numbers, payment data, or customer phone numbers — Pakistani data protection laws (PECA 2016) apply.

Testing: Test your MCP server standalone before deploying. Use the MCP Inspector tool or write simple JSON-RPC test scripts.

Logging: Log every tool call with timestamp, input, output, and latency. When your client asks "why did this fail?" you need receipts.

Practice Lab

Practice Lab

Task 1: Understand MCP Architecture — Draw a diagram of how MCP works: (1) Claude Code (client), (2) MCP Host, (3) Your MCP servers, (4) External systems (database, APIs). Label each component and describe its role. Use the ASCII diagram style from this lesson as reference.

Task 2: Plan Custom MCP Server — Design an MCP server for your niche. List: (1) Name, (2) Resources (3-5), (3) Tools (5-10), (4) Use cases. Example: "Restaurant MCP" with resources menu://items, orders://today, tools check_ingredient_stock(), generate_meal_recommendations().

Task 3: Pakistani Business MCP Blueprint — Pick a real Pakistani business you interact with (your neighborhood grocery store, a Daraz seller, a tuition academy, a property dealer). Design a complete MCP setup for them:

  1. List 3 MCP servers they would need
  2. For each server, define 2 resources and 3 tools
  3. Write 5 natural-language questions the business owner could ask Claude once connected
  4. Estimate how much you could charge for building this (hint: PKR 200,000-500,000 is reasonable for a small business AI integration in Pakistan)

Key Takeaways

  • MCP = Plugins for Claude. It lets Claude talk to databases, APIs, files, and any external system through a standard protocol.
  • JSON-RPC over stdio is the communication method. You don't need to memorize it — the SDK handles it. Focus on building tools, not plumbing.
  • Four capability types: Resources (data to read), Tools (functions to execute), Prompts (templates to use), Sampling (data to sample). Tools are what you'll build 80% of the time.
  • Pakistan-specific opportunity is massive. JazzCash, Daraz, Zameen.pk, NADRA, FBR, Foodpanda — none of these have official MCP servers yet. First movers win.
  • MCP servers are reusable. Build a JazzCash MCP server once, use it in every project that needs payment data. This is your competitive moat.
  • Freelancing goldmine. International clients on Upwork will pay $50-150/hour for MCP developers. The skill is new enough that supply is extremely low globally.
  • Security is non-negotiable. When handling Pakistani customer data (CNIC, phone numbers, payment info), follow PECA 2016 guidelines. Encrypt sensitive fields, log access, rate-limit everything.
  • Start small, think big. Your first MCP server can be a simple SQLite reader. Your tenth can be a multi-system AI business intelligence layer worth lakhs.

Conclusion

MCP is the future of AI integration. Instead of hacking API calls into your code, you define a clean interface (MCP server), and Claude understands it instantly.

Master MCP, and you can build AI systems that integrate with any Pakistani business system: Zameen.pk property data, JazzCash payments, WhatsApp via WATI, SMS via Jazz/Zong, Daraz seller tools, NADRA verification, FBR tax filing. All unified under Claude's intelligence.

The developers who learn MCP now will be the ones Pakistani businesses come to when they want AI. That developer should be you.

Lesson Summary

Includes hands-on practice lab7 runnable code examples4-question knowledge check below

What is MCP Quiz

4 questions to test your understanding. Score 60% or higher to pass.