Claude Code & MCP MasterclassModule 2

2.3Production MCP — Gmail, Slack, GitHub & Custom API Servers

30 min 8 code blocks Practice Lab Quiz (4Q)

Production MCP — Gmail, Slack, GitHub

This lesson teaches you to build production-grade MCP servers for popular platforms: Gmail for email, Slack for messaging, GitHub for version control. These are the most useful MCPs for Pakistani tech builders.

Gmail MCP Server

Access your Gmail inbox without leaving Claude.

python
from mcp.server import Server
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
import json

app = Server("gmail-mcp")

SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']

def get_gmail_service():
    flow = InstalledAppFlow.from_client_secrets_file(
        'credentials.json', SCOPES)
    creds = flow.run_local_server(port=0)
    return build('gmail', 'v1', credentials=creds)

@app.resource("gmail://inbox")
async def read_inbox():
    service = get_gmail_service()
    results = service.users().messages().list(userId='me', maxResults=10).execute()
    messages = results.get('messages', [])

    inbox_data = []
    for msg in messages:
        data = service.users().messages().get(userId='me', id=msg['id']).execute()
        headers = data['payload']['headers']
        subject = next((h['value'] for h in headers if h['name'] == 'Subject'), 'No Subject')
        inbox_data.append({'id': msg['id'], 'subject': subject})

    return TextContent(text=json.dumps(inbox_data))

@app.tool("send_email")
async def send_email(to: str, subject: str, body: str):
    service = get_gmail_service()
    message = {
        'raw': base64.urlsafe_b64encode(
            f"To: {to}\nSubject: {subject}\n\n{body}".encode()
        ).decode()
    }
    result = service.users().messages().send(userId='me', body=message).execute()
    return f"Email sent: {result['id']}"

if __name__ == "__main__":
    asyncio.run(app.run())

Usage: claude run "Read my last 5 emails and summarize the main topics"

Claude reads your Gmail via MCP, summarizes instantly.

Slack MCP Server

Send messages, read channels, get notifications through Claude.

python
from mcp.server import Server
from slack_sdk import WebClient
import os

app = Server("slack-mcp")
slack_client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])

@app.resource("slack://channels")
async def list_channels():
    result = slack_client.conversations_list()
    channels = result['channels']
    return TextContent(text=json.dumps(channels))

@app.tool("send_slack_message")
async def send_message(channel: str, message: str):
    result = slack_client.chat_postMessage(
        channel=channel,
        text=message
    )
    return f"Message sent to {channel}: {result['ts']}"

@app.tool("read_channel_messages")
async def read_channel(channel: str, limit: int = 10):
    result = slack_client.conversations_history(
        channel=channel,
        limit=limit
    )
    messages = result['messages']
    return TextContent(text=json.dumps(messages))

if __name__ == "__main__":
    asyncio.run(app.run())

Usage: claude run "Post to #marketing channel: We just released v2.0 of our AI bot"

GitHub MCP Server

Query repositories, manage issues, analyze code via Claude.

python
from mcp.server import Server
from github import Github
import os

app = Server("github-mcp")
gh = Github(os.environ['GITHUB_TOKEN'])

@app.resource("github://repos")
async def list_repos():
    user = gh.get_user()
    repos = user.get_repos()
    repo_data = [{'name': r.name, 'url': r.html_url, 'stars': r.stargazers_count} for r in repos]
    return TextContent(text=json.dumps(repo_data))

@app.tool("create_github_issue")
async def create_issue(repo_name: str, title: str, body: str):
    repo = gh.get_user().get_repo(repo_name)
    issue = repo.create_issue(title=title, body=body)
    return f"Issue created: {issue.html_url}"

@app.tool("list_open_issues")
async def list_issues(repo_name: str):
    repo = gh.get_user().get_repo(repo_name)
    issues = repo.get_issues(state='open')
    issue_data = [{'number': i.number, 'title': i.title} for i in issues[:10]]
    return TextContent(text=json.dumps(issue_data))

if __name__ == "__main__":
    asyncio.run(app.run())

Usage: claude run "Create a GitHub issue in my repo: Add Urdu language support"

Pakistan-Specific Production MCPs

Zameen.pk Real Estate MCP:

python
@app.resource("zameen://listings")
async def get_listings(city: str, min_price: int, max_price: int):
    # Scrape or API call to Zameen.pk
    listings = [...]
    return TextContent(text=json.dumps(listings))

@app.tool("analyze_real_estate_market")
async def analyze(city: str, property_type: str):
    # Analyze price trends, demand
    return "DHA Karachi: 15% YoY appreciation"

WATI WhatsApp MCP:

python
@app.tool("send_whatsapp")
async def send_whatsapp(phone: str, message: str):
    # Call WATI API
    response = requests.post(
        "https://api.wati.io/api/v1/sendSessionMessage",
        json={"phoneNumber": phone, "message": message}
    )
    return response.json()

Deployment: Running Production MCP

Option 1: Docker Container

dockerfile
FROM python:3.11
WORKDIR /app
COPY server.py requirements.txt ./
RUN pip install -r requirements.txt
CMD ["python", "server.py"]

Deploy on AWS EC2, DigitalOcean, or Railway. Cost: USD 5-20/month.

Option 2: Vercel Edge Functions (low latency)

code
Deploy your MCP as serverless function. Instant scaling.

Option 3: Local (for testing)

bash
python server.py &
# Runs on localhost:3000

Best Practices

  1. Rate Limiting: Protect against abuse. Limit to 100 calls/minute.
  2. Error Handling: Return meaningful errors. "Gmail API rate limited, retry in 30s"
  3. Security: Store API keys in environment variables, not code.
  4. Caching: Cache resources (Gmail inbox changes rarely, cache 5 minutes).
  5. Logging: Log all Claude requests and responses (for auditing).
Practice Lab

Practice Lab

Task 1: Gmail MCP — Build working Gmail MCP. Connect to your email. Verify Claude can read your inbox and summarize latest emails.

Task 2: Production Deployment — Take one of your MCPs (Crypto, Gmail, Slack). Deploy to production (Vercel, DigitalOcean, AWS). Document setup and costs.

Pakistan Example

Pakistani SaaS founder Shayan builds "Karachi SaaS Dashboard MCP" combining multiple integrations:

  • Gmail (read customer support emails)
  • Slack (post alerts to #support)
  • GitHub (manage issues)
  • Stripe (check payments)
  • Zameen.pk (if real estate product)

One MCP server exposes all platforms. Claude can now: "Which customers emailed support in last 24 hours? Check their Stripe payment status and create GitHub issues for follow-up."

Claude (via MCP):

  1. Reads Gmail (customer emails)
  2. Checks Stripe (payment status)
  3. Creates GitHub issues (follow-up tasks)
  4. Posts to Slack (alert team)

All through one unified interface.

Result: Support automation on steroids. Customer issues resolved 10x faster.

Lesson Summary

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

Production MCP — Gmail, Slack, GitHub Quiz

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