Skip to content

Kiro threads cannot use OAuth MCP servers because T3 does not advertise Kiro secretStorage/openExternalUrl #30948

Open

Description

@willgosnold

🤖 Claude Opus 5.5 filing on behalf of willgosnold

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server (Kiro provider: packages/provider-kiro, packages/provider-acp)

Steps to reproduce

  1. Configure a remote OAuth MCP server for Kiro, for example Atlassian in ~/.kiro/settings/mcp.json: "atlassian": { "url": "https://mcp.atlassian.com/v2/mcp" }.
  2. Sign in to it from kiro-cli (/mcp, then re-authenticate). kiro-cli now lists the server as running, with its tools.
  3. Start a Kiro thread in T3 Code on the same machine and ask it to use one of that server's tools.

Expected behavior

The Kiro session started by T3 reuses the stored sign-in, the same way kiro-cli does, and the MCP server's tools load. If there is no token, Kiro can open the browser to sign in.

Actual behavior

The MCP server never loads in Kiro sessions T3 starts. Kiro's mcp.log records Failed to connect … "error":"Unauthorized" at every session start, then shuts down its OAuth callback listener without opening a browser. A fresh kiro-cli session started a minute later connects to the same server without asking for sign-in.

Cause: Kiro's agent stores MCP OAuth credentials through the ACP client, not on its own. In @kiro/agent (dist/server/acp-server.js, kiro-cli 2.37.1), initialize reads:

secretStorage: clientCapabilities._meta.kiro.secretStorage === true,
openExternalUrl: clientCapabilities._meta.kiro.openExternalUrl === true,

If secretStorage is true, the agent loads and saves the MCP OAuth client registration, tokens, PKCE verifier and discovery state through _kiro/secret/get, _kiro/secret/store and _kiro/secret/delete. If openExternalUrl is true, it opens the sign-in page through _kiro/openExternalUrl. Both default to false.

kiro-cli sets both, and answers the secret requests from ~/.kiro/secrets.json (mode 0600). T3 advertises only hooks (packages/provider-kiro/src/server/adapter.ts on main):

clientCapabilitiesMeta: { kiro: { hooks: { enabled: true, v2: true } } },

and doesn't handle _kiro/secret/* or _kiro/openExternalUrl. A Kiro session started by T3 therefore has no way to read the stored token and no way to start a sign-in, so every OAuth MCP server fails with Unauthorized.

The Claude provider doesn't have this problem, because Claude Code keeps MCP OAuth tokens in its own ~/.claude/.credentials.json.

Possible fix: advertise _meta.kiro.secretStorage and _meta.kiro.openExternalUrl in the Kiro adapter, and handle the four requests. Backing them with ~/.kiro/secrets.json, as kiro-cli does, would also reuse existing kiro-cli sign-ins. I haven't built or tested this.

Impact

Major degradation or frequent failure. No OAuth-based MCP server can be used from Kiro threads in T3. Stdio MCP servers and the T3 MCP server are unaffected.

Version or commit

t3 v0.1.7 (WSL runtime). Source references from main @ 9e85538.

Environment

Windows desktop app with WSL2 runtime (Ubuntu 22.04.5, kernel 5.15.167.4-microsoft-standard-WSL2). kiro-cli 2.37.1, started by T3 as kiro-cli acp --agent-engine=v3 --auth-method=cli. Model claude-opus-5.5.

Logs or stack traces

# Kiro agent log for each process: client name and whether "Client supports ACP secret storage" was logged
20261104T152250901 kiro-cli  secretStorage=1   atlassian: Failed to connect -> user re-auth -> mcp.connect.ok, listTools.ok
20261104T153626864 kiro-cli  secretStorage=1   atlassian: mcp.connect.ok, listTools.ok (no sign-in needed)
20261104T152429953 t3-code   secretStorage=0   atlassian: Failed to connect (Unauthorized)
20261104T153547351 t3-code   secretStorage=0   atlassian: Failed to connect (Unauthorized)
20261104T154040542 t3-code   secretStorage=0   atlassian: Failed to connect (Unauthorized)

# mcp.log, T3-started Kiro session
[MCP OAuth] Starting redirect server in case the server requires OAuth...
[MCP OAuth] Redirect server started on http://localhost:41509/oauth/callback
mcp.connect.error  serverName=atlassian
Failed to connect  serverName=atlassian  error=Unauthorized
[MCP OAuth] Stopping redirect server

Workaround

Use the Claude provider for threads that need OAuth MCP servers, or use kiro-cli directly.

Activity

  1. willgosnold commented on Nov 4, 2026

    @willgosnold
    Author

    Follow-up from a t3 triage session on the same machine (T3 Code 0.1.7, desktop on Windows with WSL2 runtime, kiro-cli 2.37.1).

    The proposed fix works. I started kiro-cli acp --agent-engine=v3 --auth-method=cli from a minimal ACP client and changed only two things:

    • initialize sends clientCapabilities: { _meta: { kiro: { secretStorage: true } } }
    • the client answers _kiro/secret/get from ~/.kiro/secrets.json

    The agent asked for kiro.mcp.<hash>.tokens, got the token kiro-cli had stored, and the Atlassian server connected:

    mcp/status atlassian connecting
    secret/get tokens hit
    mcp/status atlassian connected
    mcp.connect.ok  serverName=atlassian
    mcp.listTools.ok  serverName=atlassian
    

    Without the capability, the same command fails with Unauthorized on every start and registers a new OAuth client each time. The storage key is sha256(lowercased url + "|" + sorted headers), so a T3 handler backed by ~/.kiro/secrets.json would reuse existing kiro-cli sign-ins as they are.

    A second gap: T3 drops Kiro's auth-needed signal. When no token is available, the agent sends:

    • _kiro/mcp/status with { status: "failed", authType: "oauth", failedAuthorization: true, authorizationUrl, errorMessage }
    • session/update → session_info_update with _meta.kiro.displayError (errorType: "mcp_connection_error", "MCP server "atlassian" requires authorization…")

    T3 shows neither, so the thread fails silently. The agent also stops its OAuth redirect server right after the failure, so the authorizationUrl can't complete on its own. A full fix probably needs secretStorage (reuse stored tokens), openExternalUrl (start sign-in), and showing _kiro/mcp/status failures in the thread.

    No duplicates found. Not fixed on main (adapter.ts still sends only hooks in clientCapabilitiesMeta).

    Produced by Kiro (claude-opus-5.5) via the T3 Code triage playbook.

  2. changed the title [-][Bug]: Kiro threads cannot use OAuth MCP servers because T3 does not advertise Kiro secretStorage/openExternalUrl[/-] [+]Kiro threads cannot use OAuth MCP servers because T3 does not advertise Kiro secretStorage/openExternalUrl[/+] on Nov 4, 2026
  3. ChristopherPHolder commented on Nov 12, 2026

    @ChristopherPHolder

    Workaround until #31019 is merged: a stdio shim between T3 Code and kiro-cli.

    Posting this in case someone wants to try it. It applies the fix described above from outside T3 Code, so OAuth MCP servers load in Kiro threads today.

    The shim is a small Node script that T3 Code starts instead of kiro-cli. It starts the real kiro-cli and relays the ACP traffic in both directions, with two changes:

    • On initialize, it adds secretStorage: true and openExternalUrl: true to clientCapabilities._meta.kiro.
    • It answers _kiro/secret/get, _kiro/secret/store, _kiro/secret/delete and _kiro/openExternalUrl itself, using Kiro's own secrets file, so existing kiro-cli sign-ins are reused. T3 Code never sees these requests.

    Everything else passes through unchanged. Tested on macOS with Kiro CLI 3.1.0. It should also work on Linux. It does not work on Windows as is.

    Requirements

    • macOS or Linux
    • Node.js, on the PATH that T3 Code gives to the processes it starts
    • Kiro CLI, installed and logged in (kiro-cli login)
    • T3 Code with the native Kiro provider (not Kiro added from the ACP registry)

    Setup

    1. Create the script. Save the code from The script at the bottom of this file
      as ~/.local/bin/kiro-acp-t3-shim.mjs, then make it executable:

      mkdir -p ~/.local/bin
      # save the script as ~/.local/bin/kiro-acp-t3-shim.mjs, then:
      chmod 755 ~/.local/bin/kiro-acp-t3-shim.mjs
    2. Point it at the real Kiro CLI. Run which kiro-cli. The script assumes
      /opt/homebrew/bin/kiro-cli. If yours is somewhere else, change the default path on the line
      that starts with const REAL_BIN =. This must be the real kiro-cli, never the shim itself.

    3. Check that it passes through. This should print the same version as kiro-cli --version:

      ~/.local/bin/kiro-acp-t3-shim.mjs --version
    4. Switch T3 Code to it.

      1. Open Settings → Providers → Kiro and enable it.
      2. Set Binary path to the full path of the script, for example
        /Users/<you>/.local/bin/kiro-acp-t3-shim.mjs. Do not use ~.
      3. Refresh the provider.
      4. If you have a Kiro entry that came from the ACP registry, disable it so threads do not
        start on the old one.
    5. Start a new Kiro thread. MCP servers you already signed in to from the Kiro CLI or IDE load
      from the stored tokens. For a server that needs a new sign-in, the sign-in page opens in your
      default browser.

    Check that it works

    • The OAuth MCP server's tools appear in the thread.
    • The newest ~/.kiro/logs/*/kiro.log contains both of these lines:
      • Client supports ACP secret storage
      • Client supports ACP openExternalUrl

    If something goes wrong

    Symptom Fix
    The provider fails to start with env: node: No such file or directory T3 Code cannot find node. Replace the first line of the script with the full path to Node, for example #!/opt/homebrew/bin/node (find it with which node).
    failed to start /opt/homebrew/bin/kiro-cli Step 2 was missed.
    You want to see what the shim is doing Add KIRO_SHIM_LOG=/some/path/shim.log to the Kiro provider's environment variables in T3 Code. The log holds method names, secret keys and server names, never token values. It is off by default.

    To undo everything, clear the Binary path (or set it back to kiro-cli) and refresh the
    provider.

    Good to know

    • The shim reads and writes Kiro's own secrets file: $KIRO_HOME/secrets.json, or
      ~/.kiro/secrets.json when KIRO_HOME is not set. That is the file the Kiro CLI uses, so
      sign-ins are shared between the two. The shim keeps it readable by you only (mode 0600).
    • It opens only http: and https: URLs, and only when Kiro asks for a sign-in.
    • The browser opens on the machine that runs the T3 Code server, so this fits a local setup, not
      a remote server.
    • It is a stopgap. T3 Code pull request
      #31019 adds stored-token support to T3 Code
      itself. Once that ships, you need the shim only for signing in from inside T3 Code.

    The script

    #!/usr/bin/env node
    // Stdio proxy between T3 Code and `kiro-cli acp`.
    //
    // Kiro's V3 engine expects the ACP client to store MCP OAuth credentials. T3 does
    // not declare or implement that, so OAuth MCP servers get dropped. This proxy
    // declares `secretStorage` and `openExternalUrl` on `initialize` and answers the
    // four `_kiro/*` requests itself, backed by the Kiro CLI's own secrets file.
    //
    // Env:
    //   KIRO_REAL_BIN            real kiro-cli (default /opt/homebrew/bin/kiro-cli)
    //   KIRO_SHIM_SECRETS_FILE   secrets file override (default $KIRO_HOME/secrets.json, else ~/.kiro/secrets.json)
    //   KIRO_SHIM_LOG            debug log path (off by default; method names and keys only)
    //   KIRO_SHIM_OPEN_CMD       URL opener override (default: open / xdg-open)
    
    import { execFile, spawn } from "node:child_process";
    import { randomBytes } from "node:crypto";
    import fs from "node:fs";
    import os from "node:os";
    import path from "node:path";
    
    const REAL_BIN = process.env.KIRO_REAL_BIN || "/opt/homebrew/bin/kiro-cli";
    const LOG_PATH = process.env.KIRO_SHIM_LOG || "";
    const SECRETS_FILE =
      process.env.KIRO_SHIM_SECRETS_FILE ||
      path.join(process.env.KIRO_HOME || path.join(os.homedir(), ".kiro"), "secrets.json");
    const OPEN_CMD =
      process.env.KIRO_SHIM_OPEN_CMD || (process.platform === "darwin" ? "open" : "xdg-open");
    
    const HANDLED = new Set([
      "_kiro/secret/get",
      "_kiro/secret/store",
      "_kiro/secret/delete",
      "_kiro/openExternalUrl",
    ]);
    
    function log(message) {
      if (!LOG_PATH) return;
      try {
        fs.appendFileSync(LOG_PATH, `${new Date().toISOString()} [${process.pid}] ${message}\n`, {
          mode: 0o600,
        });
      } catch {
        // Logging must never break the proxy.
      }
    }
    
    // --- secrets file -----------------------------------------------------------
    
    function readSecrets() {
      try {
        const parsed = JSON.parse(fs.readFileSync(SECRETS_FILE, "utf8"));
        return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
      } catch {
        return {};
      }
    }
    
    function writeSecrets(secrets) {
      const dir = path.dirname(SECRETS_FILE);
      fs.mkdirSync(dir, { recursive: true });
      const tmp = path.join(dir, `.secrets.json.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
      try {
        fs.writeFileSync(tmp, JSON.stringify(secrets, null, 2), { mode: 0o600 });
        fs.chmodSync(tmp, 0o600);
        fs.renameSync(tmp, SECRETS_FILE);
      } catch (error) {
        fs.rmSync(tmp, { force: true });
        throw error;
      }
    }
    
    function requireString(params, field) {
      const value = params?.[field];
      if (typeof value !== "string") throw new Error(`Invalid params: "${field}" must be a string`);
      return value;
    }
    
    // --- request handlers (agent -> client) -------------------------------------
    
    async function handle(method, params) {
      switch (method) {
        case "_kiro/secret/get": {
          const key = requireString(params, "key");
          const secrets = readSecrets();
          const value = Object.hasOwn(secrets, key) ? secrets[key] : null;
          log(`${method} key=${key} found=${typeof value === "string"}`);
          return { value: typeof value === "string" ? value : null };
        }
        case "_kiro/secret/store": {
          const key = requireString(params, "key");
          const value = requireString(params, "value");
          const secrets = readSecrets();
          secrets[key] = value;
          writeSecrets(secrets);
          log(`${method} key=${key}`);
          return { success: true };
        }
        case "_kiro/secret/delete": {
          const key = requireString(params, "key");
          const secrets = readSecrets();
          delete secrets[key];
          writeSecrets(secrets);
          log(`${method} key=${key}`);
          return { success: true };
        }
        case "_kiro/openExternalUrl": {
          const raw = requireString(params, "url");
          let protocol;
          try {
            protocol = new URL(raw).protocol;
          } catch {
            throw new Error("Invalid URL");
          }
          if (protocol !== "http:" && protocol !== "https:") {
            throw new Error(`Refusing to open URL with protocol ${protocol}`);
          }
          // The URL carries OAuth state, so log the server name only.
          log(`${method} server=${typeof params.serverName === "string" ? params.serverName : "?"}`);
          await new Promise((resolve, reject) => {
            execFile(OPEN_CMD, [raw], (error) =>
              error ? reject(new Error(`Failed to launch ${OPEN_CMD}`)) : resolve(),
            );
          });
          return { success: true };
        }
        default:
          throw new Error(`Unhandled method ${method}`);
      }
    }
    
    // --- line plumbing ----------------------------------------------------------
    
    const NEWLINE = 0x0a;
    
    // Splits a byte stream on "\n" with no length limit and hands each raw line
    // (without its newline) to `onLine`. Lines are forwarded as bytes, so anything
    // we do not rewrite passes through byte for byte.
    function makeLineSplitter(onLine) {
      let pending = [];
      return {
        push(chunk) {
          let start = 0;
          let index;
          while ((index = chunk.indexOf(NEWLINE, start)) !== -1) {
            const tail = chunk.subarray(start, index);
            const line = pending.length > 0 ? Buffer.concat([...pending, tail]) : tail;
            pending = [];
            onLine(line, true);
            start = index + 1;
          }
          if (start < chunk.length) pending.push(chunk.subarray(start));
        },
        flush() {
          if (pending.length === 0) return;
          const line = Buffer.concat(pending);
          pending = [];
          onLine(line, false);
        },
      };
    }
    
    function tryParse(line) {
      try {
        const parsed = JSON.parse(line.toString("utf8"));
        return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
      } catch {
        return null;
      }
    }
    
    function asObject(value) {
      return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
    }
    
    const INITIALIZE_MARKER = Buffer.from('"initialize"');
    const KIRO_MARKER = Buffer.from('"_kiro/');
    const NEWLINE_BUFFER = Buffer.from("\n");
    
    const child = spawn(REAL_BIN, process.argv.slice(2), {
      stdio: ["pipe", "pipe", "inherit"],
    });
    log(`spawned ${REAL_BIN} pid=${child.pid} secrets=${SECRETS_FILE}`);
    
    function writeWithBackpressure(destination, source, data) {
      if (destination.destroyed || destination.writableEnded) return;
      if (!destination.write(data)) {
        source.pause();
        destination.once("drain", () => source.resume());
      }
    }
    
    function emit(destination, source, line, hadNewline) {
      writeWithBackpressure(
        destination,
        source,
        hadNewline ? Buffer.concat([line, NEWLINE_BUFFER]) : line,
      );
    }
    
    // T3 -> kiro
    const fromClient = makeLineSplitter((line, hadNewline) => {
      if (line.includes(INITIALIZE_MARKER)) {
        const message = tryParse(line);
        if (message && message.method === "initialize" && message.id !== undefined) {
          const params = asObject(message.params);
          const capabilities = asObject(params.clientCapabilities);
          const meta = asObject(capabilities._meta);
          message.params = {
            ...params,
            clientCapabilities: {
              ...capabilities,
              _meta: {
                ...meta,
                kiro: { ...asObject(meta.kiro), secretStorage: true, openExternalUrl: true },
              },
            },
          };
          log("initialize: declared secretStorage + openExternalUrl");
          emit(child.stdin, process.stdin, Buffer.from(JSON.stringify(message)), true);
          return;
        }
      }
      emit(child.stdin, process.stdin, line, hadNewline);
    });
    
    // kiro -> T3
    const fromAgent = makeLineSplitter((line, hadNewline) => {
      if (line.includes(KIRO_MARKER)) {
        const message = tryParse(line);
        if (
          message &&
          typeof message.method === "string" &&
          message.id !== undefined &&
          message.id !== null &&
          HANDLED.has(message.method)
        ) {
          const { id, method } = message;
          Promise.resolve()
            .then(() => handle(method, message.params))
            .then(
              (result) => ({ jsonrpc: "2.0", id, result }),
              (error) => {
                // Handler errors are built here and never contain secret values.
                const text = error instanceof Error ? error.message : "Internal error";
                log(`${method} failed: ${text}`);
                return { jsonrpc: "2.0", id, error: { code: -32603, message: text } };
              },
            )
            .then((response) => {
              emit(child.stdin, child.stdout, Buffer.from(JSON.stringify(response)), true);
            });
          return;
        }
      }
      emit(process.stdout, child.stdout, line, hadNewline);
    });
    
    process.stdin.on("data", (chunk) => fromClient.push(chunk));
    process.stdin.on("end", () => {
      fromClient.flush();
      log("client closed stdin");
      child.stdin.end();
    });
    process.stdin.on("error", () => child.stdin.end());
    
    child.stdout.on("data", (chunk) => fromAgent.push(chunk));
    child.stdout.on("end", () => fromAgent.flush());
    
    child.stdin.on("error", () => {});
    process.stdout.on("error", () => {});
    
    for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
      process.on(signal, () => {
        log(`forwarding ${signal}`);
        child.kill(signal);
      });
    }
    
    child.on("error", (error) => {
      log(`spawn failed: ${error.message}`);
      process.stderr.write(`kiro-acp-t3-shim: failed to start ${REAL_BIN}: ${error.message}\n`);
      process.exit(127);
    });
    
    child.on("close", (code, signal) => {
      log(`child closed code=${code} signal=${signal}`);
      process.stdin.destroy();
      const exitCode = code ?? 128 + (os.constants.signals[signal] ?? 1);
      // Let buffered stdout drain before exiting.
      process.stdout.write("", () => process.exit(exitCode));
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions