notifications-mcp

notifications-mcp

Unified Notifications MCP Server that enables AI agents to send email alerts via Gmail. Supports OAuth authentication and multiple recipients.

Category
Visit Server

README

Streamable HTTP + SSE MCP Server

Production-Ready Model Context Protocol (MCP) Server with Streamable HTTP + SSE, Bearer Authentication, Strict Session-Identity Binding, Prompt Injection Guardrails, Recipient Allowlisting, and Rate Limiting.


๐Ÿ‘ฅ Work Split & Responsibilities

Contributor Area & Deliverables
@Vinod Server scaffolding, Streamable HTTP (POST + GET SSE) transport, Mcp-Session-Id session management, Last-Event-ID resumability, hosting & tunnel setup (scripts/run_tunnel.py), Bearer token authentication, Origin checks, and JSON-RPC error-handling layer.
@Vishal Tool handlers (get_current_datetime, send_email), input validation & Pydantic schemas, prompt injection detection & audit logging, recipient allowlist & sliding-window rate limiting, and 6 Live Demo verification test cases (scripts/test_demo_cases.py).

๐ŸŒŸ Core Features & Standards

  1. Official MCP Specification Standard: JSON-RPC 2.0 transport over Streamable HTTP (POST /mcp and GET /mcp SSE).
  2. Session Security & Resumability:
    • Mcp-Session-Id: UUID sessions strictly tied to authenticated caller identities.
    • Last-Event-ID: SSE event ring buffer for event replay upon reconnect.
  3. Security Guardrails:
    • Auth Enforcement: Every /mcp request requires a valid Bearer token or API key.
    • Session Hijacking Defense: Session IDs cannot be shared across different identities.
    • Prompt Injection Defense: Regex and heuristic analyzer scanning email fields with security audit logging.
    • Recipient Allowlist & Rate Limits: Prevents unauthorized email exfiltration and flooding.
    • Clean Error Sanitization: Generic, safe JSON-RPC errors (no stack trace leaks).
  4. Mock Tools:
    • get_current_datetime(timezone?): System date/time with IANA timezone validation.
    • send_email(to, subject, body): Server SMTP with safe simulation demo mode.

๐Ÿ“ Repository Structure

Custom_MCP_Server/
โ”œโ”€โ”€ config.yaml                    # Server, auth tokens, allowlists, rate limits, and SMTP config
โ”œโ”€โ”€ pyproject.toml                 # Package definition & dependencies
โ”œโ”€โ”€ requirements.txt               # Dependencies
โ”œโ”€โ”€ README.md                      # Documentation & demo checklist
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ run_tunnel.py              # Hosting / tunnel launcher (Cloudflared, Ngrok, Localtunnel, Local)
โ”‚   โ””โ”€โ”€ test_demo_cases.py         # Automated verification suite for the 6 Live Demo test cases
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ config.py                  # Typed configuration models
โ”‚   โ”œโ”€โ”€ server.py                  # Starlette Streamable HTTP + SSE application
โ”‚   โ”œโ”€โ”€ registry.py                # MCP tools registration & dispatcher
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ middleware.py          # Auth, Origin, and session validation middleware
โ”‚   โ”‚   โ””โ”€โ”€ session_manager.py     # UUID session manager with Last-Event-ID buffer
โ”‚   โ”œโ”€โ”€ security/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ injection_detector.py  # Prompt injection detector & audit logger
โ”‚   โ”‚   โ”œโ”€โ”€ allowlist.py           # Email recipient & domain allowlist validator
โ”‚   โ”‚   โ””โ”€โ”€ rate_limiter.py        # Sliding-window rate limiter per caller
โ”‚   โ”œโ”€โ”€ common/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ errors.py              # JSON-RPC 2.0 error codes and builders
โ”‚   โ”‚   โ””โ”€โ”€ logging.py             # Structured JSON logger with security tags
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ datetime_tool.py       # get_current_datetime tool handler
โ”‚       โ””โ”€โ”€ email_tool.py          # send_email tool handler with SMTP/demo mode
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ conftest.py
    โ”œโ”€โ”€ test_datetime_tool.py      # Datetime unit tests
    โ”œโ”€โ”€ test_email_tool.py         # Email & security guardrail tests
    โ”œโ”€โ”€ test_security_auth.py      # Auth & session isolation tests
    โ””โ”€โ”€ test_streamable_http.py    # Streamable HTTP / SSE transport tests

๐Ÿš€ Quickstart Guide

1. Prerequisites

  • Python 3.10+
  • Node.js (optional, for MCP Inspector)

2. Install Dependencies

pip install -r requirements.txt

3. Start the Server

python -m src.server

You will see:

{"timestamp": "...", "level": "INFO", "message": "Starting Streamable MCP Server | host=0.0.0.0 | port=8100"}
{"timestamp": "...", "level": "INFO", "message": "MCP POST/GET endpoint  โ†’ http://localhost:8100/mcp"}
{"timestamp": "...", "level": "INFO", "message": "Health check probe     โ†’ http://localhost:8100/health"}

โš™๏ธ Configuration (config.yaml)

server:
  host: "0.0.0.0"
  port: 8100
  allowed_origins:
    - "http://localhost:8100"
    - "*"

auth:
  enabled: true
  tokens:
    "agent-token-alpha": "agent_alpha"
    "agent-token-beta": "agent_beta"
    "vishal-test-token": "vishal_engineer"
    "vinod-test-token": "vinod_engineer"

security:
  email:
    allowlist:
      - "ops@company.com"
      - "manager@company.com"
      - "vishal@company.com"
      - "vinod@company.com"
      - "*@trusteddomain.com"
    rate_limit:
      max_calls: 10
      window_seconds: 60
    prompt_injection_guard:
      enabled: true

smtp:
  mode: "simulation"  # "simulation" (safe for testing/demos) or "smtp" (live server)
  host: "smtp.example.com"
  port: 587
  sender_address: "notifications@company.com"

๐Ÿ› ๏ธ Tool Schemas

Tool 1: get_current_datetime

  • Description: Returns the current host system date and time with optional IANA timezone conversion.
  • Parameters:
    {
      "type": "object",
      "properties": {
        "timezone": {
          "type": "string",
          "description": "Optional IANA timezone name (e.g. 'UTC', 'America/New_York', 'Asia/Kolkata')."
        }
      },
      "required": []
    }
    

Tool 2: send_email

  • Description: Sends an email notification via server SMTP with strict security guardrails.
  • Parameters:
    {
      "type": "object",
      "properties": {
        "to": {
          "type": "string",
          "description": "Recipient email address. Must be in the authorized allowlist."
        },
        "subject": {
          "type": "string",
          "description": "Email subject line."
        },
        "body": {
          "type": "string",
          "description": "Email body content."
        }
      },
      "required": ["to", "subject", "body"]
    }
    

๐Ÿ”Œ Connecting with MCP Inspector & cURL

Connect via MCP Inspector:

npx @modelcontextprotocol/inspector

Connect to URL: http://localhost:8100/mcp with Custom Header: Authorization: Bearer vishal-test-token.

Sample cURL Invocations:

1. Call get_current_datetime:

curl -X POST http://localhost:8100/mcp \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer vishal-test-token" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "get_current_datetime",
      "arguments": {"timezone": "Asia/Kolkata"}
    }
  }'

2. Call send_email:

curl -X POST http://localhost:8100/mcp \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer vishal-test-token" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "send_email",
      "arguments": {
        "to": "ops@company.com",
        "subject": "System Status",
        "body": "All services operating normally."
      }
    }
  }'

๐ŸŒ Hosting & Tunnel Setup

To expose the MCP server to a public URL / cloud demo:

# Option 1: Direct Local / VM binding
python scripts/run_tunnel.py --mode local --port 8100

# Option 2: Cloudflare Tunnel (Free, no port-forwarding needed)
python scripts/run_tunnel.py --mode cloudflared --port 8100

# Option 3: Ngrok
python scripts/run_tunnel.py --mode ngrok --port 8100

# Option 4: Localtunnel
python scripts/run_tunnel.py --mode localtunnel --port 8100

๐Ÿงช Live Demo Checklist (6 Test Cases)

Run the automated test runner to verify all 6 demo cases in one command:

python scripts/test_demo_cases.py

Or run with pytest:

pytest -v

Verified Test Cases:

  • [x] Case 1: Authorized call to each tool succeeds (both get_current_datetime and send_email).
  • [x] Case 2: Unauthorized caller gets a generic error (HTTP 401, error code -32001).
  • [x] Case 3: Malformed input returns a clean validation error (invalid timezone or missing schema fields).
  • [x] Case 4: Prompt injection attempts in email are blocked and logged (e.g. system prompt overrides).
  • [x] Case 5: Sending to non-allowlisted email is rejected (blocks external/unauthorized addresses).
  • [x] Case 6: Session ID reuse across different identities is denied (HTTP 403, error code -32005).

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured