Serve MCP at a secret path, so claude.ai can connect

claude.ai's connector dialog takes a name and a URL. Sending a bearer token
needs a "Request headers" beta most accounts lack, and OAuth is not built
yet, so with MCP_PATH_SECRET set the endpoint is also served at
/<secret>/mcp without the bearer token — a trial until OAuth replaces it.

The path is the credential there. It is compared in constant time, and a
wrong one answers 404 like any unknown path. The config refuses fewer than 32
URL-safe characters and never echoes the value, nothing in the server logs
request paths, and the Caddy snippet rewrites the segment before an access
log entry is written (verified against Caddy 2.11). Claude Code and the CLI
keep the bearer token; DEPLOYMENT.md says what the path trades away.

178 tests. Smoke 76/76 and 74/74 on the local instance.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-09-16 20:19:17 +02:00
parent 973b82ebf5
commit ab265b5b0c
15 changed files with 240 additions and 43 deletions

View File

@@ -38,9 +38,13 @@ mcp.example.org {
log {
output file /var/log/caddy/schulcloud-mcp.log
format json
# Request URLs are not secrets here (the token is in a header, not the
# path), but the Authorization header must never be written to disk.
# Caddy does not log headers by default; do not add them.
# With MCP_PATH_SECRET set, a request path *is* a credential: claude.ai
# reaches the server at /<secret>/mcp. The filter rewrites that segment
# before the entry is written. The Authorization header must never reach
# disk either; Caddy does not log headers by default do not add them.
format filter {
request>uri regexp ^/[A-Za-z0-9_-]{32,}/mcp /<secret>/mcp
wrap json
}
}
}