@abraca/mcp 2.49.0 → 2.51.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/mcp",
3
- "version": "2.49.0",
3
+ "version": "2.51.0",
4
4
  "description": "MCP server for Abracadabra — AI agent collaboration on CRDT documents",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "y-protocols": "^1.0.6",
36
36
  "yjs": "^13.6.8",
37
37
  "zod": "^4.3.6",
38
- "@abraca/convert": "2.49.0"
38
+ "@abraca/convert": "2.51.0"
39
39
  },
40
40
  "scripts": {
41
41
  "test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
@@ -144,6 +144,7 @@ export class HookBridge {
144
144
  private httpServer: http.Server | null = null;
145
145
  private _port: number | null = null;
146
146
  private portFilePath: string;
147
+ private portFileTimer: ReturnType<typeof setInterval> | null = null;
147
148
 
148
149
  constructor(private server: AbracadabraMCPServer) {
149
150
  // Stable, predictable path (NOT tmpdir) so the Claude Code hook command
@@ -180,14 +181,17 @@ export class HookBridge {
180
181
  this._port = addr.port;
181
182
  this.httpServer = srv;
182
183
 
183
- // Write port file for hook discovery
184
- try {
185
- fs.writeFileSync(this.portFilePath, String(this._port), "utf-8");
186
- } catch (err: any) {
187
- console.error(
188
- `[hook-bridge] Warning: could not write port file: ${err.message}`,
189
- );
190
- }
184
+ // Claim the shared port file, then re-assert it on an interval.
185
+ // Claude Code spawns this MCP server from .mcp.json for health
186
+ // checks; each transient spawn starts its OWN bridge on a fresh
187
+ // random port and overwrites (or, on exit, unlinks) the single
188
+ // shared port file — leaving the hook command pointing at a dead
189
+ // port. Periodically re-writing lets the long-lived serving
190
+ // instance reclaim the file within ~2s of any clobber, so the
191
+ // hook keeps resolving to a live bridge.
192
+ this.writePortFile();
193
+ this.portFileTimer = setInterval(() => this.writePortFile(), 2000);
194
+ this.portFileTimer.unref?.();
191
195
 
192
196
  console.error(`[hook-bridge] Listening on 127.0.0.1:${this._port}`);
193
197
  console.error(`[hook-bridge] Port file: ${this.portFilePath}`);
@@ -196,8 +200,26 @@ export class HookBridge {
196
200
  });
197
201
  }
198
202
 
203
+ /** Write the current listening port to the shared port file (best-effort). */
204
+ private writePortFile(): void {
205
+ if (this._port == null) return;
206
+ try {
207
+ fs.writeFileSync(this.portFilePath, String(this._port), "utf-8");
208
+ } catch (err: any) {
209
+ console.error(
210
+ `[hook-bridge] Warning: could not write port file: ${err.message}`,
211
+ );
212
+ }
213
+ }
214
+
199
215
  /** Shut down the HTTP server and remove the port file. */
200
216
  async destroy(): Promise<void> {
217
+ // Stop re-asserting the port file before we tear down.
218
+ if (this.portFileTimer) {
219
+ clearInterval(this.portFileTimer);
220
+ this.portFileTimer = null;
221
+ }
222
+
201
223
  if (this.httpServer) {
202
224
  await new Promise<void>((resolve) => {
203
225
  this.httpServer!.close(() => resolve());
@@ -205,9 +227,16 @@ export class HookBridge {
205
227
  this.httpServer = null;
206
228
  }
207
229
 
208
- // Remove port file
230
+ // Only remove the port file if it still points at THIS instance — never
231
+ // clobber a newer/long-lived instance's registration. A transient
232
+ // health-check spawn that overwrote the file must not delete the real
233
+ // serving instance's port on the way out (see start() for why concurrent
234
+ // instances exist).
209
235
  try {
210
- fs.unlinkSync(this.portFilePath);
236
+ const current = fs.readFileSync(this.portFilePath, "utf-8").trim();
237
+ if (current === String(this._port)) {
238
+ fs.unlinkSync(this.portFilePath);
239
+ }
211
240
  } catch {
212
241
  // Already gone or never written
213
242
  }