Claude Code `claude -p`: claude.ai connectors (Gmail, Drive...) show "pending" with no tools in the init event since 2.1.311 — set MCP_CONNECTION_NONBLOCKING=0
In headless `claude -p --output-format stream-json --verbose`, Claude Code 2.1.312 lists the account's claude.ai connectors in the `system`/`init` event with status "pending" and contributes none of their tools; a short one-turn run finishes before they connect. 2.1.311 listed no MCP servers at all; 2.1.310 listed them "connected" with their tools. Setting `MCP_CONNECTION_NONBLOCKING=0` (or `false`) in the environment makes 2.1.312 connect them before init (all "connected", tools listed, init at about 2 s). Anything that reads the init event's tool list (a tool allow-list guard, a lockdown check) breaks silently or fails closed without it.
What happened
A wrapper starts claude -p and inspects the first stream-json event (type: "system", subtype: "init") to check which tools the session will have before letting it run. After upgrading Claude Code, the claude.ai connectors (remote MCP servers attached to the claude.ai account, e.g. Gmail, Google Drive, Google Calendar) were no longer usable at init.
Reproduction
claude -p --model <model> --output-format stream-json --verbose \
--setting-sources project --permission-mode dontAsk --tools "" --max-turns 1 \
"Reply with the single word OK." | head -1
Read mcp_servers and tools from that first line:
| CLI version | init mcp_servers (claude.ai connectors) |
tools from them |
|---|---|---|
| 2.1.310 | all connected |
listed (e.g. 89 total) |
| 2.1.311 | none listed at all | 0 |
| 2.1.312 | all pending |
0 (they never connected before the 1-turn answer) |
2.1.312 + MCP_CONNECTION_NONBLOCKING=0 |
all connected |
listed, init at ~2 s |
MCP_CONNECTION_NONBLOCKING=false behaves the same as 0. In the bundled CLI the flag is read as "non-blocking unless explicitly false", so non-blocking is the default.
Fix
Pass MCP_CONNECTION_NONBLOCKING=0 in the environment of the headless calls that need connector tools at init (only those; a call started with --strict-mcp-config and no servers does not need it). Keep any guard strict: with the variable set, re-check the init event as before.
Check run
After setting it for the probe and the real call, the init event listed 5 connectors connected and the guard allowed exactly the intended read tools; the run completed. Without it, the same guard refused with "read tools missing".
Notes
- Re-probe after every CLI update before trusting an init-event tool list.
- A server still
pendingat init lists no tools, so a deny list built from tool names would miss it; deny by server prefix (mcp__<server>) instead.
Conditions
- claude_code
- 2.1.310, 2.1.311, 2.1.312
- os
- Ubuntu 24.04
- mode
- claude -p, --output-format stream-json
- date
- 2026-10-28