Cloudflare Worker MCP server for Mem.ai - Edge-deployed intelligent memory platform with OAuth protection
Mem.ai MCP Server - Cloudflare Worker
A production-ready Cloudflare Worker that provides AI assistants with intelligent access to Mem.ai's knowledge management platform via the Model Context Protocol (MCP).
✨ Features
- 🧠 Intelligent Memory: Save and process content with Mem It's AI-powered organization
- 📝 Note Management: Create, read, and delete structured markdown notes
- 📁 Collections: Organize notes into searchable collections
- 🔒 OAuth Protected: GitHub OAuth authentication (optional)
- ⚡ Edge Deployment: Low-latency access via Cloudflare's global network
- 🆓 Free Tier: Runs on Cloudflare's generous free tier
- 🎯 6 MCP Tools: Complete Mem.ai API coverage
📋 Prerequisites
- Cloudflare account (free tier works!)
- Mem.ai account and API key
- Wrangler CLI installed
- Node.js 18+ and npm
🚀 Quick Start
Installation
# Clone the repository
git clone https://github.com/BurtTheCoder/mcp-mem.ai-cfw.git
cd mcp-mem.ai-cfw
# Install dependencies
npm install
# Run automated setup
./setup.sh
The setup script will:
- Create KV namespaces (for OAuth mode)
- Generate
wrangler.tomlconfiguration - Configure secrets (API keys)
- Guide you through OAuth setup (if selected)
Deployment Modes
Option 1: OAuth-Protected (Recommended for Production)
Secure access with GitHub OAuth authentication.
# During setup, choose option 1
./setup.sh
# Deploy to Cloudflare
npm run deploy
OAuth Setup Requirements:
- Create a GitHub OAuth App at https://github.com/settings/developers
- Set callback URL to:
https://mem-mcp-server.<your-subdomain>.workers.dev/github/callback - Configure Client ID and Secret during setup
Option 2: Simple Mode (Development)
No OAuth - direct API key authentication.
# During setup, choose option 2
./setup.sh
# Deploy to Cloudflare
npm run deploy
Local Development
# Start local development server
npm run dev
# Access at http://localhost:8787
🛠️ Available MCP Tools
1. mem_it - Intelligent Content Processing
Save and automatically process any content type with AI-powered organization.
Parameters:
input(required): Content to save (text, HTML, markdown)instructions(optional): Processing instructionscontext(optional): Additional contexttimestamp(optional): ISO 8601 timestamp
Example:
{
"input": "Meeting notes: Discussed Q1 roadmap...",
"instructions": "Extract action items",
"context": "Product Planning"
}
2. create_note - Create Structured Note
Create a markdown-formatted note with explicit organization.
Parameters:
content(required): Markdown contentcollection_ids(optional): UUIDs of collectionscollection_titles(optional): Collection titles
3. read_note - Read Note by ID
Retrieve full note content and metadata.
Parameters:
note_id(required): UUID of the note
4. delete_note - Delete Note
Permanently delete a note.
Parameters:
note_id(required): UUID of the note
5. create_collection - Create Collection
Create a collection for organizing related notes.
Parameters:
title(required): Collection titledescription(optional): Markdown description
6. delete_collection - Delete Collection
Delete a collection (notes remain, just unassociated).
Parameters:
collection_id(required): UUID of the collection
⚙️ Configuration
Environment Variables (Secrets)
Set via wrangler secret put:
# Required
wrangler secret put MEM_API_KEY
# Optional (for OAuth mode)
wrangler secret put GITHUB_CLIENT_ID
wrangler secret put GITHUB_CLIENT_SECRET
wrangler.toml
Generated by setup.sh. Manual configuration:
name = "mem-mcp-server"
main = "src/github-oauth-index.ts" # or src/simple-index.ts
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
[[durable_objects.bindings]]
name = "MCP_AGENT"
class_name = "MemMCPAgent"
[[migrations]]
tag = "v1"
new_sqlite_classes = ["MemMCPAgent"]
# For OAuth mode only:
[[kv_namespaces]]
binding = "OAUTH_KV"
id = "your_kv_namespace_id"
preview_id = "your_preview_kv_id"
🏗️ Architecture
src/
├── types.ts # TypeScript interfaces & Zod schemas
├── mem-client.ts # Mem.ai API client
├── mcp-agent.ts # Durable Object with 6 MCP tools
├── github-oauth-index.ts # OAuth-protected worker
└── simple-index.ts # Simple worker (no OAuth)
Key Components
1. Durable Object (mcp-agent.ts)
- Stateful MCP server instance
- Handles all 6 Mem.ai tools
- Uses SQLite for persistence
2. API Client (mem-client.ts)
- TypeScript wrapper for Mem.ai API
- Error handling and validation
- Type-safe with Zod schemas
3. OAuth Handler (github-oauth-index.ts)
- GitHub OAuth flow
- PKCE support
- Token management with KV storage
4. Simple Handler (simple-index.ts)
- Direct SSE endpoint
- No authentication overhead
- Perfect for development
📚 API Endpoints
OAuth Mode
| Endpoint | Description |
|----------|-------------|
| / | Server information |
| /authorize | OAuth authorization |
| /token | Token exchange |
| /github/callback | OAuth callback |
| /sse | SSE endpoint (authenticated) |
| /.well-known/oauth-authorization-server | OAuth discovery |
Simple Mode
| Endpoint | Description |
|----------|-------------|
| / | Server information |
| /sse | SSE endpoint (no auth) |
| /health | Health check |
🔧 Claude Desktop Integration
OAuth Mode
Add to claude_desktop_config.json:
{
"mcpServers": {
"mem": {
"url": "https://mem-mcp-server.<your-subdomain>.workers.dev/sse"
}
}
}
Claude will handle OAuth flow automatically.
Simple Mode
{
"mcpServers": {
"mem": {
"url": "https://mem-mcp-server.<your-subdomain>.workers.dev/sse"
}
}
}
💰 Cloudflare Free Tier
This worker runs comfortably on Cloudflare's free tier:
- ✅ 100,000 requests/day
- ✅ 10ms CPU time per request
- ✅ Unlimited Durable Objects
- ✅ 1GB KV storage
Perfect for personal use and small teams!
🧪 Testing
# Test locally
npm run dev
# Check health endpoint
curl http://localhost:8787/health
# Test root endpoint
curl http://localhost:8787/
📊 Monitoring
View logs and analytics in Cloudflare Dashboard:
# View live logs
wrangler tail
# Check deployment status
wrangler deployments list
🐛 Troubleshooting
"Authentication failed"
- Check that
MEM_API_KEYis set correctly - Verify API key is valid at https://mem.ai
"Durable Object not found"
- Run migrations:
wrangler migrations apply - Redeploy:
npm run deploy
OAuth callback fails
- Verify GitHub OAuth app callback URL matches your worker URL
- Check
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETare set
"KV namespace not found"
- Run
setup.shagain to recreate namespaces - Manually create via Cloudflare Dashboard
🤝 Contributing
Contributions welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
- Mem.ai - Intelligent memory platform
- Mem.ai API Docs
- Model Context Protocol
- Cloudflare Workers
- Python Version - FastMCP Python implementation
💡 Related Projects
- mcp-limitless - Limitless AI MCP server (template for this project)
- mcp-mem.ai - Python FastMCP version
🙏 Acknowledgments
- Built with Cloudflare Workers
- OAuth flow based on mcp-limitless
- Powered by Mem.ai
Built with ❤️ using Cloudflare Workers and TypeScript