-
|
I've been running the mcp-memory-service for some days now as a Docker container with SQLite backend behind a named Cloudflare tunnel, which worked exceptionally well. When I configure the tunnel in Claude.ai or in the mobile app, I get prompted for the API key to authenticate and the MCP server gets connected, tools get exposed, access is working as expected. Instructing AI some time later to lookup something usually ends with a "tools are not available" and the MCP configuration being shown as "not connected" until I hit the "Connect" button and re-authenticate with the API key. The Cloudflare tunnel is setup with ZeroTrust enabled and for the Anthropic subnets (and my local uplinks) to bypass authentication. I guess I'm just missing something obvious but I can't figure it out for the life of me. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
|
sounds like the token might be expiring and not refreshing automatically. check if your token refresh logic is set up correctly in the mcp-memory-service. if you’ve got the oauth endpoints right but it's still not working, maybe dig into the logs to see if there's any clue when it disconnects. not sure beyond that, might be worth checking with the team on their discord or forums. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @PL-Peter! Great setup — running behind a Cloudflare tunnel with ZeroTrust is a solid approach. The behavior you're seeing (works initially, disconnects after ~1 hour) is a known limitation of our current OAuth implementation: Root CauseAccess tokens expire after 60 minutes (the default Workarounds (for now)Option 1: Increase token lifetimeSet in your This extends tokens to 24 hours (the maximum). Not a permanent fix, but dramatically reduces the re-auth friction. Option 2: Use API key auth instead of OAuthIf your Cloudflare tunnel already handles access control (ZeroTrust with Anthropic subnets bypassing auth), you may not need the OAuth flow at all. You can authenticate with a simple API key: The API key doesn't expire, so the connection stays alive indefinitely. Combined with your ZeroTrust setup, this is arguably more practical for a single-user deployment. Option 3: Bypass the built-in auth entirelySince your Cloudflare tunnel + ZeroTrust already authenticates requests, you could disable the service-level auth and let Cloudflare handle everything. Though I'd still recommend at least the API key as defense-in-depth. The real fix: refresh token supportWe're aware this is a gap. The OAuth registration endpoint already advertises If this is something you'd like to see prioritized, feel free to open a feature request issue — or even a PR! The relevant code is in Hope this helps — let us know how it goes! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the heads-up. I'll also look into the possibilities with Cloudflare (there's the MCP server publishing feature for example). Exposing the MCP enpoint completely unprotected to Cloudflare is maybe not what normal users want to do. It just takes a single wrong decision on the Cloudflare setup to expose the whole operation to the Internet then, which - depending on the information stored - might end in disaster. Thanks for reaching back so quickly. |
Beta Was this translation helpful? Give feedback.
-
|
Security Tip: Cloudflare API Token IP Restrictions Since this discussion touches on Cloudflare tunnel and ZeroTrust configuration — a general best practice worth mentioning: When creating or managing Cloudflare API tokens (e.g., for D1, Vectorize, or tunnel management), you should always consider adding Client IP Address Filtering to your tokens. This limits which IP addresses can use the token, significantly reducing the risk of abuse if a token is accidentally leaked. You can configure this in the Cloudflare dashboard under My Profile → API Tokens → Edit Token → Client IP Address Filtering. A few things to keep in mind:
This won't solve the OAuth token refresh issue discussed above, but it's a good layer of defense-in-depth for anyone running mcp-memory-service with Cloudflare backends. 🔒 |
Beta Was this translation helpful? Give feedback.
-
Final solution (for now)(Named) Cloudflare tunnel
MCP auth/aggregation
mcp-memory-service
ConclusionThe setup involved trial and error, but it wasn't brutal. Not for everyone, but manageable if you know Docker and networking. |
Beta Was this translation helpful? Give feedback.
-
|
Quick follow-up for anyone landing here: |
Beta Was this translation helpful? Give feedback.
Hi @PL-Peter! Great setup — running behind a Cloudflare tunnel with ZeroTrust is a solid approach.
The behavior you're seeing (works initially, disconnects after ~1 hour) is a known limitation of our current OAuth implementation:
Root Cause
Access tokens expire after 60 minutes (the default
MCP_OAUTH_ACCESS_TOKEN_EXPIRE_MINUTES=60), and our OAuth server does not yet issue refresh tokens. When the token expires, Claude.ai has no way to silently renew the session — it can only show "not connected" until you re-authenticate manually.Workarounds (for now)
Option 1: Increase token lifetime
Set in your
.env/ container environment:This extends token…