fix(stream): only warn about MCP servers we configured
The unconnected-server warning fired on everything `init` listed, which includes whatever the host's own claude config carries. On the pi that was seven unrelated connectors parked at `pending` / `needs-auth` forever — seven bogus lines on every turn, burying the one line the warning exists to surface. Scope it to the servers passed in `mcp_servers`. Those are the ones we have an expectation about; the rest are the host's business.
This commit is contained in:
+34
-1
@@ -371,7 +371,7 @@ async def test_unconnected_mcp_servers_are_logged(
|
||||
_result(),
|
||||
]
|
||||
)
|
||||
tm = StreamTurnManager(proc) # type: ignore[arg-type]
|
||||
tm = StreamTurnManager(proc, expected_mcp_servers=("telegram", "firefly")) # type: ignore[arg-type]
|
||||
await tm.start()
|
||||
with caplog.at_level(logging.WARNING, logger="claude_code_api.stream"):
|
||||
await _drain(tm)
|
||||
@@ -379,6 +379,39 @@ async def test_unconnected_mcp_servers_are_logged(
|
||||
assert "firefly" not in caplog.text
|
||||
|
||||
|
||||
async def test_unexpected_mcp_servers_are_not_warned_about(caplog: Any) -> None:
|
||||
"""Servers we didn't configure are the host's business, not ours.
|
||||
|
||||
A box where somebody logged in interactively can carry a pile of
|
||||
unrelated connectors parked at ``needs-auth`` forever. Warning about
|
||||
those every turn would bury the one line that matters.
|
||||
"""
|
||||
import logging
|
||||
|
||||
proc = FakeStreamProcess(
|
||||
[
|
||||
{
|
||||
"type": "system",
|
||||
"subtype": "init",
|
||||
"session_id": "s",
|
||||
"mcp_servers": [
|
||||
{"name": "telegram", "status": "connected"},
|
||||
{"name": "claude.ai Gmail", "status": "needs-auth"},
|
||||
{"name": "claude.ai Drive", "status": "pending"},
|
||||
],
|
||||
},
|
||||
_assistant({"type": "text", "text": "x"}),
|
||||
_result(),
|
||||
]
|
||||
)
|
||||
tm = StreamTurnManager(proc, expected_mcp_servers=("telegram",)) # type: ignore[arg-type]
|
||||
await tm.start()
|
||||
with caplog.at_level(logging.WARNING, logger="claude_code_api.stream"):
|
||||
await _drain(tm)
|
||||
assert "claude.ai" not in caplog.text
|
||||
assert "MCP server" not in caplog.text
|
||||
|
||||
|
||||
# --- failures ------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user