dsh-unity-mcp 0.0.7 → 0.0.8

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 (2) hide show
  1. package/lib/lazy-tools.mjs +15 -0
  2. package/package.json +1 -1
@@ -9,6 +9,9 @@ export function installLazyTools(ctx, lazy = true, setupTools = []) {
9
9
  if (states.has(agent)) return;
10
10
  const state = { loaded: !lazy, signature: '', disposers: [], tools: [] };
11
11
  const refresh = () => {
12
+ if (state.disposed || state.refreshing) return;
13
+ state.refreshing = true;
14
+ try {
12
15
  const raw = rawDefinitions();
13
16
  const defs = [...setupTools, ...createEngineTools(raw)], signature = JSON.stringify(defs.map(({ name, description, parameters }) => ({ name, description, parameters })));
14
17
  if (signature === state.signature && raw.length === state.raw?.length && raw.every((tool, i) => tool === state.raw[i])) return;
@@ -24,9 +27,12 @@ export function installLazyTools(ctx, lazy = true, setupTools = []) {
24
27
  state.tools.push(...installed);
25
28
  }
26
29
  state.signature = signature;
30
+ } finally { state.refreshing = false; }
27
31
  };
28
32
  state.refresh = refresh;
29
33
  state.dispose = agent.ctx.effect(() => () => {
34
+ state.disposed = true;
35
+ states.delete(agent);
30
36
  for (const dispose of state.tools.splice(0).reverse()) dispose();
31
37
  state.mask?.();
32
38
  for (const dispose of state.disposers.splice(0).reverse()) dispose();
@@ -46,6 +52,15 @@ export function installLazyTools(ctx, lazy = true, setupTools = []) {
46
52
  }));
47
53
  refresh();
48
54
  }
55
+ // MCP discovery completes asynchronously, potentially before the first pre-step.
56
+ // Own registrations/restrictions also emit tools/change: suppress nested refreshes.
57
+ let syncing = false;
58
+ ctx.on('tools/change', () => {
59
+ if (syncing) return;
60
+ syncing = true;
61
+ try { for (const state of states.values()) state.refresh(); }
62
+ finally { syncing = false; }
63
+ });
49
64
  ctx.on('agent/created', ({ agent }) => { attach(agent); });
50
65
  ctx.on('agent/pre-step', ({ agent }, next) => { attach(agent); states.get(agent).refresh(); return next(); });
51
66
  for (const agent of ctx.agents.list()) attach(agent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unity-mcp",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Unity and Tuanjie editor tools for DSH, powered by CoderGamester/mcp-unity with per-agent lazy loading.",
5
5
  "type": "module",
6
6
  "license": "MIT",