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

オープン
#3,506 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, helm, kubernetes

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

📋 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
主要言語
Go
スター
4.5k
フォーク
937
平均マージ
1日 10時間
マージ済み PR(30日)
150

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

kagent-dev/kagent のほかの issue

kagent-dev/kagent の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。