Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
fix(mcp-watchdog): a 401 with no credential to present is not needs_bootstrap (#945)
Aurora Capital357740264898
diff --git a/claude-ops/bin/ops-doctor b/claude-ops/bin/ops-doctorindex 0e8b903a..94924505 100755--- a/claude-ops/bin/ops-doctor+++ b/claude-ops/bin/ops-doctor@@ -524,6 +524,9 @@ try:bad = []for name, info in s.items():if info.get('state') == 'healthy': continue+ # no_probe_credential means the watchdog had no token to present, not+ # that the server is down — sessions use it fine. Never warn on it.+ if info.get('state') == 'no_probe_credential': continueprobed = info.get('probed_at', '')if not probed: continuefrom datetime import datetimediff --git a/claude-ops/scripts/ops-mcp-watchdog.py b/claude-ops/scripts/ops-mcp-watchdog.pyindex be6f3eb1..71845b42 100755--- a/claude-ops/scripts/ops-mcp-watchdog.py+++ b/claude-ops/scripts/ops-mcp-watchdog.py@@ -6,7 +6,14 @@ Every cron tick:using the cached Bearer (or API key). Classify:healthy — 200 OK, MCP server responded with init resulttoken_expired — 401, refresh_token exists → recoverable via OAuth refresh- needs_bootstrap— 401, no refresh_token → user must do interactive consent+ needs_bootstrap— 401 after presenting a credential that was rejected →+ user must do interactive consent+ no_probe_credential+ — 401 with no credential to present. NOT a fault: Claude+ Code keeps OAuth tokens for natively-authenticated HTTP+ MCPs in memory, unreachable to any external prober, so+ those servers answer every session fine while probing+ 401 forever. Never dispatches the fixer or a reauth.cloudflare_ua — 403 from Cloudflare's bot challenge (UA filter)unreachable — DNS / connection failureserver_error — 5xx@@ -275,6 +282,13 @@ def probe(url: str, mcp_name: str = "") -> dict:if kc_tok:headers["Authorization"] = f"Bearer {kc_tok}"+ # Did we find ANY credential to present? If not, a 401 tells us nothing+ # about the server — only that the probe knocked with empty hands. Claude+ # Code holds OAuth tokens for natively-authenticated HTTP MCPs in memory,+ # where no external prober can reach them, so those servers work perfectly+ # in every session while probing 401 forever.+ had_credential = "Authorization" in headers+body = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize","params": {@@ -296,12 +310,22 @@ def probe(url: str, mcp_name: str = "") -> dict:passif code == 401:has_refresh = bool(tokens and tokens.get("refresh_token"))+ if has_refresh:+ state = "token_expired"+ elif had_credential:+ # We presented a credential and it was rejected — a real+ # bootstrap is needed.+ state = "needs_bootstrap"+ else:+ # Nothing to present. Not a diagnosis; the probe is blind here.+ state = "no_probe_credential"return {- "state": "token_expired" if has_refresh else "needs_bootstrap",+ "state": state,"http_code": 401,"detail": err[:120],"has_refresh_token": has_refresh,"tokens_present": bool(tokens),+ "had_probe_credential": had_credential,}if code == 403:# Cloudflare 1010 bot challenge etc.@@ -471,7 +495,8 @@ def main() -> int:cur_state = {}summary = {"healthy": 0, "token_expired": 0, "needs_bootstrap": 0,- "cloudflare_ua": 0, "server_error": 0, "unreachable": 0, "other": 0}+ "no_probe_credential": 0, "cloudflare_ua": 0, "server_error": 0,+ "unreachable": 0, "other": 0}recovered = []degraded = []@@ -529,15 +554,28 @@ def main() -> int:summary["token_expired"] -= 1summary["healthy"] += 1- # Diff: degraded means previously healthy now not- if prev == "healthy" and cur_state[name]["state"] != "healthy":- degraded.append((name, cur_state[name]["state"], cur_state[name].get("detail", "")))+ # Diff: degraded means previously healthy now not. A blind probe+ # (no credential to present) is not evidence of degradation.+ now_state = cur_state[name]["state"]+ if prev == "healthy" and now_state == "no_probe_credential":+ # Silent on purpose — but say so in the log, so a token that really+ # did disappear leaves a trace instead of vanishing into a state+ # this watchdog is built to ignore.+ log(f"{name}: probe lost its credential (was healthy); not treating "+ f"as degraded — verify by calling one of its tools in a session")+ if (prev == "healthy" and now_state != "healthy"+ and now_state != "no_probe_credential"):+ degraded.append((name, now_state, cur_state[name].get("detail", "")))if prev and prev != "healthy" and cur_state[name]["state"] == "healthy":recovered.append(name)# Auto-reauth via Playwright for needs_bootstrap MCPsif AUTO_REAUTH and REAUTH_SCRIPT.exists():for name, info in cur_state.items():+ # Only a probe that presented a credential and was rejected proves+ # a bootstrap is needed. no_probe_credential proves nothing, and+ # driving a browser OAuth flow off that guess wastes a run and can+ # leave a stranded consent window.if info.get("state") != "needs_bootstrap":continuehost = (urlparse.urlparse(info["url"]).hostname or "").lower()diff --git a/claude-ops/skills/ops-mcp/SKILL.md b/claude-ops/skills/ops-mcp/SKILL.mdindex 9471b859..2431a942 100644--- a/claude-ops/skills/ops-mcp/SKILL.md+++ b/claude-ops/skills/ops-mcp/SKILL.md@@ -87,7 +87,7 @@ DAEMONSkeepalive [ok|warn|never_run] last tick [Xs ago]SERVERS ([N] configured)- [name] [healthy|token_expired|needs_bootstrap|unreachable|server_error]+ [name] [healthy|token_expired|needs_bootstrap|no_probe_credential|unreachable|server_error]url=[masked — scheme+host only] last_probed=[Xs ago]SUMMARY@@ -106,7 +106,7 @@ servers: 4 healthy, 1 needs_bootstrap (giga)cron: registered```-After dashboard: if any server is `needs_bootstrap`, surface a one-line hint: "Run `/ops:mcp reauth <name>` to restore OAuth." No `AskUserQuestion` unless something requires a binary choice.+After dashboard: if any server is `needs_bootstrap`, surface a one-line hint: "Run `/ops:mcp reauth <name>` to restore OAuth." Never say that about `no_probe_credential` — that state means the watchdog held no token to present, not that the server is broken. Claude Code keeps OAuth tokens for natively-authenticated HTTP MCPs in memory, so such a server answers every session normally. Report it as `probe blind (works in-session)` and recommend nothing. No `AskUserQuestion` unless something requires a binary choice.---@@ -134,7 +134,7 @@ Format per server:[name]type: [http|stdio]url/cmd: [masked url or command path]- state: [healthy|token_expired|needs_bootstrap|unreachable|not_probed]+ state: [healthy|token_expired|needs_bootstrap|no_probe_credential|unreachable|not_probed]probed: [ISO timestamp or "never"]detail: [detail field if not healthy]```@@ -169,7 +169,7 @@ Print the exit code and last 5 lines of `run.log` on completion.## Route — `reauth [server]`-Invokes `ops-mcp-reauth.py` (Playwright headless OAuth flow) for the named server. If no server is named, list `needs_bootstrap` servers and `AskUserQuestion` which to reauth.+Invokes `ops-mcp-reauth.py` (Playwright headless OAuth flow) for the named server. If no server is named, list `needs_bootstrap` servers and `AskUserQuestion` which to reauth. Never offer a `no_probe_credential` server here; verify it by calling one of its tools instead.```bashREAUTH="${CLAUDE_PLUGIN_ROOT}/scripts/ops-mcp-reauth.py"diff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.shindex 81b72861..0610c3da 100755--- a/claude-ops/tests/run-all.sh+++ b/claude-ops/tests/run-all.sh@@ -72,6 +72,7 @@ run_suite "$TESTS_DIR/test-ops-package.sh"run_suite "$TESTS_DIR/test-safety-hooks.sh"run_suite "$TESTS_DIR/outbound-guard/run.sh"run_suite "$TESTS_DIR/test-mcp-fixer-infra-guard.sh"+run_suite "$TESTS_DIR/test-mcp-watchdog-probe-credential.sh"run_suite "$TESTS_DIR/test-deploy-fix-hooks.sh"run_suite "$TESTS_DIR/test-deploy-fix-fleet.sh"run_suite "$TESTS_DIR/test-cloudflare-dns-lib.sh"diff --git a/claude-ops/tests/test-mcp-watchdog-probe-credential.sh b/claude-ops/tests/test-mcp-watchdog-probe-credential.shnew file mode 100755index 00000000..d7196178--- /dev/null+++ b/claude-ops/tests/test-mcp-watchdog-probe-credential.sh@@ -0,0 +1,133 @@+#!/usr/bin/env bash+# A 401 only means "needs_bootstrap" when the probe actually presented a+# credential and the server rejected it. With nothing to present, a 401 says+# only that the prober knocked with empty hands.+#+# This matters because Claude Code keeps OAuth tokens for natively-authenticated+# HTTP MCPs in memory, where no external process can read them. Such a server+# answers every session normally and probes 401 forever. Classifying that as+# needs_bootstrap dispatched the fix agent and a Playwright OAuth flow on every+# tick, and told the owner to re-auth a server that was never broken.+# Measured 2026-09-08: claude-design and openrouter, both working in-session.+#+# run-all.sh invokes suites with bash, so the Python driver is embedded here.+set -uo pipefail++HERE="$(cd "$(dirname "$0")" && pwd)"+WATCHDOG="${MCP_WATCHDOG_UNDER_TEST:-$HERE/../scripts/ops-mcp-watchdog.py}"++if [ ! -f "$WATCHDOG" ]; then+ echo "FAIL: watchdog not found at $WATCHDOG"+ exit 1+fi++python3 - "$WATCHDOG" <<'PY'+import importlib.util+import json+import sys+import urllib.error+import urllib.request++PATH = sys.argv[1]+spec = importlib.util.spec_from_file_location("wd", PATH)+wd = importlib.util.module_from_spec(spec)+spec.loader.exec_module(wd)++FAILS = []+PASSES = 0+++def check(name, cond, detail=""):+ global PASSES+ if cond:+ PASSES += 1+ else:+ FAILS.append(f"{name}{(': ' + detail) if detail else ''}")+++def fake_401(body=b'{"error":"invalid_token"}'):+ """Make every probe hit a 401, so classification is the only variable."""+ def _open(req, timeout=None):+ raise urllib.error.HTTPError(+ req.full_url, 401, "Unauthorized", {}, __import__("io").BytesIO(body))+ return _open+++real_open = urllib.request.urlopen+real_find = wd.find_token_cache+real_kc = wd.keychain_oauth_token+real_cfg = wd.config_headers+real_api = wd.get_api_key_for+try:+ urllib.request.urlopen = fake_401()++ # --- Case 1: no credential anywhere → no_probe_credential, not a fault.+ wd.find_token_cache = lambda url: (None, None)+ wd.keychain_oauth_token = lambda name: None+ wd.config_headers = lambda name: {}+ wd.get_api_key_for = lambda name: None+ r = wd.probe("https://example.invalid/mcp", "some-native-mcp")+ check("blind 401 is not needs_bootstrap", r["state"] != "needs_bootstrap",+ f"got {r['state']}")+ check("blind 401 is no_probe_credential", r["state"] == "no_probe_credential",+ f"got {r['state']}")+ check("blind 401 records had_probe_credential=False",+ r.get("had_probe_credential") is False, repr(r.get("had_probe_credential")))++ # --- Case 2: a keychain token WAS presented and rejected → real bootstrap.+ wd.keychain_oauth_token = lambda name: "tok-from-keychain"+ r = wd.probe("https://example.invalid/mcp", "some-oauth-mcp")+ check("rejected credential is needs_bootstrap", r["state"] == "needs_bootstrap",+ f"got {r['state']}")+ check("rejected credential records had_probe_credential=True",+ r.get("had_probe_credential") is True, repr(r.get("had_probe_credential")))+ wd.keychain_oauth_token = lambda name: None++ # --- Case 3: a static config header counts as a presented credential.+ wd.config_headers = lambda name: {"Authorization": "Bearer from-config"}+ r = wd.probe("https://example.invalid/mcp", "header-mcp")+ check("config header counts as a credential", r["state"] == "needs_bootstrap",+ f"got {r['state']}")+ wd.config_headers = lambda name: {}++ # --- Case 4: a refresh token still wins — that path is recoverable.+ wd.find_token_cache = lambda url: (None, None)+ class _P:+ def read_text(self):+ return json.dumps({"access_token": "a", "refresh_token": "r"})+ wd.find_token_cache = lambda url: (_P(), None)+ r = wd.probe("https://example.invalid/mcp", "refreshable-mcp")+ check("refresh token still classifies token_expired",+ r["state"] == "token_expired", f"got {r['state']}")+finally:+ urllib.request.urlopen = real_open+ wd.find_token_cache = real_find+ wd.keychain_oauth_token = real_kc+ wd.config_headers = real_cfg+ wd.get_api_key_for = real_api++# --- Case 5: the state must never drive the fixer or a browser OAuth flow.+src = open(PATH).read()+reauth_guard = 'if info.get("state") != "needs_bootstrap":' in src+check("auto-reauth loop only acts on needs_bootstrap", reauth_guard)+check("degradation diff excludes no_probe_credential",+ '!= "no_probe_credential"' in src)++# --- Case 6: the summary must be able to count it.+check("summary has a no_probe_credential bucket", '"no_probe_credential": 0' in src)++# --- Case 7: ops-doctor must not warn on it.+import os+doctor = os.path.join(os.path.dirname(PATH), "..", "bin", "ops-doctor")+if os.path.exists(doctor):+ d = open(doctor).read()+ check("ops-doctor skips no_probe_credential in its degraded>1h warning",+ "no_probe_credential" in d)+else:+ check("ops-doctor present", False, "not found")++for f in FAILS:+ print(f"FAIL: {f}")+print(f"{PASSES} passed, {len(FAILS)} failed")+sys.exit(1 if FAILS else 0)+PY