fix(mcp): add skip_preflight config option for servers serving HTML on GET

Some MCP servers (e.g. Spring Boot apps with a React SPA) serve their
frontend on any unmatched GET route. The MCP endpoint works perfectly
via POST (JSON-RPC), but a GET to /mcp falls through to the SPA
controller and returns text/html. Hermes's preflight content-type probe
sees HTML instead of application/json or text/event-stream and refuses
to connect.

This adds a per-server  config option that
bypasses the content-type probe, letting the SDK connect directly via
POST where it works fine.

```yaml
mcp_servers:
  stirling-pdf:
    url: http://localhost:8090/mcp
    headers:
      X-API-KEY: <key>
    skip_preflight: true
```

Related: #52460 (OAuth redirect preflight), #51600 (skip probe on mcp add),
#40366 (skip probe on reconnect — already merged).
This commit is contained in:
kaishi00 2026-06-29 17:30:55 -04:00 committed by Teknium
parent 32c1c47eef
commit 549def3a21

View file

@ -2489,7 +2489,7 @@ class MCPServerTask:
# re-probing is a redundant round-trip. Also skip for OAuth servers:
# without a cached token the endpoint returns HTML or 401, which
# would incorrectly block the OAuth flow before it can run.
if config.get("transport") != "sse" and not self._ready.is_set() and self._auth_type != "oauth":
if config.get("transport") != "sse" and not config.get("skip_preflight") and not self._ready.is_set() and self._auth_type != "oauth":
try:
_probe_headers = dict(config.get("headers") or {})
await self._preflight_content_type(