claude-chatter-mcp 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. claude_chatter_mcp-0.5.0/LICENSE +21 -0
  2. claude_chatter_mcp-0.5.0/PKG-INFO +322 -0
  3. claude_chatter_mcp-0.5.0/README.md +292 -0
  4. claude_chatter_mcp-0.5.0/agy_wakeup/__init__.py +6 -0
  5. claude_chatter_mcp-0.5.0/agy_wakeup/agentapi.py +57 -0
  6. claude_chatter_mcp-0.5.0/agy_wakeup/cli.py +27 -0
  7. claude_chatter_mcp-0.5.0/agy_wakeup/command.py +48 -0
  8. claude_chatter_mcp-0.5.0/agy_wakeup/control.py +48 -0
  9. claude_chatter_mcp-0.5.0/agy_wakeup/endpoint.py +72 -0
  10. claude_chatter_mcp-0.5.0/agy_wakeup/hook.py +76 -0
  11. claude_chatter_mcp-0.5.0/agy_wakeup/paths.py +8 -0
  12. claude_chatter_mcp-0.5.0/agy_wakeup/pinning.py +19 -0
  13. claude_chatter_mcp-0.5.0/agy_wakeup/poker.py +111 -0
  14. claude_chatter_mcp-0.5.0/agy_wakeup/prime.py +53 -0
  15. claude_chatter_mcp-0.5.0/agy_wakeup/shell.py +97 -0
  16. claude_chatter_mcp-0.5.0/claude_chatter_mcp/__init__.py +1 -0
  17. claude_chatter_mcp-0.5.0/claude_chatter_mcp/agy_glue.py +34 -0
  18. claude_chatter_mcp-0.5.0/claude_chatter_mcp/cli.py +105 -0
  19. claude_chatter_mcp-0.5.0/claude_chatter_mcp/mcp_server.py +364 -0
  20. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/PKG-INFO +322 -0
  21. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/SOURCES.txt +25 -0
  22. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/dependency_links.txt +1 -0
  23. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/entry_points.txt +3 -0
  24. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/requires.txt +3 -0
  25. claude_chatter_mcp-0.5.0/claude_chatter_mcp.egg-info/top_level.txt +2 -0
  26. claude_chatter_mcp-0.5.0/pyproject.toml +45 -0
  27. claude_chatter_mcp-0.5.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vladimir Berezhnoy <non7top@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,322 @@
1
+ Metadata-Version: 2.4
2
+ Name: claude-chatter-mcp
3
+ Version: 0.5.0
4
+ Summary: MCP server that lets Antigravity (agy) and other MCP hosts message Claude Code sessions, with push wake-up for idle agy conversations.
5
+ Author: non7top
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/non7top/claude-chatter-mcp
8
+ Project-URL: Source, https://github.com/non7top/claude-chatter-mcp
9
+ Project-URL: Issues, https://github.com/non7top/claude-chatter-mcp/issues
10
+ Keywords: mcp,claude-code,antigravity,agy,peer-messaging,ipc
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: POSIX
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Communications
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: claude-chatter>=0.2.1
27
+ Requires-Dist: psutil>=5.9.0
28
+ Requires-Dist: fastmcp>=4.0.10
29
+ Dynamic: license-file
30
+
31
+ # claude-chatter-mcp bridge
32
+
33
+ `claude-chatter-mcp` lets MCP-compatible agents (built for **Google Antigravity**) exchange messages with Claude Code sessions. It speaks Claude Code's peer-messaging protocol (`SendMessage`/`ListAgents`): the bridge announces itself as a session and talks to other sessions over their Unix sockets. Non-blocking and authenticated.
34
+
35
+ It ships three ways: as a plain MCP server (`bridge-mcp`), as a standalone daemon/CLI, and as an **Antigravity CLI (`agy`) plugin** that bundles the MCP server, a `PreInvocation` hook that primes push, a rules file and the `chatter` skill (see [Option 5](#option-5-antigravity-plugin-mcp-server--push-priming)).
36
+
37
+ ## Packages
38
+
39
+ This distribution installs two Python packages on top of the [`claude-chatter`](https://pypi.org/project/claude-chatter/) library:
40
+
41
+ | Package | What it does |
42
+ | --- | --- |
43
+ | `claude-chatter` (separate PyPI library, a dependency) | The peer-messaging protocol: session discovery, socket transport, SQLite mailbox, jobs, and the `claude-chatter` / `chatter` CLI. |
44
+ | `claude_chatter_mcp` | The MCP server and the `bridge-mcp` command. The plain CLI modes (`--list`, `--send`, `--inbox`, ...) are served by the library's CLI. |
45
+ | `agy_wakeup` | Waking an idle Antigravity conversation: the prime command, the `PreInvocation` hook, the shell-side primer, the control socket and the `agentapi send-message` call. It does not import `claude_chatter_mcp`; `claude_chatter_mcp/agy_glue.py` configures it for this bridge. The `agy-wakeup` command exposes its `--prime` and `--prime-hook` modes. |
46
+
47
+ ## 🚀 Key Features
48
+
49
+ * **Session Discovery & Automatic Purging**: Scans local workspace configurations (`~/.claude/sessions/*.json`), verifies process lifecycles via PID tracking (`psutil`), and automatically purges orphaned session descriptors and stale `.key` credential files.
50
+ * **Authenticated Unix Socket IPC**: Authenticates outbound message frames directly into active target session sockets (`/run/user/<uid>/cc-socks/*.sock`) using the `peerToken` read from each session's `.key` file.
51
+ * **Fire-and-Forget Message Dispatch**: `send_message`/`--send` dispatches and returns immediately; a real reply, if the target sends one, arrives later as its own inbound message rather than being synchronously extracted from a transcript file.
52
+ * **Dedicated Inbound Unix Socket Listener**: Listens on a per-session socket (default `/run/user/<uid>/cc-socks/bridge-<name>.sock`, falling back to `/tmp/cc-socks/`; override with `--socket` or `CHATTER_BRIDGE_SOCKET`; single-user `0600` permissions) for real-time peer confirmations and inbound message buffering.
53
+ * **Push to Antigravity**: `enable_push` / `bridge-mcp --prime` lets an inbound message wake an idle `agy` conversation through `agy agentapi send-message`, so the agent does not have to poll `read_messages` (see [Waking an idle Antigravity session](#-waking-an-idle-antigravity-session-push)).
54
+ * **Background Job Listing**: `list_jobs` / `--jobs` reads `~/.claude/jobs` to report every background job, including finished ones that have no live process, with state, result text, PR states, worktree, running status and transcript path.
55
+ * **Graceful Lifecycle & Signal Handling**: Catches `SIGTERM` and `SIGINT` signals to cleanly unbind sockets and exit with status code `0`, avoiding process termination errors during MCP server reloads.
56
+
57
+ ---
58
+
59
+ ## 🛠️ Architecture
60
+
61
+ ```
62
+ ┌──────────────────────┐ ┌──────────────────────┐
63
+ │ Google Antigravity │ │ Claude Code │
64
+ │ (Prose / agy) │ │ (Execution / CLI) │
65
+ └──────────┬───────────┘ └──────────▲───────────┘
66
+ │ │
67
+ (MCP Tool Calls) (Pushed NDJSON Stream)
68
+ │ │
69
+ ┌──────────▼────────────────────────────────────┴───────────┐
70
+ │ SOCKET BRIDGE MCP SERVER │
71
+ │ ┌───────────────────────┐ ┌─────────────────────────┐ │
72
+ │ │ Response History Cache│ │ Active Session Monitor │ │
73
+ │ │ (In-Memory) │ │ (Dead Socket Purging) │ │
74
+ │ └───────────────────────┘ └─────────────────────────┘ │
75
+ │ ┌───────────────────────┐ ┌─────────────────────────┐ │
76
+ │ │ Inbound IPC Server │ │ Outbound Socket Manager │ │
77
+ │ │ Listener Daemon │ │ (Key-Authenticated) │ │
78
+ │ └───────────────────────┘ └─────────────────────────┘ │
79
+ └───────────────────────────────────────────────────────────┘
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 📦 Installation & Setup
85
+
86
+ ### Option 1: From PyPI
87
+
88
+ ```bash
89
+ # Zero-installation, register with Antigravity CLI (agy):
90
+ agy mcp add claudemessaging uvx --from claude-chatter-mcp bridge-mcp
91
+
92
+ # Or install the commands permanently (bridge-mcp, agy-wakeup, claude-chatter, chatter):
93
+ uv tool install claude-chatter-mcp
94
+ # or: pipx install claude-chatter-mcp
95
+ agy mcp add claudemessaging bridge-mcp
96
+ ```
97
+
98
+ Requires Python 3.10 or newer. POSIX only, developed on Linux; see Limits below.
99
+
100
+ ---
101
+
102
+ ### Option 2: Via `uvx` or `uv tool run` from GitHub (Zero-Installation / Ephemeral)
103
+
104
+ Register directly with **Antigravity CLI (`agy`)** from GitHub without cloning:
105
+
106
+ **Using `uvx`:**
107
+ ```bash
108
+ agy mcp add claudemessaging uvx --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
109
+ ```
110
+
111
+ **Using `uv tool run`:**
112
+ ```bash
113
+ agy mcp add claudemessaging uv tool run --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
114
+ ```
115
+
116
+ Or run directly in terminal:
117
+ ```bash
118
+ uvx --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
119
+ ```
120
+
121
+ ---
122
+
123
+ ### Option 3: Permanent Tool Installation from GitHub (`uv tool install`)
124
+
125
+ Install the `bridge-mcp` binary permanently into your system path using `uv`:
126
+
127
+ ```bash
128
+ # 1. Install tool permanently into ~/.local/bin (or uv tool path)
129
+ uv tool install git+https://github.com/non7top/claude-chatter-mcp.git
130
+
131
+ # 2. Register with Antigravity CLI
132
+ agy mcp add claudemessaging bridge-mcp
133
+ ```
134
+
135
+ ---
136
+
137
+ ### Option 4: Local Repository Installation
138
+
139
+ 1. **Clone the repository**:
140
+ ```bash
141
+ git clone https://github.com/non7top/claude-chatter-mcp.git
142
+ cd claude-chatter-mcp
143
+ ```
144
+
145
+ 2. **Register with Antigravity CLI (`agy`) using `uv` / `uvx`**:
146
+ ```bash
147
+ agy mcp add claudemessaging uvx --from . bridge-mcp
148
+ ```
149
+
150
+ 3. **Or register with standard `python3`**:
151
+ ```bash
152
+ agy mcp add claudemessaging python3 $(pwd)/bridge_mcp.py
153
+ ```
154
+
155
+ 4. **Verify registration**:
156
+ ```bash
157
+ agy mcp list
158
+ ```
159
+
160
+ ---
161
+
162
+ ### Option 5: Antigravity plugin (MCP server + push priming)
163
+
164
+ This repo is also an Antigravity CLI plugin: `plugin.json`, `mcp_config.json` (the MCP server), `hooks.json` (a `PreInvocation` hook that primes push, see below) and `rules/claude-chatter.md`.
165
+
166
+ ```bash
167
+ agy plugin install https://github.com/non7top/claude-chatter-mcp
168
+ ```
169
+
170
+ Only `uv` needs to be installed: the plugin's MCP server and hook run `uvx --from git+https://github.com/non7top/claude-chatter-mcp bridge-mcp`, which fetches and caches the bridge on first use.
171
+
172
+ If you registered the server by hand earlier (`agy mcp add ...`), remove it so the plugin's copy is the only one.
173
+
174
+ ---
175
+
176
+ ## 🔔 Waking an idle Antigravity session (push)
177
+
178
+ `agy` cannot be woken by an MCP server, so by default it only sees inbound messages when it calls `read_messages`. Push closes that gap using `agy agentapi send-message`, which needs `ANTIGRAVITY_LS_ADDRESS` and `ANTIGRAVITY_CSRF_TOKEN`. `agy` gives those only to its agent's shell tool, never to MCP servers, so each conversation has to be **primed** once:
179
+
180
+ 1. The agent calls the `enable_push` tool, which returns a shell command (`bridge-mcp --prime`).
181
+ 2. The agent runs that command in its shell tool. It reads its own `ANTIGRAVITY_*` environment and hands it to its bridge over a `0600` control socket (`<bridge socket>.ctl`). The token is kept in memory only and passed to `agy` through the child's environment, never argv, logs or disk.
182
+ 3. From then on every inbound message makes the bridge run `agy agentapi send-message` with a fixed notice ("N new message(s) in your bridge inbox, call `read_messages`"). No sender-written text is injected. Bursts are coalesced into one notice, and a push counts as delivered only when agy's reply names the conversation (`response.sendMessage.recipientId`); an unconfirmed push is recorded as an error and never resent.
183
+
184
+ Optional: set `AGY_WAKEUP_PIN_AGY=1` to also pin the agy process that was primed (pid plus start time). The bridge then stops pushing and drops the stored credential once that process has ended or its pid has been reused.
185
+
186
+ The bridge never edits agy's settings. If you want agy to stop asking before it runs the prime command, add a `command(...)` rule for it yourself (see agy's Permissions documentation); `~/.claude/chatter-bin/bridge-mcp` is the stable path to use.
187
+
188
+ With the plugin installed, the `PreInvocation` hook (`bridge-mcp --prime-hook`) asks `agy` to run the priming command for any conversation that isn't primed yet, so the agent doesn't have to decide to. Whether `agy` honours that injected step is not yet verified; `rules/claude-chatter.md` and the `read_messages` `push_hint` are the fallbacks.
189
+
190
+ ---
191
+
192
+ ## 🧰 MCP Tool Reference
193
+
194
+ The MCP server exposes these tools:
195
+
196
+ ### 1. `list_sessions`
197
+ Scans Claude Code workspace configurations, cleans up orphaned/dead session files, and returns all active Claude sessions (name, pid, session ID, socket, cwd, kind, status). Auth tokens are not included in the output.
198
+ * **Arguments**: None
199
+
200
+ ### 2. `list_jobs`
201
+ Reads `~/.claude/jobs/*/state.json` and returns one entry per background job, finished ones included: `state`, `detail`, `output` (the final result text the fleet list shows), `needs`, PR `children`, `cwd`, worktree path/branch, last timeline entry, transcript path and mtime (the path only; the file is never read), `running` (the daemon roster has a live worker for the job), `live` (pid/kind/status when a session process is attached via `jobId`), and `pr_state` per PR link from Claude Code's `gh-pr-status-cache.json`. Read-only; also `bridge-mcp --jobs`.
202
+ * **Arguments**: None
203
+
204
+ ### 3. `send_message`
205
+ Dispatches an authenticated user message frame to a target Claude Code session. Fire-and-forget: returns as soon as the message is delivered. Any real reply the target sends back arrives later as its own inbound message, observable via `get_responses`.
206
+ * **Arguments**:
207
+ * `session` (string, required): Target session name (e.g. `rgle`), PID, or Session ID.
208
+ * `message` (string, required): Text message content to deliver.
209
+
210
+ ### 4. `read_messages`
211
+ Returns unread inbound messages (oldest first), keyed by message ID, and marks them read. Inbound and outbound messages are persisted in a local SQLite database (`~/.claude/chatter-messages.db`), so unread messages and message history survive bridge and host restarts. Push can wake a primed Antigravity session when one arrives, but it is best effort, so also call this periodically or after a `tools/list_changed` notification.
212
+ * **Arguments**:
213
+ * `mark_read` (boolean, optional, default true): set false to peek without consuming.
214
+
215
+ ### 5. `get_responses`
216
+ Queries inbound and outbound message history persisted across bridge restarts (newest first).
217
+ * **Arguments**:
218
+ * `msg_id` (string, optional): Specific message ID filter.
219
+ * `limit` (integer, optional): Maximum number of messages to return (newest first).
220
+ * `offset` (integer, optional, default 0): Number of messages to skip when paginating.
221
+
222
+ ### 6. `enable_push`
223
+ Returns the shell command that primes push for this conversation (see above) and whether push is already primed.
224
+ * **Arguments**: None
225
+
226
+ ### 7. `purge_sessions`
227
+ Manually triggers proactive scanning and deletion of dead socket descriptors and key files.
228
+ * **Arguments**: None
229
+
230
+ ### 8. `rename_session`
231
+ Renames this bridge's announced session descriptor in `~/.claude/sessions/` so surrounding Claude Code processes discover it under the new name via `ListAgents`. Tracks stable session identity and alias history in SQLite across renames, safely merging message histories without collisions. When renaming onto a session name with existing message history in storage, duplicate message IDs retain the renamed session's copy. Renaming is rejected if the target name is currently held by an active session.
232
+ * **Arguments**:
233
+ * `new_name` (string, required): The new session name to announce (e.g. `bridge-dev`). Without a rename, the name defaults to `<project basename>-<2 random alphanumerics>`, generated once and stored per project path in `~/.claude/chatter-session-names/`; a rename overwrites the stored name. Under `agy` the project path is the agy process's working directory, because `agy` does not expose its conversation title to MCP servers, the shell environment or the status line payload (requested upstream: [google-antigravity/antigravity-cli#1415](https://github.com/google-antigravity/antigravity-cli/issues/1415)). Override with `--name` or `CHATTER_SESSION_NAME`.
234
+
235
+ ---
236
+
237
+ ## 🖥️ Standalone Daemon & CLI Mode
238
+
239
+ In addition to standard stdio MCP mode, `bridge_mcp.py` can be launched in **standalone mode** (as a persistent background daemon or command-line execution tool):
240
+
241
+ ### Standalone Daemon Server
242
+ Run the bridge as a background service without stdio MCP binding:
243
+ ```bash
244
+ bridge-mcp --standalone --name custom-bridge-name
245
+ ```
246
+ Or with `python3`:
247
+ ```bash
248
+ python3 bridge_mcp.py --standalone --name custom-bridge-name
249
+ ```
250
+
251
+ ### Command-Line Execution Tools
252
+ Execute single-shot operations directly from terminal:
253
+
254
+ * **List Active Sessions**:
255
+ ```bash
256
+ bridge-mcp --list
257
+ ```
258
+ * **Proactively Purge Dead Sessions**:
259
+ ```bash
260
+ bridge-mcp --purge
261
+ ```
262
+ * **List Background Jobs** (finished ones included; read-only apart from the session scan that precedes it):
263
+ ```bash
264
+ bridge-mcp --jobs
265
+ ```
266
+ * **Check Inbox** (displays unread inbound messages without marking them read):
267
+ ```bash
268
+ bridge-mcp --inbox
269
+ ```
270
+ * **View Message History**:
271
+ ```bash
272
+ bridge-mcp --history
273
+ ```
274
+ * **Send Message to Session** (fire-and-forget; any reply arrives later as its own inbound message):
275
+ ```bash
276
+ bridge-mcp --send rgle "Hello from CLI"
277
+ ```
278
+
279
+ ---
280
+
281
+ ## 🔧 Operations, Security and Limits
282
+
283
+ **Files the bridge reads or writes** (all under `~/.claude/`):
284
+ * `sessions/` - Claude Code's session descriptors and `.key` files; the bridge reads them and writes its own descriptor and key.
285
+ * `chatter-messages.db` - SQLite database storing inbound and outbound messages, tracking read/unread status across bridge restarts. Mode 0600. Read and outbound messages are kept for 30 days (capped at 1,000 per session); unread inbound messages are preserved up to 90 days. In SQLite WAL mode, read-only inspect commands (`--inbox`, `--history`) access the database with `mode=ro` and do not alter stored data, though SQLite may create empty `.db-wal` and `.db-shm` files for WAL index coordination.
286
+ * `logs/claude-chatter.log` - shared by all bridge processes (also written to stderr); rotates at 5 MiB, 3 backups.
287
+ * `chatter-session-names/` - the generated or renamed session name and stable session ID per project path.
288
+ * `chatter-primed/` - which Antigravity conversations are primed for push, plus a retry marker (a failed priming is retried after 10 minutes).
289
+ * `chatter-bin/bridge-mcp` - a stable symlink to this install, so the prime command can be allow-listed.
290
+
291
+ **Settings:** `--name` or `CHATTER_SESSION_NAME` (alias `AGY_SESSION_NAME`) sets the session name; `--socket` or `CHATTER_BRIDGE_SOCKET` (alias `AGY_MCP_BRIDGE_SOCKET`) sets the bridge socket. `AGY_WAKEUP_PIN_AGY=1` turns on agy process pinning (see the push section; off by default).
292
+
293
+ **Security model:**
294
+ * Peer tokens are read from each session's `.key` file and only used to authenticate outbound frames. `list_sessions` and `--list` do not print them.
295
+ * The bridge's own key file and its sockets are created with `0600` permissions.
296
+ * The Antigravity token used for push is held in memory only, passed to `agy` through its environment (never argv, logs or disk), and only accepted together with a loopback address.
297
+ * Push injects a fixed notice, never text written by the sender.
298
+
299
+ **Limits:**
300
+ * The bridge works on the real `~/.claude`, which is why it runs host-native and only the tests run in a container with an isolated home.
301
+ * Developed on Linux: the default socket directory is `/run/user/<uid>/cc-socks` (fallback `/tmp/cc-socks`), and process start time and PID namespace come from `/proc` and `/etc/machine-id`, with placeholder values when those are unreadable.
302
+ * `list_jobs` reads Claude Code's own job, roster and PR-cache files. Their layout is not a documented interface and may change; unparseable files are skipped.
303
+ * Replies are asynchronous, and an idle Claude Code session may not answer until someone prompts it.
304
+ * Push is best effort; keep calling `read_messages`. See [docs/agy-notes.md](https://github.com/non7top/claude-chatter-mcp/blob/master/docs/agy-notes.md) for the Antigravity details.
305
+
306
+ ---
307
+
308
+ ## ⚙️ Running Tests
309
+
310
+ Run the included unit and integration test suites in a disposable non-root container:
311
+
312
+ ```bash
313
+ make test
314
+ ```
315
+
316
+ This runs `test_suite.py` (MCP server, CLI) and `test_agy_wakeup.py` (the `agy_wakeup` package). The protocol and storage tests live in the `claude-chatter` library.
317
+
318
+ ---
319
+
320
+ ## 📄 License
321
+
322
+ MIT License. See [LICENSE](https://github.com/non7top/claude-chatter-mcp/blob/master/LICENSE) for details.
@@ -0,0 +1,292 @@
1
+ # claude-chatter-mcp bridge
2
+
3
+ `claude-chatter-mcp` lets MCP-compatible agents (built for **Google Antigravity**) exchange messages with Claude Code sessions. It speaks Claude Code's peer-messaging protocol (`SendMessage`/`ListAgents`): the bridge announces itself as a session and talks to other sessions over their Unix sockets. Non-blocking and authenticated.
4
+
5
+ It ships three ways: as a plain MCP server (`bridge-mcp`), as a standalone daemon/CLI, and as an **Antigravity CLI (`agy`) plugin** that bundles the MCP server, a `PreInvocation` hook that primes push, a rules file and the `chatter` skill (see [Option 5](#option-5-antigravity-plugin-mcp-server--push-priming)).
6
+
7
+ ## Packages
8
+
9
+ This distribution installs two Python packages on top of the [`claude-chatter`](https://pypi.org/project/claude-chatter/) library:
10
+
11
+ | Package | What it does |
12
+ | --- | --- |
13
+ | `claude-chatter` (separate PyPI library, a dependency) | The peer-messaging protocol: session discovery, socket transport, SQLite mailbox, jobs, and the `claude-chatter` / `chatter` CLI. |
14
+ | `claude_chatter_mcp` | The MCP server and the `bridge-mcp` command. The plain CLI modes (`--list`, `--send`, `--inbox`, ...) are served by the library's CLI. |
15
+ | `agy_wakeup` | Waking an idle Antigravity conversation: the prime command, the `PreInvocation` hook, the shell-side primer, the control socket and the `agentapi send-message` call. It does not import `claude_chatter_mcp`; `claude_chatter_mcp/agy_glue.py` configures it for this bridge. The `agy-wakeup` command exposes its `--prime` and `--prime-hook` modes. |
16
+
17
+ ## 🚀 Key Features
18
+
19
+ * **Session Discovery & Automatic Purging**: Scans local workspace configurations (`~/.claude/sessions/*.json`), verifies process lifecycles via PID tracking (`psutil`), and automatically purges orphaned session descriptors and stale `.key` credential files.
20
+ * **Authenticated Unix Socket IPC**: Authenticates outbound message frames directly into active target session sockets (`/run/user/<uid>/cc-socks/*.sock`) using the `peerToken` read from each session's `.key` file.
21
+ * **Fire-and-Forget Message Dispatch**: `send_message`/`--send` dispatches and returns immediately; a real reply, if the target sends one, arrives later as its own inbound message rather than being synchronously extracted from a transcript file.
22
+ * **Dedicated Inbound Unix Socket Listener**: Listens on a per-session socket (default `/run/user/<uid>/cc-socks/bridge-<name>.sock`, falling back to `/tmp/cc-socks/`; override with `--socket` or `CHATTER_BRIDGE_SOCKET`; single-user `0600` permissions) for real-time peer confirmations and inbound message buffering.
23
+ * **Push to Antigravity**: `enable_push` / `bridge-mcp --prime` lets an inbound message wake an idle `agy` conversation through `agy agentapi send-message`, so the agent does not have to poll `read_messages` (see [Waking an idle Antigravity session](#-waking-an-idle-antigravity-session-push)).
24
+ * **Background Job Listing**: `list_jobs` / `--jobs` reads `~/.claude/jobs` to report every background job, including finished ones that have no live process, with state, result text, PR states, worktree, running status and transcript path.
25
+ * **Graceful Lifecycle & Signal Handling**: Catches `SIGTERM` and `SIGINT` signals to cleanly unbind sockets and exit with status code `0`, avoiding process termination errors during MCP server reloads.
26
+
27
+ ---
28
+
29
+ ## 🛠️ Architecture
30
+
31
+ ```
32
+ ┌──────────────────────┐ ┌──────────────────────┐
33
+ │ Google Antigravity │ │ Claude Code │
34
+ │ (Prose / agy) │ │ (Execution / CLI) │
35
+ └──────────┬───────────┘ └──────────▲───────────┘
36
+ │ │
37
+ (MCP Tool Calls) (Pushed NDJSON Stream)
38
+ │ │
39
+ ┌──────────▼────────────────────────────────────┴───────────┐
40
+ │ SOCKET BRIDGE MCP SERVER │
41
+ │ ┌───────────────────────┐ ┌─────────────────────────┐ │
42
+ │ │ Response History Cache│ │ Active Session Monitor │ │
43
+ │ │ (In-Memory) │ │ (Dead Socket Purging) │ │
44
+ │ └───────────────────────┘ └─────────────────────────┘ │
45
+ │ ┌───────────────────────┐ ┌─────────────────────────┐ │
46
+ │ │ Inbound IPC Server │ │ Outbound Socket Manager │ │
47
+ │ │ Listener Daemon │ │ (Key-Authenticated) │ │
48
+ │ └───────────────────────┘ └─────────────────────────┘ │
49
+ └───────────────────────────────────────────────────────────┘
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 📦 Installation & Setup
55
+
56
+ ### Option 1: From PyPI
57
+
58
+ ```bash
59
+ # Zero-installation, register with Antigravity CLI (agy):
60
+ agy mcp add claudemessaging uvx --from claude-chatter-mcp bridge-mcp
61
+
62
+ # Or install the commands permanently (bridge-mcp, agy-wakeup, claude-chatter, chatter):
63
+ uv tool install claude-chatter-mcp
64
+ # or: pipx install claude-chatter-mcp
65
+ agy mcp add claudemessaging bridge-mcp
66
+ ```
67
+
68
+ Requires Python 3.10 or newer. POSIX only, developed on Linux; see Limits below.
69
+
70
+ ---
71
+
72
+ ### Option 2: Via `uvx` or `uv tool run` from GitHub (Zero-Installation / Ephemeral)
73
+
74
+ Register directly with **Antigravity CLI (`agy`)** from GitHub without cloning:
75
+
76
+ **Using `uvx`:**
77
+ ```bash
78
+ agy mcp add claudemessaging uvx --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
79
+ ```
80
+
81
+ **Using `uv tool run`:**
82
+ ```bash
83
+ agy mcp add claudemessaging uv tool run --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
84
+ ```
85
+
86
+ Or run directly in terminal:
87
+ ```bash
88
+ uvx --from git+https://github.com/non7top/claude-chatter-mcp.git bridge-mcp
89
+ ```
90
+
91
+ ---
92
+
93
+ ### Option 3: Permanent Tool Installation from GitHub (`uv tool install`)
94
+
95
+ Install the `bridge-mcp` binary permanently into your system path using `uv`:
96
+
97
+ ```bash
98
+ # 1. Install tool permanently into ~/.local/bin (or uv tool path)
99
+ uv tool install git+https://github.com/non7top/claude-chatter-mcp.git
100
+
101
+ # 2. Register with Antigravity CLI
102
+ agy mcp add claudemessaging bridge-mcp
103
+ ```
104
+
105
+ ---
106
+
107
+ ### Option 4: Local Repository Installation
108
+
109
+ 1. **Clone the repository**:
110
+ ```bash
111
+ git clone https://github.com/non7top/claude-chatter-mcp.git
112
+ cd claude-chatter-mcp
113
+ ```
114
+
115
+ 2. **Register with Antigravity CLI (`agy`) using `uv` / `uvx`**:
116
+ ```bash
117
+ agy mcp add claudemessaging uvx --from . bridge-mcp
118
+ ```
119
+
120
+ 3. **Or register with standard `python3`**:
121
+ ```bash
122
+ agy mcp add claudemessaging python3 $(pwd)/bridge_mcp.py
123
+ ```
124
+
125
+ 4. **Verify registration**:
126
+ ```bash
127
+ agy mcp list
128
+ ```
129
+
130
+ ---
131
+
132
+ ### Option 5: Antigravity plugin (MCP server + push priming)
133
+
134
+ This repo is also an Antigravity CLI plugin: `plugin.json`, `mcp_config.json` (the MCP server), `hooks.json` (a `PreInvocation` hook that primes push, see below) and `rules/claude-chatter.md`.
135
+
136
+ ```bash
137
+ agy plugin install https://github.com/non7top/claude-chatter-mcp
138
+ ```
139
+
140
+ Only `uv` needs to be installed: the plugin's MCP server and hook run `uvx --from git+https://github.com/non7top/claude-chatter-mcp bridge-mcp`, which fetches and caches the bridge on first use.
141
+
142
+ If you registered the server by hand earlier (`agy mcp add ...`), remove it so the plugin's copy is the only one.
143
+
144
+ ---
145
+
146
+ ## 🔔 Waking an idle Antigravity session (push)
147
+
148
+ `agy` cannot be woken by an MCP server, so by default it only sees inbound messages when it calls `read_messages`. Push closes that gap using `agy agentapi send-message`, which needs `ANTIGRAVITY_LS_ADDRESS` and `ANTIGRAVITY_CSRF_TOKEN`. `agy` gives those only to its agent's shell tool, never to MCP servers, so each conversation has to be **primed** once:
149
+
150
+ 1. The agent calls the `enable_push` tool, which returns a shell command (`bridge-mcp --prime`).
151
+ 2. The agent runs that command in its shell tool. It reads its own `ANTIGRAVITY_*` environment and hands it to its bridge over a `0600` control socket (`<bridge socket>.ctl`). The token is kept in memory only and passed to `agy` through the child's environment, never argv, logs or disk.
152
+ 3. From then on every inbound message makes the bridge run `agy agentapi send-message` with a fixed notice ("N new message(s) in your bridge inbox, call `read_messages`"). No sender-written text is injected. Bursts are coalesced into one notice, and a push counts as delivered only when agy's reply names the conversation (`response.sendMessage.recipientId`); an unconfirmed push is recorded as an error and never resent.
153
+
154
+ Optional: set `AGY_WAKEUP_PIN_AGY=1` to also pin the agy process that was primed (pid plus start time). The bridge then stops pushing and drops the stored credential once that process has ended or its pid has been reused.
155
+
156
+ The bridge never edits agy's settings. If you want agy to stop asking before it runs the prime command, add a `command(...)` rule for it yourself (see agy's Permissions documentation); `~/.claude/chatter-bin/bridge-mcp` is the stable path to use.
157
+
158
+ With the plugin installed, the `PreInvocation` hook (`bridge-mcp --prime-hook`) asks `agy` to run the priming command for any conversation that isn't primed yet, so the agent doesn't have to decide to. Whether `agy` honours that injected step is not yet verified; `rules/claude-chatter.md` and the `read_messages` `push_hint` are the fallbacks.
159
+
160
+ ---
161
+
162
+ ## 🧰 MCP Tool Reference
163
+
164
+ The MCP server exposes these tools:
165
+
166
+ ### 1. `list_sessions`
167
+ Scans Claude Code workspace configurations, cleans up orphaned/dead session files, and returns all active Claude sessions (name, pid, session ID, socket, cwd, kind, status). Auth tokens are not included in the output.
168
+ * **Arguments**: None
169
+
170
+ ### 2. `list_jobs`
171
+ Reads `~/.claude/jobs/*/state.json` and returns one entry per background job, finished ones included: `state`, `detail`, `output` (the final result text the fleet list shows), `needs`, PR `children`, `cwd`, worktree path/branch, last timeline entry, transcript path and mtime (the path only; the file is never read), `running` (the daemon roster has a live worker for the job), `live` (pid/kind/status when a session process is attached via `jobId`), and `pr_state` per PR link from Claude Code's `gh-pr-status-cache.json`. Read-only; also `bridge-mcp --jobs`.
172
+ * **Arguments**: None
173
+
174
+ ### 3. `send_message`
175
+ Dispatches an authenticated user message frame to a target Claude Code session. Fire-and-forget: returns as soon as the message is delivered. Any real reply the target sends back arrives later as its own inbound message, observable via `get_responses`.
176
+ * **Arguments**:
177
+ * `session` (string, required): Target session name (e.g. `rgle`), PID, or Session ID.
178
+ * `message` (string, required): Text message content to deliver.
179
+
180
+ ### 4. `read_messages`
181
+ Returns unread inbound messages (oldest first), keyed by message ID, and marks them read. Inbound and outbound messages are persisted in a local SQLite database (`~/.claude/chatter-messages.db`), so unread messages and message history survive bridge and host restarts. Push can wake a primed Antigravity session when one arrives, but it is best effort, so also call this periodically or after a `tools/list_changed` notification.
182
+ * **Arguments**:
183
+ * `mark_read` (boolean, optional, default true): set false to peek without consuming.
184
+
185
+ ### 5. `get_responses`
186
+ Queries inbound and outbound message history persisted across bridge restarts (newest first).
187
+ * **Arguments**:
188
+ * `msg_id` (string, optional): Specific message ID filter.
189
+ * `limit` (integer, optional): Maximum number of messages to return (newest first).
190
+ * `offset` (integer, optional, default 0): Number of messages to skip when paginating.
191
+
192
+ ### 6. `enable_push`
193
+ Returns the shell command that primes push for this conversation (see above) and whether push is already primed.
194
+ * **Arguments**: None
195
+
196
+ ### 7. `purge_sessions`
197
+ Manually triggers proactive scanning and deletion of dead socket descriptors and key files.
198
+ * **Arguments**: None
199
+
200
+ ### 8. `rename_session`
201
+ Renames this bridge's announced session descriptor in `~/.claude/sessions/` so surrounding Claude Code processes discover it under the new name via `ListAgents`. Tracks stable session identity and alias history in SQLite across renames, safely merging message histories without collisions. When renaming onto a session name with existing message history in storage, duplicate message IDs retain the renamed session's copy. Renaming is rejected if the target name is currently held by an active session.
202
+ * **Arguments**:
203
+ * `new_name` (string, required): The new session name to announce (e.g. `bridge-dev`). Without a rename, the name defaults to `<project basename>-<2 random alphanumerics>`, generated once and stored per project path in `~/.claude/chatter-session-names/`; a rename overwrites the stored name. Under `agy` the project path is the agy process's working directory, because `agy` does not expose its conversation title to MCP servers, the shell environment or the status line payload (requested upstream: [google-antigravity/antigravity-cli#1415](https://github.com/google-antigravity/antigravity-cli/issues/1415)). Override with `--name` or `CHATTER_SESSION_NAME`.
204
+
205
+ ---
206
+
207
+ ## 🖥️ Standalone Daemon & CLI Mode
208
+
209
+ In addition to standard stdio MCP mode, `bridge_mcp.py` can be launched in **standalone mode** (as a persistent background daemon or command-line execution tool):
210
+
211
+ ### Standalone Daemon Server
212
+ Run the bridge as a background service without stdio MCP binding:
213
+ ```bash
214
+ bridge-mcp --standalone --name custom-bridge-name
215
+ ```
216
+ Or with `python3`:
217
+ ```bash
218
+ python3 bridge_mcp.py --standalone --name custom-bridge-name
219
+ ```
220
+
221
+ ### Command-Line Execution Tools
222
+ Execute single-shot operations directly from terminal:
223
+
224
+ * **List Active Sessions**:
225
+ ```bash
226
+ bridge-mcp --list
227
+ ```
228
+ * **Proactively Purge Dead Sessions**:
229
+ ```bash
230
+ bridge-mcp --purge
231
+ ```
232
+ * **List Background Jobs** (finished ones included; read-only apart from the session scan that precedes it):
233
+ ```bash
234
+ bridge-mcp --jobs
235
+ ```
236
+ * **Check Inbox** (displays unread inbound messages without marking them read):
237
+ ```bash
238
+ bridge-mcp --inbox
239
+ ```
240
+ * **View Message History**:
241
+ ```bash
242
+ bridge-mcp --history
243
+ ```
244
+ * **Send Message to Session** (fire-and-forget; any reply arrives later as its own inbound message):
245
+ ```bash
246
+ bridge-mcp --send rgle "Hello from CLI"
247
+ ```
248
+
249
+ ---
250
+
251
+ ## 🔧 Operations, Security and Limits
252
+
253
+ **Files the bridge reads or writes** (all under `~/.claude/`):
254
+ * `sessions/` - Claude Code's session descriptors and `.key` files; the bridge reads them and writes its own descriptor and key.
255
+ * `chatter-messages.db` - SQLite database storing inbound and outbound messages, tracking read/unread status across bridge restarts. Mode 0600. Read and outbound messages are kept for 30 days (capped at 1,000 per session); unread inbound messages are preserved up to 90 days. In SQLite WAL mode, read-only inspect commands (`--inbox`, `--history`) access the database with `mode=ro` and do not alter stored data, though SQLite may create empty `.db-wal` and `.db-shm` files for WAL index coordination.
256
+ * `logs/claude-chatter.log` - shared by all bridge processes (also written to stderr); rotates at 5 MiB, 3 backups.
257
+ * `chatter-session-names/` - the generated or renamed session name and stable session ID per project path.
258
+ * `chatter-primed/` - which Antigravity conversations are primed for push, plus a retry marker (a failed priming is retried after 10 minutes).
259
+ * `chatter-bin/bridge-mcp` - a stable symlink to this install, so the prime command can be allow-listed.
260
+
261
+ **Settings:** `--name` or `CHATTER_SESSION_NAME` (alias `AGY_SESSION_NAME`) sets the session name; `--socket` or `CHATTER_BRIDGE_SOCKET` (alias `AGY_MCP_BRIDGE_SOCKET`) sets the bridge socket. `AGY_WAKEUP_PIN_AGY=1` turns on agy process pinning (see the push section; off by default).
262
+
263
+ **Security model:**
264
+ * Peer tokens are read from each session's `.key` file and only used to authenticate outbound frames. `list_sessions` and `--list` do not print them.
265
+ * The bridge's own key file and its sockets are created with `0600` permissions.
266
+ * The Antigravity token used for push is held in memory only, passed to `agy` through its environment (never argv, logs or disk), and only accepted together with a loopback address.
267
+ * Push injects a fixed notice, never text written by the sender.
268
+
269
+ **Limits:**
270
+ * The bridge works on the real `~/.claude`, which is why it runs host-native and only the tests run in a container with an isolated home.
271
+ * Developed on Linux: the default socket directory is `/run/user/<uid>/cc-socks` (fallback `/tmp/cc-socks`), and process start time and PID namespace come from `/proc` and `/etc/machine-id`, with placeholder values when those are unreadable.
272
+ * `list_jobs` reads Claude Code's own job, roster and PR-cache files. Their layout is not a documented interface and may change; unparseable files are skipped.
273
+ * Replies are asynchronous, and an idle Claude Code session may not answer until someone prompts it.
274
+ * Push is best effort; keep calling `read_messages`. See [docs/agy-notes.md](https://github.com/non7top/claude-chatter-mcp/blob/master/docs/agy-notes.md) for the Antigravity details.
275
+
276
+ ---
277
+
278
+ ## ⚙️ Running Tests
279
+
280
+ Run the included unit and integration test suites in a disposable non-root container:
281
+
282
+ ```bash
283
+ make test
284
+ ```
285
+
286
+ This runs `test_suite.py` (MCP server, CLI) and `test_agy_wakeup.py` (the `agy_wakeup` package). The protocol and storage tests live in the `claude-chatter` library.
287
+
288
+ ---
289
+
290
+ ## 📄 License
291
+
292
+ MIT License. See [LICENSE](https://github.com/non7top/claude-chatter-mcp/blob/master/LICENSE) for details.
@@ -0,0 +1,6 @@
1
+ """
2
+ Wake an idle Antigravity (agy) conversation from another process.
3
+
4
+ Kept free of imports on purpose: the PreInvocation hook runs before every model
5
+ invocation and must stay cheap.
6
+ """