[BUG] Chart's kagent-api RemoteMCPServer never discovers tools under server.auth.mode: trusted-proxy (401 on initialize)

Abierto
#3,506 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, helm, kubernetes

Línea de trabajo

Start with go/core/internal/service/tool/mcp.go and go/core/internal/httpserver/auth/proxy_authn.go, then inspect helm/kagent/templates/toolserver-api.yaml and the service account authentication configuration. Trace how control-plane discovery authenticates to the controller's own MCP endpoint and confirm the intended credential and audience. Done means kagent-api is accepted and discovers its tools in trusted-proxy mode without a user token.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

📋 Prerequisites
  • I have searched the existing issues to avoid creating a duplicate
  • By submitting this issue, you agree to follow our Code of Conduct
  • I am using the latest version of the software
  • I have tried to clear cache/cookies or used incognito mode (if ui-related)
  • I can consistently reproduce this issue
🎯 Affected Service(s)

Controller Service

🚦 Impact/Severity

Minor inconvenience

🐛 Bug Description

With config.server.auth.mode: trusted-proxy, the controller can't discover the tools on its own MCP endpoint. The Helm chart creates the RemoteMCPServer kagent-api (helm/kagent/templates/toolserver-api.yaml), and that object stays Accepted=False with reason DiscoveryFailed. The sessions, checkpoints and sandboxes tools never show up, so agents can't use them.

The controller authenticates /mcp with ProxyAuthenticator. That authenticator rejects any request without exactly one Authorization: Bearer <JWT> header (go/core/internal/httpserver/auth/proxy_authn.go:28-36). Discovery comes from the controller itself, through RuntimeMCPClient.connect (go/core/internal/service/tool/mcp.go:124). The only headers it sends are the ones the RemoteMCPServer resolves (server.ResolveHeaders, line 138), and the chart's kagent-api server defines none. connect also explicitly refuses actorJwt for control-plane calls (line 130). So the call reaches the controller with no credential and gets a 401.

Enabling config.server.auth.serviceAccount (the ServiceAccountProvider, audience kagent-invocation) doesn't help, because the discovery client never sends a service account token.

My guess is that this went unnoticed because trusted-proxy was only wired end to end recently (#2968). Before that the controller always ran unsecure, so self-discovery never had to authenticate.

🔄 Steps To Reproduce

Reproduced on 2026-11-03 on a local kind cluster, from a clean checkout of main at e3b80793, using the repository's own dev targets.

  1. Create the cluster and install kagent with Substrate and the dev database. The default auth mode is insecure.
    git clone https://github.com/kagent-dev/kagent && cd kagent
    make create-kind-cluster
    make build kagent-cli-deploy
    
  2. Confirm that kagent-api discovers its tools in the default mode:
    kubectl --context kind-kagent -n kagent get remotemcpserver kagent-api \
      -o jsonpath='{.status.conditions[?(@.type=="Accepted")].message}{"\n"}'
    # Discovered 19 MCP tools
    
  3. Switch the controller to trusted-proxy. grpcReflection is only needed for the optional grpcurl check in step 6.
    helm --kube-context kind-kagent -n kagent upgrade kagent "dist/kagent-$(git describe --tags --always).tgz" \
      --reuse-values \
      --set config.server.auth.mode=trusted-proxy \
      --set config.server.auth.userIdClaim=email \
      --set config.server.grpcReflection=true --wait
    kubectl --context kind-kagent -n kagent rollout status deploy/kagent-controller
    
  4. Force a fresh discovery, so the status doesn't still come from the insecure run. The reconciler watches label changes.
    kubectl --context kind-kagent -n kagent label remotemcpserver kagent-api repro="$(date +%s)" --overwrite
    
  5. Read the status and the controller logs:
    kubectl --context kind-kagent -n kagent get remotemcpserver kagent-api \
      -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}: {.message}{"\n"}{end}'
    # Accepted=False DiscoveryFailed: Failed to connect to MCP server: failed to connect MCP client: calling "initialize": sending "initialize": Unauthorized
    kubectl --context kind-kagent -n kagent logs deploy/kagent-controller | grep -m1 'Reconciler error'
    
  6. (Optional) A signed-in user calling a kagent-api tool through the API fails the same way. Under trusted-proxy the controller reads the token's email claim without verifying the signature, so an unsigned test token works:
    b64() { printf '%s' "$1" | base64 | tr '+/' '-_' | tr -d '='; }
    TOKEN="$(b64 '{"alg":"HS256","typ":"JWT"}').$(b64 '{"email":"[email protected]"}').dGVzdA"
    kubectl --context kind-kagent -n kagent run grpcurl --rm -i --restart=Never --image=fullstorydev/grpcurl:v1.9.3 -- \
      -plaintext -H "authorization: Bearer $TOKEN" \
      -d '{"server":{"ref":{"namespace":"kagent","name":"kagent-api"},"group_kind":"RemoteMCPServer.api.kagent.dev"},"tool_name":"list_agents"}' \
      kagent-controller.kagent.svc.cluster.local:8083 kagent.api.v1.ToolService/CallMCPAppTool
    # ERROR: Code: Internal  Message: internal server error
    
    Setting config.server.auth.mode=insecure again and repeating step 4 brings back Accepted=True with 19 tools.
🤔 Expected Behavior

kagent-api is Accepted=True and its tools are discovered, the same as with mode: insecure. The controller's calls to its own endpoint authenticate with a credential the controller can verify, without a user token and without needing an authenticating proxy in front of the controller.

📱 Actual Behavior

The RemoteMCPServer status:

Accepted=False reason=DiscoveryFailed
message: Failed to connect to MCP server: failed to connect MCP client: calling "initialize": sending "initialize": Unauthorized

The controller logs Reconciler error for RemoteMCPServer kagent/kagent-api, retrying with backoff.

💻 Environment
  • Kubernetes version: 1.37
  • Kubernetes provider: AWS (EKS)
  • Application version: kagent 1.0.0-rc1 (chart and images). The code involved is unchanged on main at 3b28b6b7.
  • Agent Substrate 1.0.0-rc1
  • Also reproduced on kind (Kubernetes 1.35, make create-kind-cluster) from main at e3b80793, with the steps above.
🔍 Additional Context
  • Did this work before? On 1.0.0-alpha17 with the same values, kagent-api discovered its tools. That release never actually applied trusted-proxy (#2968), so it wasn't really a working configuration.
  • Workarounds:
    • mode: insecure makes discovery work, but it gives up per-user identity, so it isn't usable for us.
    • Putting a static Authorization header on the RemoteMCPServer through headersFrom would mean minting a long-lived token. Under trusted-proxy that token would be an unverified user JWT. We don't want either.
  • Possible fix, for maintainers to confirm: for control-plane MCP calls to the controller's own endpoint, RuntimeMCPClient could attach a projected service account token with audience kagent-invocation, and the existing ServiceAccountProvider would verify it. The chart would then enable server.auth.serviceAccount whenever mode is trusted-proxy, or the controller would always trust its own service account. I'm happy to work through the approach here or in #kagent-dev before opening a PR.
📋 Logs
$ kubectl -n kagent get remotemcpserver kagent-api
NAME         PROTOCOL          URL                                                          ACCEPTED
kagent-api   STREAMABLE_HTTP   http://kagent-controller.kagent.svc.cluster.local:8083/mcp   False
🙋 Are you willing to contribute?
  • I am willing to submit a PR to fix this issue
Lenguaje dominante
Go
Estrellas
4.5k
Forks
937
Merge medio
1 d 10 h
PR fusionados (30 d)
150

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de kagent-dev/kagent

Todos los issues de kagent-dev/kagent

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.