Device sweep: resolve Claude connector UUIDs#220
Merged
Conversation
Fetch the backend's unresolved-UUID worklist, match each against the local Claude session files (Claude Code + CoWork folders), and report the resolved name + tools back via the single-server scan endpoint with the originating UUID. Only UUIDs the backend asked for are sent; HTTP via curl per the Zscaler constraint.
Call run_sweep at the end of the discovery run so connector UUIDs self-heal on the tool's existing periodic cadence. Best-effort — never affects the discovery outcome.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c728c8d. Configure here.
vigneshsubbiah16
left a comment
Contributor
There was a problem hiding this comment.
🛡️ Automated Security Review (consensus)
1 finding — 0 high-confidence, 1 to triage. Reviewers: Cursor, Claude, Semgrep, Gitleaks.
🟡 TRIAGE
API key not escaped for newlines in curl --config
scripts/coding_discovery_tools/sweep_connectors.py:139(_auth_header/_curl_config_quote)- Impact: A newline or other control character in the device API key could break out of the double-quoted
Authorizationline in the stdin curl config and inject extra curl directives. - Fix: Reject/strip control characters (especially
\n/\r) fromapi_keybefore embedding, or pass the token via-H @-/ an env-based form instead of string interpolation. - Reviewers: Claude
Previously acknowledged (not re-flagged)
- Outbound connector names and tool metadata to the control plane — accepted by design (PR scope: worklist-scoped resolution of backend-requested UUIDs only).
🤖 consensus review · reviewers: Cursor,Claude,Semgrep,Gitleaks · head c728c8db · 2026-06-29T18:42Z
MohamedAklamaash
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Device-side sweep that resolves bare Claude connector UUIDs to their real names so the control plane can group/policy them. Companion backend PR: ai-gateway-data #2340.
OAuth remote connectors are named by a per-registration UUID at runtime; the real display name only lives in the local Claude session files on the device, so the backend can't resolve it alone.
How (
sweep_connectors.py, wired intoai_tools_discovery.main)GET /api/v1/ai-tools/unresolved-connector-uuids/— the worklist of UUIDs the backend still needs. Empty → skip.claude-code-sessions= Claude Code,local-agent-mode-sessions= CoWork) →remoteMcpServersConfig→{uuid, name, tools}, newest-file-first, name-consistent tool union.POSTthe realname+tools+ originatingconnector_uuidto/api/v1/ai-tools/mcp-server-scan/.Runs at the end of every discovery (
run_sweep) so it self-heals on the tool's existing periodic cadence. Best-effort — never affects the discovery outcome. Only UUIDs the backend asked for leave the device; HTTP viacurl(Zscaler constraint, nourllib).Notes / follow-ups
claude-connector:<name>keeper with tools, worklist entry cleared.🤖 Generated with Claude Code
Note
Medium Risk
New outbound posts carry MCP connector names and tool metadata (worklist-scoped), and local reads use the running user's Claude app-support dir only, which may miss connectors under other users on multi-user/root scans.
Overview
Adds a device-side connector UUID sweep so the control plane can turn orphan
claude-connectorrows (UUID-only names) into real display names and tool lists that only exist in local Claude session files.New
sweep_connectors.pyimplementsrun_sweep: GET/api/v1/ai-tools/unresolved-connector-uuids/, parseremoteMcpServersConfigfromclaude-code-sessionsandlocal-agent-mode-sessionslocal_*.json(newest-first, same-name tool union), then POST each backend-requested match to/api/v1/ai-tools/mcp-server-scan/withconnector_uuid,claude-connectorscope, and tools. HTTP uses curl + stdin config (same pattern as other discovery scripts). Runnable standalone via CLI.ai_tools_discoveryimportsrun_sweepand invokes it after the scan completed event inside a try/except so failures are logged only and do not change discovery exit status.Reviewed by Cursor Bugbot for commit c728c8d. Bugbot is set up for automated code reviews on this repo. Configure here.
Greptile Summary
This PR adds a device-side sweep (
sweep_connectors.py) that resolves bare Claude connector UUIDs to real display names by reading local Claude session files and reporting matches back to the control plane. It is wired into the existing discovery run as a best-effort post-scan step.sweep_connectors.pyfetches an unresolved-UUID worklist from the backend, readsremoteMcpServersConfigfrom bothclaude-code-sessionsandlocal-agent-mode-sessions(newest-file-first), then POSTs each matched UUID's real name and tools to the single-server scan endpoint one at a time viacurl.ai_tools_discovery.pyimports and callsrun_sweepat the tail ofmain(), wrapping it in a broadtry/exceptso failures can't disrupt the discovery outcome.Confidence Score: 3/5
The sweep is isolated behind a try/except and cannot crash the main discovery run, but it ships with no metrics instrumentation and sweep failures are logged at debug level making them invisible in production.
The core logic for reading session files and posting resolutions looks correct and the isolation from the main discovery flow is handled properly. The main gap is that the new flow has zero Prometheus metrics — no counters for resolved/failed items, no latency histograms for either HTTP call — which means any regression in resolution rate or backend latency is undetectable until a user-visible symptom appears.
sweep_connectors.py needs the most attention: it is the entire new flow and is missing all metrics instrumentation. The logging style (print to stderr) also needs updating to integrate cleanly with the discovery runner's structured logger.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant D as Discovery (main) participant S as sweep_connectors participant BE as Control Plane participant FS as Local Session Files D->>S: run_sweep(domain, api_key) S->>BE: GET /api/v1/ai-tools/unresolved-connector-uuids/ BE-->>S: "{uuids: [...]}" alt nothing to resolve S-->>D: (0, 0, 0) else UUIDs needed S->>FS: "glob **/local_*.json (claude-code-sessions + local-agent-mode-sessions)" FS-->>S: session JSON files (sorted newest-first) S->>S: "parse remoteMcpServersConfig → {uuid: {name, tools}}" loop for each matched UUID S->>BE: "POST /api/v1/ai-tools/mcp-server-scan/ {mcp_server, connector_uuid}" BE-->>S: 2xx / error end S-->>D: (sent, failed, matched) end%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant D as Discovery (main) participant S as sweep_connectors participant BE as Control Plane participant FS as Local Session Files D->>S: run_sweep(domain, api_key) S->>BE: GET /api/v1/ai-tools/unresolved-connector-uuids/ BE-->>S: "{uuids: [...]}" alt nothing to resolve S-->>D: (0, 0, 0) else UUIDs needed S->>FS: "glob **/local_*.json (claude-code-sessions + local-agent-mode-sessions)" FS-->>S: session JSON files (sorted newest-first) S->>S: "parse remoteMcpServersConfig → {uuid: {name, tools}}" loop for each matched UUID S->>BE: "POST /api/v1/ai-tools/mcp-server-scan/ {mcp_server, connector_uuid}" BE-->>S: 2xx / error end S-->>D: (sent, failed, matched) endReviews (1): Last reviewed commit: "Run the connector sweep as part of disco..." | Re-trigger Greptile