notifications-mcp
Unified Notifications MCP Server that enables AI agents to send email alerts via Gmail. Supports OAuth authentication and multiple recipients.
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
- Official MCP Specification Standard: JSON-RPC 2.0 transport over Streamable HTTP (
POST /mcpandGET /mcpSSE). - 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.
- Security Guardrails:
- Auth Enforcement: Every
/mcprequest 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).
- Auth Enforcement: Every
- 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_datetimeandsend_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
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.