nginx: match the MCP location with or without a trailing slash

claude.ai strips the trailing slash from the connector URL, so a
location of /mcp/<secret>/ missed and fell to the 301 catch-all. Use a
regex (^/mcp/<secret>/?(.*)$) that matches both and normalises onto the
FastMCP root.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Flux
2026-06-23 21:50:31 +01:00
co-authored by Claude Opus 4.8
parent 77b42a8758
commit 25a73fe416
+5 -4
View File
@@ -33,10 +33,11 @@ server {
} }
# --- MCP server (claude.ai cooking-mode connector) --- # --- MCP server (claude.ai cooking-mode connector) ---
# Trailing slashes on both sides strip the secret prefix, so the FastMCP # Regex so it matches with OR without a trailing slash — claude.ai stores
# service (serving at "/") sees clean paths. # the connector URL without one. Whatever follows the secret is normalised
location /mcp/REPLACE_WITH_LONG_SECRET/ { # onto the FastMCP root (the service serves at "/").
proxy_pass http://127.0.0.1:8765/; location ~ ^/mcp/REPLACE_WITH_LONG_SECRET/?(?<mcp_rest>.*)$ {
proxy_pass http://127.0.0.1:8765/$mcp_rest$is_args$args;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;