@abraca/mcp 2.48.0 → 2.50.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/dist/index.d.ts CHANGED
@@ -69,6 +69,14 @@ declare class AbracadabraMCPServer {
69
69
  * `kind === "space"`. Populated by {@link connect}.
70
70
  */
71
71
  get spaces(): DocumentMeta[];
72
+ /**
73
+ * Re-fetch the server's top-level `kind="space"` docs and refresh the
74
+ * cached `_spaces` snapshot. {@link connect} only takes the snapshot once,
75
+ * so a space created/seeded after connect (or removed) would otherwise stay
76
+ * invisible to `list_spaces` until a full reconnect. Tools that surface the
77
+ * space list should call this first so they reflect server truth.
78
+ */
79
+ refreshSpaces(): Promise<DocumentMeta[]>;
72
80
  get rootDocument(): Y.Doc | null;
73
81
  get rootYProvider(): AbracadabraProvider | null;
74
82
  get userId(): string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/mcp",
3
- "version": "2.48.0",
3
+ "version": "2.50.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.48.0"
38
+ "@abraca/convert": "2.50.0"
39
39
  },
40
40
  "scripts": {
41
41
  "test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
@@ -43,6 +43,7 @@ const DISCONNECTED: Record<string, unknown> = {
43
43
  // ── data accessors (called as functions) ──
44
44
  getTreeMap: () => null,
45
45
  getTrashMap: () => null,
46
+ refreshSpaces: async () => [],
46
47
  getDocSummary: () => null,
47
48
  getEnabledPluginNames: () => [],
48
49
 
@@ -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
  }
package/src/server.ts CHANGED
@@ -163,6 +163,25 @@ export class AbracadabraMCPServer {
163
163
  return this._spaces;
164
164
  }
165
165
 
166
+ /**
167
+ * Re-fetch the server's top-level `kind="space"` docs and refresh the
168
+ * cached `_spaces` snapshot. {@link connect} only takes the snapshot once,
169
+ * so a space created/seeded after connect (or removed) would otherwise stay
170
+ * invisible to `list_spaces` until a full reconnect. Tools that surface the
171
+ * space list should call this first so they reflect server truth.
172
+ */
173
+ async refreshSpaces(): Promise<DocumentMeta[]> {
174
+ if (!this.client) return this._spaces;
175
+ try {
176
+ const { spaces } = pickEntrySpace(await this.client.listChildren());
177
+ this._spaces = spaces;
178
+ } catch {
179
+ // Network/transient failure — keep the last-known snapshot rather
180
+ // than blanking the list.
181
+ }
182
+ return this._spaces;
183
+ }
184
+
166
185
  get rootDocument(): Y.Doc | null {
167
186
  return this._activeConnection?.doc ?? null;
168
187
  }
package/src/tools/tree.ts CHANGED
@@ -592,7 +592,10 @@ export function registerTreeTools(
592
592
  {},
593
593
  async () => {
594
594
  server.setActiveToolCall({ name: 'list_spaces' })
595
- const spaces = server.spaces
595
+ // Refresh from the server first — `_spaces` is otherwise a connect-time
596
+ // snapshot, so a space seeded/created (or removed) after connect would
597
+ // stay stale until a full reconnect (the "space disappeared" bug).
598
+ const spaces = await server.refreshSpaces()
596
599
  if (!spaces.length) {
597
600
  return { content: [{ type: 'text', text: 'No spaces available — create one to get started.' }] }
598
601
  }