t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Chat backend (SDK createQuery) never surfaces tools from slow-connecting plugin MCP servers, despite /mcp reporting them connected

Open orchidautomation opened this issue 3 months ago • 3 comments

Summary

A plugin MCP server with a large tool count (95 tools) shows as connected in the native /mcp status view (run via an interactive claude CLI terminal), but its tools are never callable from a chat session driven by t3code's GUI backend. ToolSearch/the deferred-tool index never contains any of that server's tools for the life of the session, even after the server is confirmed connected. Smaller plugin servers on the same account (2, 13, 32, 47 tools) work fine from the same GUI session.

Environment

  • t3code desktop, chat session backed by apps/server/src/provider/Layers/ClaudeAdapter.ts
  • @anthropic-ai/claude-agent-sdk pinned at 0.3.170 in pnpm-lock.yaml (current upstream is 0.3.224)
  • Comparison terminal: native claude CLI v2.1.224, run interactively, same machine, same ~/.claude.json config

Steps to reproduce

  1. Configure a plugin MCP server with a large tool surface (in my case ~95 tools) alongside several smaller plugin servers (2/13/32/47 tools).
  2. Open the native claude CLI in a terminal and run /mcp. All servers, including the large one, show ✓ connected · N tools. Calling the large server's tools works (e.g. a skill built on top of it resolves and executes correctly).
  3. Open a chat session through the t3code GUI (same config, same working directory) and ask the agent to use a tool from the large server.
  4. The agent can invoke the skill associated with that server (skill instructions load fine), but cannot find or call any of the server's underlying MCP tools — ToolSearch with the exact tool name, exact composite server name (plugin:<name>:<name>), and broad keyword queries all return "No matching deferred tools found."
  5. Meanwhile the GUI's own /mcp panel (apparently rendered by a separate native CLI/terminal path, not the chat backend) correctly shows the server as connected · 95 tools.
  6. The smaller plugin servers' tools are discoverable via ToolSearch in the same chat session throughout.

Root cause (from reading apps/server/src/provider/Layers/ClaudeAdapter.ts)

The chat backend calls the SDK's createQuery() once per session (around the queryOptions construction near line 4093). Per the SDK changelog:

Breaking: MCP servers now connect in the background by default; sessions start immediately and slow servers report status: "pending" in init until ready. Set MCP_CONNECTION_NONBLOCKING=0 to restore the old behavior of waiting up to 5s before the first query, or mark a server alwaysLoad: true to require it in turn 1.

ClaudeAdapter.ts does not set MCP_CONNECTION_NONBLOCKING anywhere in the environment it builds (claudeEnvironment), and does not mark any server alwaysLoad: true. So the SDK's default non-blocking-connect behavior applies: the session's initial tool manifest is built from whatever's ready at that instant, and a slower-to-connect server (plausibly correlated with a much larger tool count / heavier handshake) can miss the window and get excluded.

Compounding this: apps/server/src never calls the SDK's reloadPlugins(), toggleMcpServer(), or mcpServerStatus() methods anywhere (confirmed via repo-wide grep). So even after the slow server finishes connecting, nothing re-syncs the session's tool manifest — the omission is permanent for the life of the session, not just a startup race that resolves itself.

This would explain the exact symptom: the server is genuinely connected (hence /mcp reporting it correctly, and the interactive CLI terminal working fine since it doesn't have this turn-1 manifest freeze), but the chat backend's one-shot createQuery() session never learns about tools that weren't ready in time.

Suggested fix

In apps/server/src/provider/Layers/ClaudeAdapter.ts:

  1. Set MCP_CONNECTION_NONBLOCKING=0 in the claudeEnvironment passed to createQuery() so the SDK waits (up to 5s) for MCP servers to connect before turn 1, and/or mark heavier plugin servers alwaysLoad: true if that's exposed per-server.
  2. After session start, call reloadPlugins() (or equivalent) once outstanding servers finish connecting, so long-running sessions pick up tools from servers that missed the initial window instead of never seeing them.
  3. Consider bumping the pinned @anthropic-ai/claude-agent-sdk dependency from 0.3.170 to latest (0.3.224) — several MCP-related fixes have landed since (e.g. server-added-at-runtime tool injection, background-plugin-install disconnect handling) that may be relevant even if not a direct fix for this issue.

Impact

Any user with a plugin MCP server large/slow enough to miss the initial connect window loses access to that server's tools for the entire chat session in the GUI, with no visible error — the server just silently never gets referenced in tool discovery, while the status UI reports it as healthy. This is confusing to debug because every visible signal (/mcp, skill loading) says the server is fine.

orchidautomation avatar Aug 07 '26 10:08 orchidautomation

[!NOTE] This is an automated response from a bot acting on maria's behalf. This issue has had no activity since 2026-08-07. Is it still relevant on the current version? If so, your version and OS would help.

maria-rcks avatar Oct 09 '26 18:10 maria-rcks

I couldn't reproduce this on current main (71ba6b374c, Claude Agent SDK 0.3.276), and the mechanism described in the issue doesn't show up in my runs.

Setup. A synthetic stdio MCP server with 95 tools that waits 10 s before answering initialize, so it is still pending when the session starts. I loaded it two ways: as a plugin (plugin:slowplug:slowplug) and as a project .mcp.json server.

What I ran

  • T3 Code web dev server, Claude Sonnet 5.5 thread. Turn 1 runs while the server is still connecting. In turn 2 of the same thread, the agent lists mcp__slow__slow_echo and the 94 other tools, calls it, and gets SLOW-ECHO hi.
  • Same app, ToolSearch enabled, the first message asks for the tool. The first ToolSearch returns "No matching deferred tools found. Some MCP servers are still connecting: slow … try searching again". The retry in the same turn returns mcp__slow__slow_echo, and the call works.
  • Agent SDK query() directly, with T3's settings sources, using the plugin variant with ToolSearch on. I ran this against Claude Code 2.1.303 and against 2.1.224, the version you reported. In both, turn 1's init reports the server as pending. Turn 2's init reports it connected with all 95 tools, and ToolSearch("slow_echo") finds the tool and calls it.

So a server that is slow to connect does get picked up later in the same session. Its tools are not left out for the whole session. Note that T3 runs the claude binary from your PATH (or the one set in Settings → Providers → Claude), so that version decides how MCP connections behave, not the SDK version in the lockfile.

To dig further, could you share:

  1. Your T3 Code version and the output of claude --version for the binary T3 uses. Does it still happen on current versions?
  2. Roughly how long the 95-tool server takes to connect. claude mcp list or claude --debug show this.
  3. What ToolSearch says in an affected T3 thread on a second or later message. Does it report the server as "still connecting", or say nothing? Also check whether the server process is running under the T3-launched claude at all (e.g. ps -ef | grep <server command>). A desktop app started outside a shell can have a different PATH or environment than your terminal, and that can stop a plugin server from starting there even though it connects in the terminal.

juliusmarminge avatar Oct 27 '26 02:10 juliusmarminge

Another case of this, with a variant your repro on main didn't cover: a context: fork skill sent as the first message of a new thread. In that case a ToolSearch retry doesn't help.

What happened A project skill (context: fork, agent: general-purpose) depends on the official Atlassian plugin (plugin:atlassian:atlassian, HTTP, https://mcp.atlassian.com/v2/mcp). It runs /backend-gaps <jira link> as the first message of a new Claude thread. The forked subagent never sees any mcp__plugin_atlassian_atlassian__* tools. claude mcp list from the same project directory shows the server ✔ Connected.

Diagnosis

  • In the provider event log, query.open comes at 07:57:34.902Z. The fork's task_started comes at 07:57:34.930Z, 28 ms later, before MCP servers have connected.
  • The subagent's first ToolSearch returns "No matching deferred tools found. Some MCP servers are still connecting: testing_db__remote, dev_db__local, dokploy-mcp, zabbix". atlassian is not on that list.
  • It retries 5 more times over about 40 s, with select: names, +atlassian getJiraIssue and several keyword searches. Every result is empty or comes from other servers. The subagent's tool pool seems to be fixed at spawn and never gains the late server, unlike the main thread's retry behaviour you showed above.
  • The plugin did load in that session: its atlassian:* skills appear in commands_changed.

Repro steps

  1. Enable the official Atlassian plugin for a project and authenticate it. claude mcp list shows it Connected.
  2. Add a project skill with context: fork whose instructions load Atlassian tools through ToolSearch.
  3. In T3 Code, start a new Claude thread in that project and send /<skill> … as the first message. The subagent reports that the Atlassian tools are unavailable.
  4. Control: in a new thread, send hi first, wait for the reply, then run the same skill. The subagent calls getJiraIssue, executeRead and getConfluenceContent without problems. The same skill also works in a terminal claude session, where it ran about 2.5 min after startup.

Workaround (verified) Add MCP_CONNECTION_NONBLOCKING=0 to the Claude provider instance's environment (Settings → Providers). With it, the same first-message run works. The fork again starts 32 ms after query.open, but the subagent gets the Atlassian tools, and no ToolSearch result says "still connecting".

Environment

  • T3 Code desktop 0.1.6 (Linux x64, Arch, kernel 7.2.11), local server 0.1.6
  • Claude Code 2.1.316 (claude on PATH)
  • Custom Claude provider instance with ANTHROPIC_BASE_URL (local gateway), ENABLE_TOOL_SEARCH=true, ENABLE_CLAUDEAI_MCP_SERVERS=false

Given #25959 ("not making the first message wait for MCP servers"), the subagent part may belong upstream in Claude Code. A forked skill or subagent probably shouldn't freeze its tool list before pending MCP servers connect. A narrower T3 option would be to wait for MCP readiness only when the first message is a slash command for a forked skill, or to document the env var for users who depend on forked skills.

Triaged with t3 triage by Claude Code (Claude Opus 5.5).

ahmedisam99 avatar Nov 02 '26 08:11 ahmedisam99