From d09658c3af4b84df079bd6aeb67323e024bc1b0f Mon Sep 17 00:00:00 2001 From: George Vauter Date: Mon, 13 Jul 2026 09:10:09 -0400 Subject: [PATCH] fix(mcp-setup): add runtime detection and interactive fallback for tool environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the silent 'Unknown → .mcp.json' default with a three-tier detection strategy: 1. Runtime detection (env vars: OPENCODE_SESSION, CLAUDE_CODE, etc.) 2. Directory scanning (.claude-plugin/, .opencode/, .cursor-plugin/) 3. Interactive prompt asking the user which tool they are using This fixes the chicken-and-egg problem where consumer repos have no tool directories when mcp-setup is first invoked, causing OpenCode users to get Claude Code config format. Closes #120 Signed-off-by: George Vauter --- skills/mcp-setup/SKILL.md | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/skills/mcp-setup/SKILL.md b/skills/mcp-setup/SKILL.md index c922ccb..49a7f47 100644 --- a/skills/mcp-setup/SKILL.md +++ b/skills/mcp-setup/SKILL.md @@ -99,13 +99,37 @@ container image. Fall back to `:main` and inform the user: Determine which AI coding tool is running and adapt the output. -First, scan for all recognized tool directories: +#### 5a: Implicit context (preferred) + +The most reliable signal is the tool that is currently executing this skill. +Users may have multiple AI tools installed, so binary/PATH detection is not +sufficient — it only proves installation, not active use. + +- **OpenCode** — If this skill was loaded via OpenCode's `skill` tool or + a `/comply-setup` custom command, the tool is OpenCode. The agent + should recognize that it *is* OpenCode and select itself without + scanning. +- **Claude Code** — If the skill was loaded via Claude Code's slash + command system (e.g., `/comply:mcp-setup`), the tool is Claude Code. +- **Cursor** — If the skill was loaded via Cursor's command system, the + tool is Cursor. + +Since the agent inherently knows which tool it is running inside, this +detection requires no environment checks. Use it directly and skip all +further detection steps. + +#### 5b: Directory scanning (fallback) + +If the agent cannot determine its own runtime identity (e.g., the skill +instructions were copy-pasted into a generic chat), scan for recognized +tool directories: - `.claude-plugin/` → Claude Code - `.opencode/` → OpenCode - `.cursor-plugin/` → Cursor -**If multiple tool directories are found**: prompt the user to select their active tool before proceeding. Example: +**If multiple tool directories are found**: prompt the user to select their +active tool before proceeding. Example: > Multiple AI coding tools detected in this repository: > 1. Claude Code (`.claude-plugin/`) @@ -116,9 +140,24 @@ First, scan for all recognized tool directories: **If exactly one is found**: use it automatically. -**If none are found**: fall back to Unknown. +#### 5c: Interactive prompt (last resort) + +**If the agent cannot determine its runtime identity and no tool +directories are found**, prompt the user — never silently default: + +> No AI coding tool detected automatically. +> Which AI coding tool are you using? +> +> 1. Claude Code +> 2. OpenCode +> 3. Cursor + +#### Fallback rule + +If any step above fails or produces an ambiguous result, always fall back +to prompting the user with the supported tool list. Never guess silently. -Then apply the selected tool's setup steps: +#### Apply the detected tool's setup steps - **Claude Code**: Write `.mcp.json` (see Step 7, `.mcp.json` format). - **OpenCode**: Write `opencode.json` (see Step 7, `opencode.json` format). Verify that `.opencode/skills/` symlinks exist — if not, create them: @@ -129,7 +168,6 @@ Then apply the selected tool's setup steps: ln -sf ../../skills/mcp-setup .opencode/skills/mcp-setup ``` - **Cursor**: Write `.mcp.json` (see Step 7, `.mcp.json` format). -- **Unknown**: Write `.mcp.json` and inform the user about skill discovery. ### Step 7: Write Configuration