Connecting Claude.ai to HA MCP Server behind Cloudflare Zero Trust (with OAuth, WAF & Bot Protection) #1674
Calcoon
started this conversation in
Show and tell
Replies: 1 comment 1 reply
|
Thanks for this, a lot of people have been having trouble with connecting to us via Cloudflare. I will see if I can add some of this into our guides or something somewhere. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I've spent a few hours integrating the
ha-mcpserver into Claude.ai using a Cloudflare Tunnel (cloudflared), Cloudflare Zero Trust (Access), and the built-in OAuth (Beta) feature of the Webhook Proxy for HA MCP addon.If you are protecting your Home Assistant instance with Cloudflare Access, WAF Custom Rules (like Geo-Blocks: US), and Cloudflare Bot Protection (such as "Block AI training bots" / AI Labyrinth), Claude.ai will fail to connect with errors like
Authorization with the MCP server failed(withofid_reference codes) and you will see no logs in your Home Assistant addon.Here is the complete guide on how to configure Cloudflare to make it work seamlessly and securely.
My Setup / Prerequisites
cloudflared) protected by Cloudflare Zero Trust (Access) requiring authentication (and optionally WAF rules like Geo-Blocking).The Problem
During the OAuth handshake, Claude's backend servers (originating from the US) need to reach multiple endpoints on your domain, not just the webhook URL.
Additionally, Cloudflare's Bot Management (which serves the "AI Labyrinth" to Python/HTTPX user agents) and any WAF Custom Rules (such as Geo-Blocks) will identify Claude's backend traffic (User-Agents like
Claude-Userorpython-httpx) as unauthorized and block them.Here is the step-by-step solution to bypass security checks only for the required MCP/OAuth endpoints, keeping the rest of your Home Assistant instance fully protected.
Step 1: Configure Cloudflare Access (Zero Trust)
You must allow Claude's servers to bypass your Cloudflare Access authentication screen for all the endpoints used during the handshake.
ha.yourdomain.comto your domain):yourdomain.com/api/webhook/mcp_*yourdomain.com/api/mcp_proxy/*yourdomain.com/tokenyourdomain.com/.well-known/*yourdomain.com/registerStep 2: Configure Cloudflare WAF (Custom Rules)
Even if you bypass Zero Trust, Cloudflare's Firewall (WAF) and Bot Protection (AI Labyrinth / Block AI training bots) will block the US-based requests. We need to create a "Skip" rule to bypass these checks for the MCP paths.
Allow Claude MCP Webhook.Step 3: Connect Claude.ai
https://yourdomain.com/api/webhook/mcp_xxxxxx).Important
Make sure to keep your Webhook URL, OAuth Client ID, and Client Secret safe! Treat them like passwords.
Note: I'm a tech noob, so I'm very open to feedback and suggestions on how to make this setup even more secure or efficient!
Hope this saves someone else a few hours of debugging!
PS: I've wrote this with AI, my english isn't the best - but it's about the message! 😄
All reactions