Labsco
jmbish04 logo

Cloudflare MCP Server

from jmbish04

Deploy a remote, authentication-free MCP server on Cloudflare Workers.

๐Ÿ”ฅ๐Ÿ”ฅAccount requiredAdvanced setup
๐Ÿค Show your support - give a โญ๏ธ if you liked the content

MCP Memory

MCP Memory is a MCP Server that gives MCP Clients (Cursor, Claude, Windsurf and more) the ability to remember information about users (preferences, behaviors) across conversations. It uses vector search technology to find relevant memories based on meaning, not just keywords. It's built with Cloudflare Workers, D1, Vectorize (RAG), Durable Objects, Workers AI and Agents.

๐Ÿ“บ Video

Watch the video

๐Ÿš€ Try It Out

https://memory.mcpgenerator.com/

๐Ÿง  How It Works

MCP Memory Architecture

  1. Storing Memories:

    • Your text is processed by Cloudflare Workers AI using the open-source @cf/baai/bge-m3 model to generate embeddings
    • The text and its vector embedding are stored in two places:
      • Cloudflare Vectorize: Stores the vector embeddings for similarity search
      • Cloudflare D1: Stores the original text and metadata for persistence
    • A Durable Object (MyMCP) manages the state and ensures consistency
    • The Agents framework handles the MCP protocol communication
  2. Retrieving Memories:

    • Your query is converted to a vector using Workers AI with the same @cf/baai/bge-m3 model
    • Vectorize performs similarity search to find relevant memories
    • Results are ranked by similarity score
    • The D1 database provides the original text for matched vectors
    • The Durable Object coordinates the retrieval process

This architecture enables:

  • Fast vector similarity search through Vectorize
  • Persistent storage with D1
  • Stateful operations via Durable Objects
  • Standardized AI interactions through Workers AI
  • Protocol compliance via the Agents framework

The system finds conceptually related information even when the exact words don't match.

๐Ÿ”’ Security

MCP Memory implements several security measures to protect user data:

  • Each user's memories are stored in isolated namespaces within Vectorize for data separation
  • Built-in rate limiting prevents abuse (100 req/min - you can change it in wrangler.jsonc)
  • Authentication is based on userId only
    • While this is sufficient for basic protection due to rate limiting
    • Additional authentication layers (like API keys or OAuth) can be easily added if needed
  • All data is stored in Cloudflare's secure infrastructure
  • All communications are secured with industry-standard TLS encryption (automatically provided by Cloudflare's SSL/TLS certification)

๐Ÿ’ฐ Cost Information - FREE for Most Users

MCP Memory is free to use for normal usage levels:

  • Free tier allows 1,000 memories with ~28,000 queries per month
  • Uses Cloudflare's free quota for Workers, Vectorize, Worker AI and D1 database

For more details on Cloudflare pricing, see:

Project Structure

cloudflare-browser-rendering/
โ”œโ”€โ”€ examples/                   # Example implementations and utilities
โ”‚   โ”œโ”€โ”€ basic-worker-example.js # Basic Worker with Browser Rendering
โ”‚   โ”œโ”€โ”€ minimal-worker-example.js # Minimal implementation
โ”‚   โ”œโ”€โ”€ debugging-tools/        # Tools for debugging
โ”‚   โ”‚   โ””โ”€โ”€ debug-test.js       # Debug test utility
โ”‚   โ””โ”€โ”€ testing/                # Testing utilities
โ”‚       โ””โ”€โ”€ content-test.js     # Content testing utility
โ”œโ”€โ”€ experiments/                # Educational experiments
โ”‚   โ”œโ”€โ”€ basic-rest-api/         # REST API tests
โ”‚   โ”œโ”€โ”€ puppeteer-binding/      # Workers Binding API tests
โ”‚   โ””โ”€โ”€ content-extraction/     # Content processing tests
โ”œโ”€โ”€ src/                        # MCP server source code
โ”‚   โ”œโ”€โ”€ index.ts                # Main entry point
โ”‚   โ”œโ”€โ”€ server.ts               # MCP server implementation
โ”‚   โ”œโ”€โ”€ browser-client.ts       # Browser Rendering client
โ”‚   โ””โ”€โ”€ content-processor.ts    # Content processing utilities
โ”œโ”€โ”€ puppeteer-worker.js         # Cloudflare Worker with Browser Rendering binding
โ”œโ”€โ”€ test-puppeteer.js           # Tests for the main implementation
โ”œโ”€โ”€ wrangler.toml               # Wrangler configuration for the Worker
โ”œโ”€โ”€ cline_mcp_settings.json.example # Example MCP settings for Cline
โ”œโ”€โ”€ .gitignore                  # Git ignore file
โ””โ”€โ”€ LICENSE                     # MIT License

MCP Server

The MCP server provides tools for fetching and processing web content using Cloudflare Browser Rendering for use as context in LLMs.

Building the MCP Server

npm run build

Running the MCP Server

npm start

Or, for development:

npm run dev

MCP Server Tools

The MCP server provides the following tools:

  1. fetch_page - Fetches and processes a web page for LLM context
  2. search_documentation - Searches Cloudflare documentation and returns relevant content
  3. extract_structured_content - Extracts structured content from a web page using CSS selectors
  4. summarize_content - Summarizes web content for more concise LLM context

Integrating with Cline

To integrate the MCP server with Cline, copy the cline_mcp_settings.json.example file to the appropriate location:

cp cline_mcp_settings.json.example ~/Library/Application\ Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

Or add the configuration to your existing cline_mcp_settings.json file.

Key Learnings

  1. Cloudflare Browser Rendering requires the @cloudflare/puppeteer package to interact with the browser binding.
  2. The correct pattern for using the browser binding is:
    import puppeteer from '@cloudflare/puppeteer';
    
    // Then in your handler:
    const browser = await puppeteer.launch(env.browser);
    const page = await browser.newPage();
  3. When deploying a Worker that uses the Browser Rendering binding, you need to enable the nodejs_compat compatibility flag.
  4. Always close the browser after use to avoid resource leaks.

cloudflare-api-mcp

This is a lightweight Model Control Protocol (MCP) server bootstrapped with create-mcp and deployed on Cloudflare Workers.

This MCP server allows agents (such as Cursor) to interface with the Cloudflare REST API.

It's still under development, I will be adding more tools as I find myself needing them.

Available Tools

See src/index.ts for the current list of tools. Every method in the class is an MCP tool.

Local Development

Add your Cloudflare API key and email to the .dev.vars file:

CLOUDFLARE_API_KEY=<your-cloudflare-api-key>
CLOUDFLARE_API_EMAIL=<your-cloudflare-api-email>

How to Create New MCP Tools

To create new MCP tools, add methods to the MyWorker class in src/index.ts. Each function will automatically become an MCP tool that your agent can use.

Example:

/**
 * Create a new DNS record in a zone.
 * @param zoneId {string} The ID of the zone to create the record in.
 * @param name {string} The name of the DNS record.
 * @param content {string} The content of the DNS record.
 * @param type {string} The type of DNS record (CNAME, A, TXT, or MX).
 * @param comment {string} Optional comment for the DNS record.
 * @param proxied {boolean} Optional whether to proxy the record through Cloudflare.
 * @return {object} The created DNS record.
 */
createDNSRecord(zoneId: string, name: string, content: string, type: string, comment?: string, proxied?: boolean) {
    // Implementation
}

The JSDoc comments are important:

  • First line becomes the tool's description
  • @param tags define the tool's parameters with types and descriptions
  • @return tag specifies the return value and type

Learn More