@markasso/mcp 0.7.3 → 0.7.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/README.md CHANGED
@@ -15,6 +15,15 @@ Published on npm as [`@markasso/mcp`](https://www.npmjs.com/package/@markasso/mc
15
15
 
16
16
  **Claude Code**
17
17
 
18
+ The [Markasso plugin](https://github.com/AlbertoBarrago/markasso-plugin) adds this server and a `diagram` skill that tells Claude when to draw and how; it asks for the optional licence key and keeps it in the system's credential store:
19
+
20
+ ```bash
21
+ claude plugin marketplace add AlbertoBarrago/markasso-plugin
22
+ claude plugin install markasso@markasso
23
+ ```
24
+
25
+ Or the server alone:
26
+
18
27
  ```bash
19
28
  claude mcp add markasso -- npx -y @markasso/mcp@latest
20
29
  ```
@@ -70,9 +79,13 @@ pnpm mcp:build # → mcp/dist/markasso-mcp.js
70
79
 
71
80
  Then use `node /absolute/path/to/Markasso/mcp/dist/markasso-mcp.js` as the command in any of the configs above.
72
81
 
82
+ ## Registry
83
+
84
+ Listed in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.AlbertoBarrago/markasso` ([`server.json`](server.json)). The MCP release workflow publishes each version there after npm, so `server.json`'s two `version` fields must match `package.json` (the workflow checks it).
85
+
73
86
  ## Releasing
74
87
 
75
- Bump `version` in `mcp/package.json`, add the entry to `mcp/CHANGELOG.md`, merge, then push a `mcp-v<version>` tag: the `MCP Release` workflow tests, builds and publishes to npm (trusted publishing, with provenance) and creates a GitHub release.
88
+ Bump `version` in `mcp/package.json` and both `version` fields in `mcp/server.json`, add the entry to `mcp/CHANGELOG.md`, merge, then push a `mcp-v<version>` tag: the `MCP Release` workflow tests, builds and publishes to npm (trusted publishing, with provenance), then to the MCP Registry, and creates a GitHub release.
76
89
 
77
90
  ## Tools
78
91
 
@@ -4326,7 +4326,7 @@ function escapeXml(str) {
4326
4326
  }
4327
4327
  //#endregion
4328
4328
  //#region package.json
4329
- var version = "0.7.3";
4329
+ var version = "0.7.5";
4330
4330
  //#endregion
4331
4331
  //#region ../src/core/layout.ts
4332
4332
  /** Orders vertices without recursion, preserving input order when unconstrained. */
@@ -5340,7 +5340,7 @@ var History = class {
5340
5340
  this.drag = null;
5341
5341
  this.future = drag.future;
5342
5342
  rebaseIndices(drag.change, drag.sceneBefore, this._present);
5343
- this.revert(drag.change, "undo", drag.appStateBefore, drag.selectedIdsBefore);
5343
+ this.revert(drag.change, "undo", this._present.appState, drag.appStateBefore, drag.selectedIdsBefore);
5344
5344
  }
5345
5345
  /** Set/replace the outbound hook used to forward local commands (e.g. to a
5346
5346
  * realtime session), including the patches undo/redo produce. Ephemeral
@@ -5423,7 +5423,7 @@ var History = class {
5423
5423
  const entry = this.past.pop();
5424
5424
  if (!entry) return;
5425
5425
  this.future.push(entry);
5426
- this.revert(entry.change, "undo", entry.appStateBefore);
5426
+ this.revert(entry.change, "undo", entry.appStateAfter, entry.appStateBefore);
5427
5427
  }
5428
5428
  redo() {
5429
5429
  if (this.readOnly) return;
@@ -5434,7 +5434,7 @@ var History = class {
5434
5434
  const entry = this.future.pop();
5435
5435
  if (!entry) return;
5436
5436
  this.past.push(entry);
5437
- this.revert(entry.change, "redo", entry.appStateAfter);
5437
+ this.revert(entry.change, "redo", entry.appStateBefore, entry.appStateAfter);
5438
5438
  }
5439
5439
  canUndo() {
5440
5440
  return !this.readOnly && this.past.length > 0;
@@ -5451,25 +5451,18 @@ var History = class {
5451
5451
  notify() {
5452
5452
  for (const l of this.listeners) l(this._present);
5453
5453
  }
5454
- /** Move the scene across `change` (see buildRevertPatch), restore the local
5455
- * appState of that side, and broadcast the element patch. */
5456
- revert(change, direction, appState, selectedIds) {
5454
+ /** Move the scene across `change` (see buildRevertPatch), move the local
5455
+ * appState fields the step changed from `from` back to `to`, and broadcast
5456
+ * the element patch. */
5457
+ revert(change, direction, from, to, selectedIds) {
5457
5458
  const patch = buildRevertPatch(change, this._present, direction);
5458
5459
  const patched = patch ? reducer(this._present, patch) : this._present;
5459
- this._present = restoreLocalState(patched, appState, selectedIds);
5460
+ this._present = restoreLocalState(patched, from, to, selectedIds);
5460
5461
  if (patch) this.onCommand?.(patch);
5461
5462
  this.notify();
5462
5463
  }
5463
5464
  };
5464
- /**
5465
- * appState fields undo and redo leave as they are now: the tool and the
5466
- * default style, which the tool switch and the style panel also set without
5467
- * an undo step (SET_TOOL inherits the selection's style and sets the shape
5468
- * kind), and view settings. Restoring them would undo choices the user made
5469
- * after the step. The text defaults (font size and family, alignment, mode)
5470
- * and the line routing are restored.
5471
- */
5472
- var KEPT_ON_UNDO = [
5465
+ var KEPT_ON_UNDO_SET = /* @__PURE__ */ new Set([...[
5473
5466
  "activeTool",
5474
5467
  "strokeColor",
5475
5468
  "fillColor",
@@ -5481,20 +5474,16 @@ var KEPT_ON_UNDO = [
5481
5474
  "gridVisible",
5482
5475
  "gridType",
5483
5476
  "toolLocked"
5484
- ];
5485
- var KEPT_ON_UNDO_SET = /* @__PURE__ */ new Set([...KEPT_ON_UNDO, "lastCreatedId"]);
5477
+ ], "lastCreatedId"]);
5486
5478
  /**
5487
- * Whether a change is worth an undo step: it touches elements or their order,
5488
- * or an appState field that undo restores. An element change the diff leaves
5479
+ * Whether a change is worth an undo step: it touches elements or their order.
5480
+ * An element change the diff leaves
5489
5481
  * out (a type-only change: the type is identity there) still counts, so the
5490
5482
  * board is never changed without a step.
5491
5483
  */
5492
5484
  function isUndoableChange(change, prev, next) {
5493
5485
  if (change.elements.size > 0 || change.order) return true;
5494
- if (!sameElements(prev.elements, next.elements)) return true;
5495
- const before = prev.appState;
5496
- const after = next.appState;
5497
- return Object.keys(after).some((key) => !KEPT_ON_UNDO_SET.has(key) && after[key] !== before[key]);
5486
+ return !sameElements(prev.elements, next.elements);
5498
5487
  }
5499
5488
  /** Same elements in the same order, by value (unchanged ones keep identity). */
5500
5489
  function sameElements(a, b) {
@@ -5503,24 +5492,30 @@ function sameElements(a, b) {
5503
5492
  return a.every((el, i) => el === b[i] || deepEqual(el, b[i]));
5504
5493
  }
5505
5494
  /**
5506
- * Restore the per-user appState recorded with an undo step (e.g. the font size
5507
- * default a command changed), keeping the fields in KEPT_ON_UNDO as they are
5508
- * now. The selection stays as-is unless `selectedIds` is given (cancelled
5509
- * drag); either way it is limited to elements that still exist.
5495
+ * Restore the per-user appState fields a step changed (e.g. the font size
5496
+ * default a SET_FONT_SIZE on a selection also set): each field that differs
5497
+ * between `from` and `to` goes back to its `to` value, except those in
5498
+ * KEPT_ON_UNDO, as long as it still holds the `from` value. Fields the step
5499
+ * did not change, or that changed since without a step (a default set with
5500
+ * nothing selected), stay as they are now.
5501
+ * The selection stays as-is unless `selectedIds` is given (cancelled drag);
5502
+ * either way it is limited to elements that still exist.
5510
5503
  */
5511
- function restoreLocalState(scene, appState, selectedIds = scene.selectedIds) {
5504
+ function restoreLocalState(scene, from, to, selectedIds = scene.selectedIds) {
5512
5505
  const elementIds = new Set(scene.elements.map((element) => element.id));
5513
- const current = scene.appState;
5514
- const kept = {};
5515
- for (const key of KEPT_ON_UNDO) kept[key] = current[key];
5516
- const currentLastCreatedId = current.lastCreatedId;
5506
+ const restored = {};
5507
+ for (const key of Object.keys(to)) {
5508
+ const changed = from[key] !== to[key];
5509
+ if (!KEPT_ON_UNDO_SET.has(key) && changed && scene.appState[key] === from[key]) Object.assign(restored, { [key]: to[key] });
5510
+ }
5511
+ const lastCreatedId = scene.appState.lastCreatedId;
5517
5512
  return {
5518
5513
  ...scene,
5519
5514
  selectedIds: new Set([...selectedIds].filter((id) => elementIds.has(id))),
5520
5515
  appState: {
5521
- ...appState,
5522
- ...kept,
5523
- lastCreatedId: currentLastCreatedId && elementIds.has(currentLastCreatedId) ? currentLastCreatedId : null
5516
+ ...scene.appState,
5517
+ ...restored,
5518
+ lastCreatedId: lastCreatedId && elementIds.has(lastCreatedId) ? lastCreatedId : null
5524
5519
  }
5525
5520
  };
5526
5521
  }
@@ -6641,10 +6636,18 @@ var LiveOutbox = class {
6641
6636
  return this.queue.length > 0;
6642
6637
  }
6643
6638
  push(command) {
6644
- const last = this.queue.at(-1);
6645
- const merged = last ? mergeCommands(last, command) : null;
6646
- if (merged) this.queue[this.queue.length - 1] = merged;
6647
- else this.queue.push(command);
6639
+ let merged = false;
6640
+ for (let i = this.queue.length - 1; i >= 0; i--) {
6641
+ const waiting = this.queue[i];
6642
+ const combined = mergeCommands(waiting, command);
6643
+ if (combined) {
6644
+ this.queue[i] = combined;
6645
+ merged = true;
6646
+ break;
6647
+ }
6648
+ if (!independent(waiting, command)) break;
6649
+ }
6650
+ if (!merged) this.queue.push(command);
6648
6651
  if (this.timer === null) this.flush();
6649
6652
  }
6650
6653
  /** Sends what the quota allows now, and schedules the rest. */
@@ -6725,6 +6728,25 @@ function mergeCommands(last, next) {
6725
6728
  if (last.type === "SET_ROTATION" && next.type === "SET_ROTATION") return last.id === next.id ? next : null;
6726
6729
  return null;
6727
6730
  }
6731
+ /** The elements a gesture command acts on, or null for any other command. */
6732
+ function gestureTargets(command) {
6733
+ switch (command.type) {
6734
+ case "MOVE_ELEMENT":
6735
+ case "RESIZE_ELEMENT":
6736
+ case "SET_ROTATION": return [command.id];
6737
+ case "MOVE_ELEMENTS": return command.ids;
6738
+ default: return null;
6739
+ }
6740
+ }
6741
+ /**
6742
+ * Whether two gesture commands act on separate elements, so their order
6743
+ * does not matter. Anything else may depend on what came before it.
6744
+ */
6745
+ function independent(a, b) {
6746
+ const ta = gestureTargets(a);
6747
+ const tb = gestureTargets(b);
6748
+ return !!ta && !!tb && !ta.some((id) => tb.includes(id));
6749
+ }
6728
6750
  /** Elements per CREATE_ELEMENTS, well under the validation limit (5,000). */
6729
6751
  var PIECE_ELEMENTS = 1e3;
6730
6752
  /** Size of one CREATE_ELEMENTS, under the room's message limit (512 KB). */
@@ -6910,6 +6932,13 @@ function randomClientId() {
6910
6932
  const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(24));
6911
6933
  return Array.from(bytes, (b) => alphabet[b % 62]).join("");
6912
6934
  }
6935
+ /** What each refusal reason of the room means, for the model. */
6936
+ var REJECTION_TEXT = {
6937
+ too_large: "one edit was too large for a single message, usually a large image",
6938
+ rate: "too many edits in a short time",
6939
+ full: "the room reached its size limit",
6940
+ invalid: "an edit could not be applied"
6941
+ };
6913
6942
  var LiveLink = class LiveLink {
6914
6943
  diagram;
6915
6944
  name;
@@ -6945,6 +6974,30 @@ var LiveLink = class LiveLink {
6945
6974
  get otherPeers() {
6946
6975
  return this.peers.filter((p) => p.id !== this.selfId);
6947
6976
  }
6977
+ /** Edits handed to the room so far, sent or waiting (see guarded in server.ts). */
6978
+ editCount = 0;
6979
+ /** Reasons the room gave for refusing edits since the last answer. */
6980
+ rejections = [];
6981
+ /**
6982
+ * Why the room refused some of the agent's edits since the last call, as
6983
+ * a note for the model: the board it sees here then differs from the
6984
+ * room's. Empty when nothing was refused.
6985
+ */
6986
+ takeRejections() {
6987
+ if (this.rejections.length === 0) return "";
6988
+ const reasons = this.rejections.map((reason) => REJECTION_TEXT[reason] ?? reason);
6989
+ this.rejections = [];
6990
+ return `The live room refused some of your edits (${reasons.join("; ")}): the other people do not see them.`;
6991
+ }
6992
+ /**
6993
+ * Resolves once the edits held back by the room's quota are sent (at
6994
+ * most `timeoutMs`), then after `graceMs` more, so a refusal of the last
6995
+ * ones has time to arrive.
6996
+ */
6997
+ async settle(timeoutMs, graceMs) {
6998
+ await this.outbox.idle(timeoutMs);
6999
+ await new Promise((resolve) => setTimeout(resolve, graceMs));
7000
+ }
6948
7001
  /** Requests received and not yet handed to the model. */
6949
7002
  get pendingRequests() {
6950
7003
  return this.inbox.length;
@@ -7018,6 +7071,11 @@ var LiveLink = class LiveLink {
7018
7071
  type: "command",
7019
7072
  command
7020
7073
  }) });
7074
+ /** Queues a scene command for the room, counting it (see editCount). */
7075
+ publish(command) {
7076
+ this.editCount++;
7077
+ this.outbox.push(command);
7078
+ }
7021
7079
  send(message) {
7022
7080
  if (this.socket?.readyState === WebSocket.OPEN) this.socket.send(JSON.stringify(message));
7023
7081
  }
@@ -7061,11 +7119,11 @@ var LiveLink = class LiveLink {
7061
7119
  discarded = local.length;
7062
7120
  history.resetForLiveReplay(msg.commands.filter(isValidSessionCommand));
7063
7121
  } else if (local.length > 0) {
7064
- for (const command of createCommands(local, { validOnly: true })) this.outbox.push(command);
7122
+ for (const command of createCommands(local, { validOnly: true })) this.publish(command);
7065
7123
  seeded = true;
7066
7124
  }
7067
7125
  history.setOnCommand((command) => {
7068
- if (this.open && isSessionCommand(command)) this.outbox.push(command);
7126
+ if (this.open && isSessionCommand(command)) this.publish(command);
7069
7127
  });
7070
7128
  this.open = true;
7071
7129
  resolve({
@@ -7080,7 +7138,9 @@ var LiveLink = class LiveLink {
7080
7138
  }
7081
7139
  } else if (msg.type === "presence") this.peers = msg.peers;
7082
7140
  else if (msg.type === "request") this.receiveRequest(msg);
7083
- else if (msg.type === "error" && !this.open) {
7141
+ else if (msg.type === "rejected" && typeof msg.reason === "string") {
7142
+ if (!this.rejections.includes(msg.reason)) this.rejections.push(msg.reason);
7143
+ } else if (msg.type === "error" && !this.open) {
7084
7144
  clearTimeout(timer);
7085
7145
  reject(new LiveError(msg.error === "licence required" ? licenceMessage(origin) : `The live room refused to join: ${msg.error}.`));
7086
7146
  }
@@ -7501,7 +7561,13 @@ function formatRequests(requests) {
7501
7561
  ...lines
7502
7562
  ].join("\n");
7503
7563
  }
7504
- /** Runs a tool body and turns thrown errors into MCP tool errors. */
7564
+ /**
7565
+ * How long an answer waits for the room to refuse the edits it sent, after
7566
+ * the ones held back by the quota go out (at most QUEUE_WAIT_MS, a bit over
7567
+ * one quota window).
7568
+ */
7569
+ var REFUSAL_WAIT_MS = 250;
7570
+ var QUEUE_WAIT_MS = 6e3;
7505
7571
  /** Tool calls still running; shutting down waits for them. */
7506
7572
  var inFlight = 0;
7507
7573
  var onIdle = [];
@@ -7528,8 +7594,11 @@ function callsDone(timeoutMs) {
7528
7594
  });
7529
7595
  });
7530
7596
  }
7597
+ /** Runs a tool body and turns thrown errors into MCP tool errors. */
7531
7598
  function guarded(run) {
7532
7599
  return tracked(async (args) => {
7600
+ const before = live;
7601
+ const editsBefore = before?.editCount ?? 0;
7533
7602
  let result;
7534
7603
  try {
7535
7604
  result = text(await run(args));
@@ -7537,10 +7606,11 @@ function guarded(run) {
7537
7606
  result = failure(error);
7538
7607
  }
7539
7608
  const requests = live?.pendingRequests ? live.takeRequests() : [];
7540
- if (requests.length > 0) {
7541
- const first = result.content[0];
7542
- if (first) first.text += `\n${formatRequests(requests)}`;
7543
- }
7609
+ const first = result.content[0];
7610
+ if (requests.length > 0 && first) first.text += `\n${formatRequests(requests)}`;
7611
+ if (live && live.editCount > (live === before ? editsBefore : 0)) await live.settle(QUEUE_WAIT_MS, REFUSAL_WAIT_MS);
7612
+ const refused = [before, live !== before ? live : null].map((link) => link?.takeRejections() ?? "").filter(Boolean);
7613
+ if (refused.length > 0 && first) first.text += `\n${refused.join("\n")}`;
7544
7614
  return result;
7545
7615
  });
7546
7616
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@markasso/mcp",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
+ "mcpName": "io.github.AlbertoBarrago/markasso",
4
5
  "description": "MCP server that lets AI agents create, read and edit Markasso diagrams, offline or live on a shared board",
5
6
  "type": "module",
6
7
  "repository": {