fix: unblock the MCP session, and authenticate to the AI gateway with OIDC

Two things, both discovered by instrumenting the failure rather than trusting
the message it printed.

The MCP session never failed on protocol. macOS resolves any `.local` name
through mDNS first and takes a flat ~5.0s doing it, which sits exactly on
httpx's 5s default connect timeout; fastmcp reported the resulting
ConnectTimeout only as "Failed to initialize server session". Earlier tests
used `curl --resolve`, which bypasses DNS entirely and made it look like DNS
had been eliminated. Settings.http_timeout (60s) now covers the shared client,
the client fastmcp builds, and MCPToolset's init_timeout. list-products,
get-product and create-product now enumerate over the real gateway.

Inference used a static "unused" api_key against a gateway whose
openid-connect plugin requires audience ["llm-proxy"]. The model call now
carries a token exchanged for llm-proxy-audience, so it is attributable to the
same (agent, end user) pair as every tool call.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Stéphane Tailland
2026-08-28 11:01:18 +02:00
parent 4fd6e21a40
commit 0bc06512f5
6 changed files with 59 additions and 6 deletions
+13 -1
View File
@@ -40,12 +40,24 @@ class Settings(BaseSettings):
# protocol, which is why the OpenAI provider is used against it.
llm_base_url: str = "https://llm-dev.sttlab.local/llm/v1"
llm_model: str = "google/gemini-3.7-flash"
llm_api_key: str = Field("unused", description="Kong authenticates the caller, not this key")
# The gateway's openid-connect plugin requires this audience. The bearer it
# validates is an exchanged token, not a static key, so inference carries
# the same `azp`/`sub` pair as every tool call and lands in the same audit
# trail. The key-auth path alongside it exists only for callers that cannot
# do OIDC outbound (LibreChat) and proves nothing about the end user.
llm_scope: str = "llm-proxy-audience"
# --- transport ----------------------------------------------------------
# The lab uses a private CA (sttlab-local-ca). Point this at the CA bundle
# rather than disabling verification.
ca_bundle: str | None = None
# Generous on purpose, and it is not paranoia. macOS resolves any `.local`
# name through mDNS before falling back to /etc/hosts, and that costs a flat
# ~5s per hostname — right on httpx's 5s default connect timeout. The result
# is an intermittent ConnectTimeout that fastmcp reports only as
# "Failed to initialize server session", with the real cause swallowed. In
# the cluster the names resolve instantly and this timeout never binds.
http_timeout: float = 60.0
host: str = "0.0.0.0"
port: int = 8080
# Advertised in the Agent Card, so it must be the URL other agents reach,