Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b40d6bd

Browse files
mksgluclaude
andcommitted
feat: add MCP clientInfo detection + Antigravity and Kiro adapters
Implement protocol-level platform detection via MCP clientInfo.name, eliminating env var guessing for MCP-connected clients. Add two new mcp-only adapters (Antigravity, Kiro) with full test coverage. Detection priority: clientInfo > CONTEXT_MODE_PLATFORM > env vars > fs > fallback Verified sources: - Antigravity clientInfo: "antigravity-client" - Kiro CLI clientInfo: "Kiro CLI" (kirodotdev/Kiro#5205) - Kiro MCP config: kiro.dev/docs/mcp/configuration - Kiro CLI hooks: kiro.dev/docs/cli/hooks (Phase 2) Closes mksglu#130 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent c179bec commit b40d6bd

15 files changed

Lines changed: 1395 additions & 58 deletions

File tree

README.md

Lines changed: 90 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,67 @@ Global `~/.codex/AGENTS.md` applies to all projects. Project-level `./AGENTS.md`
295295

296296
</details>
297297

298+
<details>
299+
<summary><strong>Antigravity</strong> <sup>(Beta)</sup></summary>
300+
301+
**Step 1 — Install globally:**
302+
303+
```bash
304+
npm install -g context-mode
305+
```
306+
307+
**Step 2 — Register the MCP server.** Add to `~/.gemini/antigravity/mcp_config.json`:
308+
309+
```json
310+
{
311+
"mcpServers": {
312+
"context-mode": {
313+
"command": "context-mode"
314+
}
315+
}
316+
}
317+
```
318+
319+
**Step 3 — Restart Antigravity.** On first MCP server startup, a `GEMINI.md` routing instructions file is auto-created in your project root. Antigravity reads `GEMINI.md` automatically and learns to prefer context-mode sandbox tools.
320+
321+
**About hooks:** Antigravity does not support hooks — there is no public hook API. The `GEMINI.md` routing instructions file is the only enforcement method (~60% compliance). The model receives the instructions at session start and sometimes follows them, but there is no programmatic interception — it can run raw `run_command`, read large files via `view_file`, or bypass sandbox tools at any time.
322+
323+
**Auto-detection:** context-mode detects Antigravity automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
324+
325+
Example MCP config: [`configs/antigravity/mcp_config.json`](configs/antigravity/mcp_config.json)
326+
Routing rules: [`configs/antigravity/GEMINI.md`](configs/antigravity/GEMINI.md)
327+
328+
</details>
329+
330+
<details>
331+
<summary><strong>Kiro</strong> <sup>(Beta)</sup></summary>
332+
333+
**Step 1 — Install globally:**
334+
335+
```bash
336+
npm install -g context-mode
337+
```
338+
339+
**Step 2 — Register the MCP server.** Add to `.kiro/settings/mcp.json` in your project root (or `~/.kiro/settings/mcp.json` for global):
340+
341+
```json
342+
{
343+
"mcpServers": {
344+
"context-mode": {
345+
"command": "context-mode"
346+
}
347+
}
348+
}
349+
```
350+
351+
**Step 3 — Restart Kiro.** On first MCP server startup, a `KIRO.md` routing instructions file is auto-created in your project root. Kiro reads `KIRO.md` automatically and learns to prefer context-mode sandbox tools.
352+
353+
**About hooks:** Kiro hook-based session continuity will be added once Kiro CLI hooks are fully tested. The `KIRO.md` routing instructions file is the current enforcement method (~60% compliance).
354+
355+
**Auto-detection:** context-mode detects Kiro automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
356+
357+
</details>
358+
298359
<details>
299360
<summary><strong>Build Prerequisites</strong> <sup>(CentOS, RHEL, Alpine)</sup></summary>
300361

@@ -385,15 +446,15 @@ Context Mode captures every meaningful event during your session and persists th
385446

386447
Session continuity requires 4 hooks working together:
387448

388-
| Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | Codex CLI |
389-
|---|---|:---:|:---:|:---:|:---:|:---:|:---:|
390-
| **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | -- |
391-
| **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- |
392-
| **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | -- |
393-
| **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | -- |
394-
| | **Session completeness** | **Full** | **High** | **High** | **Partial** | **High** | **--** |
449+
| Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | Codex CLI | Antigravity | Kiro |
450+
|---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
451+
| **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | -- | -- | -- |
452+
| **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- |
453+
| **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | -- | -- | -- |
454+
| **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | -- | -- | -- |
455+
| | **Session completeness** | **Full** | **High** | **High** | **Partial** | **High** | **--** | **--** | **--** |
395456

396-
> **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, **VS Code Copilot**, and **OpenCode**. **Cursor** captures tool events via `preToolUse`/`postToolUse`, but `sessionStart` is currently rejected by Cursor's validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)), so session restore after compaction is not available yet. **OpenCode** uses the `experimental.session.compacting` plugin hook for compaction recovery, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume is not supported. Codex CLI has no hook support, so session tracking is not available.
457+
> **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, **VS Code Copilot**, and **OpenCode**. **Cursor** captures tool events via `preToolUse`/`postToolUse`, but `sessionStart` is currently rejected by Cursor's validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)), so session restore after compaction is not available yet. **OpenCode** uses the `experimental.session.compacting` plugin hook for compaction recovery, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume is not supported. **Codex CLI**, **Antigravity**, and **Kiro** have no hook support in the current release, so session tracking is not available.
397458
398459
<details>
399460
<summary><strong>What gets captured</strong></summary>
@@ -474,26 +535,32 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
474535

475536
**Codex CLI** — No session support. No hooks means no event capture. Each compaction or new session starts fresh. The `AGENTS.md` routing instructions file is the only continuity mechanism.
476537

538+
**Antigravity** — No session support. Same as Codex CLI — no hooks, no event capture. The `GEMINI.md` routing instructions file is auto-written on first MCP server startup. Auto-detected via MCP protocol handshake (`clientInfo.name`).
539+
540+
**Kiro** — No session support in the current release. MCP-only. The `KIRO.md` routing instructions file is auto-written on first MCP server startup. Hook-based session continuity will be added once Kiro CLI hooks are fully tested. Auto-detected via MCP protocol handshake (`clientInfo.name`).
541+
477542
</details>
478543

479544
## Platform Compatibility
480545

481-
| Feature | Claude Code | Gemini CLI <sup>(Beta)</sup> | VS Code Copilot <sup>(Beta)</sup> | Cursor <sup>(Beta)</sup> | OpenCode <sup>(Beta)</sup> | Codex CLI <sup>(Beta)</sup> |
482-
|---|:---:|:---:|:---:|:---:|:---:|:---:|
483-
| MCP Server | Yes | Yes | Yes | Yes | Yes | Yes |
484-
| PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | -- |
485-
| PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | -- |
486-
| SessionStart Hook | Yes | Yes | Yes | -- | -- | -- |
487-
| PreCompact Hook | Yes | Yes | Yes | -- | Plugin | -- |
488-
| Can Modify Args | Yes | Yes | Yes | Yes | Plugin | -- |
489-
| Can Block Tools | Yes | Yes | Yes | Yes | Plugin | -- |
490-
| Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes |
491-
| Slash Commands | Yes | -- | -- | -- | -- | -- |
492-
| Plugin Marketplace | Yes | -- | -- | -- | -- | -- |
546+
| Feature | Claude Code | Gemini CLI <sup>(Beta)</sup> | VS Code Copilot <sup>(Beta)</sup> | Cursor <sup>(Beta)</sup> | OpenCode <sup>(Beta)</sup> | Codex CLI <sup>(Beta)</sup> | Antigravity <sup>(Beta)</sup> | Kiro <sup>(Beta)</sup> |
547+
|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
548+
| MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
549+
| PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | -- | -- | -- |
550+
| PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | -- | -- | -- |
551+
| SessionStart Hook | Yes | Yes | Yes | -- | -- | -- | -- | -- |
552+
| PreCompact Hook | Yes | Yes | Yes | -- | Plugin | -- | -- | -- |
553+
| Can Modify Args | Yes | Yes | Yes | Yes | Plugin | -- | -- | -- |
554+
| Can Block Tools | Yes | Yes | Yes | Yes | Plugin | -- | -- | -- |
555+
| Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
556+
| Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- |
557+
| Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- |
493558

494559
> **OpenCode** uses a TypeScript plugin paradigm — hooks run as in-process functions via `tool.execute.before`, `tool.execute.after`, and `experimental.session.compacting`, providing the same routing enforcement and session continuity as shell-based hooks. SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), but compaction recovery works via the plugin's compacting hook.
495560
>
496-
> **Codex CLI** does not support hooks. It relies solely on routing instruction files (`AGENTS.md`) for enforcement (~60% compliance).
561+
> **Codex CLI** and **Antigravity** do not support hooks. They rely solely on routing instruction files (`AGENTS.md` / `GEMINI.md`) for enforcement (~60% compliance). Antigravity is auto-detected via MCP protocol handshake — no manual platform configuration needed.
562+
>
563+
> **Kiro** is MCP-only in the current release. Hook-based enforcement will be added once Kiro CLI hooks are fully tested. Kiro is auto-detected via MCP protocol handshake (`clientInfo.name`).
497564
498565
### Routing Enforcement
499566

@@ -507,6 +574,8 @@ Hooks intercept tool calls programmatically — they can block dangerous command
507574
| Cursor | Yes | -- | **~98% saved** | Manual tool choice |
508575
| OpenCode | Plugin | [`AGENTS.md`](configs/opencode/AGENTS.md) | **~98% saved** | ~60% saved |
509576
| Codex CLI | -- | [`AGENTS.md`](configs/codex/AGENTS.md) | -- | ~60% saved |
577+
| Antigravity | -- | [`GEMINI.md`](configs/antigravity/GEMINI.md) | -- | ~60% saved |
578+
| Kiro | -- | [`KIRO.md`](configs/kiro/KIRO.md) | -- | ~60% saved |
510579

511580
Without hooks, one unrouted `curl` or Playwright snapshot can dump 56 KB into context — wiping out an entire session's worth of savings.
512581

configs/antigravity/GEMINI.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# context-mode — MANDATORY routing rules
2+
3+
You have context-mode MCP tools available. These rules are NOT optional — they protect your context window from flooding. A single unrouted command can dump 56 KB into context and waste the entire session. Antigravity does NOT have hooks, so these instructions are your ONLY enforcement mechanism. Follow them strictly.
4+
5+
## BLOCKED commands — do NOT use these
6+
7+
### curl / wget — FORBIDDEN
8+
Do NOT use `curl` or `wget` via `run_command`. They dump raw HTTP responses directly into your context window.
9+
Instead use:
10+
- `mcp__context-mode__ctx_fetch_and_index(url, source)` to fetch and index web pages
11+
- `mcp__context-mode__ctx_execute(language: "javascript", code: "const r = await fetch(...)")` to run HTTP calls in sandbox
12+
13+
### Inline HTTP — FORBIDDEN
14+
Do NOT run inline HTTP calls via `run_command` with `node -e "fetch(..."`, `python -c "requests.get(..."`, or similar patterns. They bypass the sandbox and flood context.
15+
Instead use:
16+
- `mcp__context-mode__ctx_execute(language, code)` to run HTTP calls in sandbox — only stdout enters context
17+
18+
### Direct web fetching — FORBIDDEN
19+
Do NOT use `read_url_content` for large pages. Raw HTML can exceed 100 KB.
20+
Instead use:
21+
- `mcp__context-mode__ctx_fetch_and_index(url, source)` then `mcp__context-mode__ctx_search(queries)` to query the indexed content
22+
23+
## REDIRECTED tools — use sandbox equivalents
24+
25+
### Shell (>20 lines output)
26+
`run_command` is ONLY for: `git`, `mkdir`, `rm`, `mv`, `cd`, `ls`, `npm install`, `pip install`, and other short-output commands.
27+
For everything else, use:
28+
- `mcp__context-mode__ctx_batch_execute(commands, queries)` — run multiple commands + search in ONE call
29+
- `mcp__context-mode__ctx_execute(language: "shell", code: "...")` — run in sandbox, only stdout enters context
30+
31+
### File reading (for analysis)
32+
If you are reading a file to **edit** it → `view_file` / `replace_file_content` is correct (edit needs content in context).
33+
If you are reading to **analyze, explore, or summarize** → use `mcp__context-mode__ctx_execute_file(path, language, code)` instead. Only your printed summary enters context. The raw file stays in the sandbox.
34+
35+
### Search (large results)
36+
Search results can flood context. Use `mcp__context-mode__ctx_execute(language: "shell", code: "grep ...")` to run searches in sandbox. Only your printed summary enters context.
37+
38+
## Tool selection hierarchy
39+
40+
1. **GATHER**: `mcp__context-mode__ctx_batch_execute(commands, queries)` — Primary tool. Runs all commands, auto-indexes output, returns search results. ONE call replaces 30+ individual calls.
41+
2. **FOLLOW-UP**: `mcp__context-mode__ctx_search(queries: ["q1", "q2", ...])` — Query indexed content. Pass ALL questions as array in ONE call.
42+
3. **PROCESSING**: `mcp__context-mode__ctx_execute(language, code)` | `mcp__context-mode__ctx_execute_file(path, language, code)` — Sandbox execution. Only stdout enters context.
43+
4. **WEB**: `mcp__context-mode__ctx_fetch_and_index(url, source)` then `mcp__context-mode__ctx_search(queries)` — Fetch, chunk, index, query. Raw HTML never enters context.
44+
5. **INDEX**: `mcp__context-mode__ctx_index(content, source)` — Store content in FTS5 knowledge base for later search.
45+
46+
## Output constraints
47+
48+
- Keep responses under 500 words.
49+
- Write artifacts (code, configs, PRDs) to FILES — never return them as inline text. Return only: file path + 1-line description.
50+
- When indexing content, use descriptive source labels so others can `search(source: "label")` later.
51+
52+
## ctx commands
53+
54+
| Command | Action |
55+
|---------|--------|
56+
| `ctx stats` | Call the `stats` MCP tool and display the full output verbatim |
57+
| `ctx doctor` | Call the `doctor` MCP tool, run the returned shell command, display as checklist |
58+
| `ctx upgrade` | Call the `upgrade` MCP tool, run the returned shell command, display as checklist |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mcpServers": {
3+
"context-mode": {
4+
"command": "context-mode"
5+
}
6+
}
7+
}

configs/kiro/mcp_config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mcpServers": {
3+
"context-mode": {
4+
"command": "context-mode"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)