@openbone/mcp 0.4.3 → 0.4.5

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/bridge.js CHANGED
@@ -8,13 +8,18 @@ import { isLocalRequest } from "./local-only.js";
8
8
  * agent appear instantly in the editor, and edits made in the editor are visible to the agent.
9
9
  *
10
10
  * Messages (JSON):
11
- * editor → server: {type:"hello"} | {type:"op", op, args} | {type:"undo"} | {type:"redo"} | {type:"load", doc}
12
- * server → editor: {type:"load", doc, path} | {type:"ops", ops} | {type:"error", message}
11
+ * editor → server: {type:"hello", doc?} | {type:"op", op, args} | {type:"undo"} | {type:"redo"} | {type:"load", doc}
12
+ * server → editor: {type:"load", doc, path} | {type:"synced"} (took over the hello's scene) | {type:"ops", ops} | {type:"error", message}
13
13
  * | {type:"files", files:[{src, kind, mime, base64}]}
14
14
  *
15
15
  * The server stores imported art and sound as paths relative to the project file, which the editor (a web page, or
16
16
  * the desktop app without that project open) can't read. So before the document or ops that use such a path, the
17
17
  * server sends the file's bytes ("files"), and the editor shows and plays them from memory.
18
+ *
19
+ * Connecting never replaces the editor's scene with an empty one: the editor's hello carries its document, and a
20
+ * server that has no project yet (nothing created, opened or edited) takes it over, answers "synced" and waits for the
21
+ * agent. A server already working on a project sends that project, and the editor asks whether to open it or send its
22
+ * own scene ("load", which detaches the server from its project file so autosave never overwrites it).
18
23
  */
19
24
  const MEDIA = {
20
25
  ttf: { kind: "font", mime: "font/ttf" },
@@ -108,13 +113,11 @@ export function startBridge(session, port, log) {
108
113
  if (e.kind === "op" || e.kind === "transaction")
109
114
  broadcast({ type: "ops", ops: e.ops }, except);
110
115
  else
111
- broadcast({ type: "load", doc, path: session.filePath });
116
+ broadcast({ type: "load", doc, path: session.filePath }, except);
112
117
  });
113
118
  wss.on("connection", (ws) => {
114
119
  clients.add(ws);
115
120
  log(`editor connected (${clients.size})`);
116
- sendFiles(ws);
117
- send(ws, { type: "load", doc: session.doc, path: session.filePath });
118
121
  ws.on("close", () => clients.delete(ws));
119
122
  ws.on("message", async (raw) => {
120
123
  let msg;
@@ -128,8 +131,15 @@ export function startBridge(session, port, log) {
128
131
  try {
129
132
  if (msg.type === "hello") {
130
133
  sentFiles.delete(ws); // a fresh editor page: send every file again
131
- sendFiles(ws);
132
- send(ws, { type: "load", doc: session.doc, path: session.filePath });
134
+ if (msg.doc && session.pristine) {
135
+ session.store.load(msg.doc, "bridge");
136
+ send(ws, { type: "synced" });
137
+ log("bridge: took over the editor's open project");
138
+ }
139
+ else {
140
+ sendFiles(ws);
141
+ send(ws, { type: "load", doc: session.doc, path: session.filePath });
142
+ }
133
143
  }
134
144
  else if (msg.type === "op" && msg.op)
135
145
  session.store.apply(msg.op, msg.args ?? {}, "bridge");
@@ -137,8 +147,11 @@ export function startBridge(session, port, log) {
137
147
  session.store.undo();
138
148
  else if (msg.type === "redo")
139
149
  session.store.redo();
140
- else if (msg.type === "load" && msg.doc)
141
- session.store.load(msg.doc);
150
+ else if (msg.type === "load" && msg.doc) {
151
+ // The editor's scene, not the project file the server had open: never autosave it over that file.
152
+ session.filePath = null;
153
+ session.store.load(msg.doc, "bridge");
154
+ }
142
155
  await session.maybeAutosave();
143
156
  }
144
157
  catch (e) {
package/dist/server.js CHANGED
@@ -30,7 +30,7 @@ export function createServer(opts = {}) {
30
30
  const session = opts.session ?? new ProjectSession();
31
31
  let host = opts.scriptHost;
32
32
  const scriptHost = async () => (host ??= await createQuickJsHost({ timeoutMs: 50 }));
33
- const server = new McpServer({ name: "openbone", version: "0.4.3" }, {
33
+ const server = new McpServer({ name: "openbone", version: "0.4.5" }, {
34
34
  instructions: "OpenBone: 2D skeletal animation + interactive state machines. Read the openbone://guide resource (or call get_guide) first. Start with new_project or open_project; edit with the add_*/update_*/set_keys tools; verify with render_frame and simulate_state_machine.",
35
35
  });
36
36
  // ---------- Generated edit tools (one per core op) ----------
package/dist/session.d.ts CHANGED
@@ -5,6 +5,10 @@ export declare class ProjectSession {
5
5
  store: DocumentStore;
6
6
  filePath: string | null;
7
7
  autosave: boolean;
8
+ /** Nothing has happened yet: no project created or opened, no edit. An editor that connects now keeps its scene. */
9
+ private touched;
10
+ constructor();
11
+ get pristine(): boolean;
8
12
  get doc(): OpenBoneDocument;
9
13
  get baseDir(): string;
10
14
  newProject(name: string, filePath: string | null, opts?: Partial<OpenBoneDocument>): void;
package/dist/session.js CHANGED
@@ -6,6 +6,16 @@ export class ProjectSession {
6
6
  store = new DocumentStore(createDocument("Untitled"));
7
7
  filePath = null;
8
8
  autosave = true;
9
+ /** Nothing has happened yet: no project created or opened, no edit. An editor that connects now keeps its scene. */
10
+ touched = false;
11
+ constructor() {
12
+ this.store.subscribe(() => {
13
+ this.touched = true;
14
+ });
15
+ }
16
+ get pristine() {
17
+ return !this.touched && this.filePath === null;
18
+ }
9
19
  get doc() {
10
20
  return this.store.doc;
11
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openbone/mcp",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "MCP server for OpenBone: let AI agents rig, animate and wire up interactive skeletal animations",
5
5
  "keywords": [
6
6
  "openbone",
@@ -52,12 +52,12 @@
52
52
  "gifenc": "^1.0.3",
53
53
  "ws": "^8.18.0",
54
54
  "zod": "^4.1.0",
55
- "@openbone/core": "0.4.3",
56
- "@openbone/export": "0.4.3",
57
- "@openbone/player": "0.4.3",
58
- "@openbone/render-canvas": "0.4.3",
59
- "@openbone/scripting": "0.4.3",
60
- "@openbone/runtime": "0.4.3"
55
+ "@openbone/player": "0.4.5",
56
+ "@openbone/export": "0.4.5",
57
+ "@openbone/core": "0.4.5",
58
+ "@openbone/runtime": "0.4.5",
59
+ "@openbone/render-canvas": "0.4.5",
60
+ "@openbone/scripting": "0.4.5"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/ws": "^8.18.1"