Skip to main content
Glama

How Persistent Memory Supercharges Your MCP Server (with Cloudflare)

Written by on .

mcp
cloudflare

  1. Persistent Memory in MCP with Cloudflare Durable Objects
    1. Why Use Persistent MCP Servers?
      1. Key Tool Examples
        1. Set Favorite Genre
          1. Log a Book Read
            1. Recommend a Book
            2. Built-in Scaling with Cloudflare
              1. Wrap Up
                1. Acknowledgements
                  1. References

                    Persistent Memory in MCP with Cloudflare Durable Objects

                    If you've ever switched MCP clients and lost your conversation history — you know the pain. The fix? Give your MCP server memory.

                    In this article, we’ll show you how to deploy remote MCP servers with built-in user context using Cloudflare Durable Objects. You’ll also see how to build tools that remember preferences, log activity, and deliver personalized responses — all without extra backend work.1

                    Why Use Persistent MCP Servers?

                    Cloudflare’s Durable Objects let you:

                    • Create per-user memory
                    • Avoid external databases
                    • Keep logic, state, and tools in one place
                    • Scale instantly across the globe

                    With just a few lines of code, your MCP server can start remembering user preferences, tool interactions, and context — even across multiple clients.1

                    Key Tool Examples

                    1. Set Favorite Genre

                    export const setGenre = tool(async ({ genre }, context) => { await context.state.storage.put("genre", genre); return `Saved \"${genre}\" as your favorite genre!`; });

                    Input:

                    { "tool": "setGenre", "args": { "genre": "Mystery" } }

                    Output:

                    { "output": "Saved \"Mystery\" as your favorite genre!" }

                    2. Log a Book Read

                    export const logBook = tool(async ({ title }, context) => { let books = await context.state.storage.get("books") || []; books.push(title); await context.state.storage.put("books", books); return `Logged \"${title}\" as read.`; });

                    Input:

                    { "tool": "logBook", "args": { "title": "The Silent Companions" } }

                    Output:

                    { "output": "Logged \"The Silent Companions\" as read." }

                    3. Recommend a Book

                    export const getRecommendation = tool(async (_, context) => { const genre = await context.state.storage.get("genre") || "fiction"; const books = await context.state.storage.get("books") || []; const prompt = `Recommend a ${genre} book, not among: ${books.join(", ")}`; return context.run(prompt); });

                    Input:

                    { "tool": "getRecommendation" }

                    Output:

                    { "output": "Try 'The Secret History' by Donna Tartt." }

                    Built-in Scaling with Cloudflare

                    Deploying MCP on Cloudflare means:

                    • Global edge performance
                    • Auto-scaling durable storage per user
                    • Built-in support for http-stream and SSE transport
                    • No custom auth or session handling required

                    To deploy, refer to Cloudflare’s official Pages guide.2

                    Wrap Up

                    With Cloudflare, your MCP server becomes your backend — persistent, scalable, and contextual by default. Add memory, deploy tools, and personalize every interaction across AI agents or clients.

                    Acknowledgements

                    This guide is based on Dina Kozlov's enlightening talk at the MCP Summit – "Building and Deploying Remote MCP Servers".1 Her practical walkthrough of Cloudflare Durable Objects and their integration with MCP tooling laid the foundation for this article’s use cases.

                    Special thanks to the Cloudflare team and the broader MCP ecosystem for pioneering scalable, memory-persistent infrastructure that makes building intelligent and context-aware agents significantly easier.

                    References

                    Footnotes

                    1. MCP Summit Talk by Dina Kozlov – "Building and Deploying Remote MCP Servers" 2 3

                    2. Cloudflare Pages Documentation – Get Started

                    Written by Om-Shree-0709 (@Om-Shree-0709)