@markasso/mcp 0.7.8 → 0.7.9
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 +1 -1
- package/dist/markasso-mcp.js +224 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ Bump `version` in `mcp/package.json` and both `version` fields in `mcp/server.js
|
|
|
103
103
|
| `diagram_update_edge` | Change a connection's label, label font size, routing, heads, dash or color |
|
|
104
104
|
| `diagram_disconnect` | Remove connections (by id or by from/to), keeping the nodes |
|
|
105
105
|
| `diagram_remove` | Remove nodes and their connections |
|
|
106
|
-
| `diagram_layout` | Arrange nodes in layers (top-to-bottom or left-to-right), then report layout warnings |
|
|
106
|
+
| `diagram_layout` | Arrange nodes in layers (top-to-bottom or left-to-right), then report layout warnings. Connections that skip layers get a lane of their own, and gaps between layers fit connection labels |
|
|
107
107
|
| `icons_search` | Find generic architecture icons and Kubernetes icons |
|
|
108
108
|
| `diagram_save` | Save as `.markasso` |
|
|
109
109
|
| `diagram_export_svg` | Export an SVG image |
|
package/dist/markasso-mcp.js
CHANGED
|
@@ -4595,9 +4595,30 @@ function escapeXml(str) {
|
|
|
4595
4595
|
}
|
|
4596
4596
|
//#endregion
|
|
4597
4597
|
//#region package.json
|
|
4598
|
-
var version = "0.7.
|
|
4598
|
+
var version = "0.7.9";
|
|
4599
4599
|
//#endregion
|
|
4600
4600
|
//#region ../src/core/layout.ts
|
|
4601
|
+
/** Space kept on both sides of a label between ranks. */
|
|
4602
|
+
var LABEL_MARGIN = 20;
|
|
4603
|
+
/**
|
|
4604
|
+
* Upper bound on placement rounds; they stop once nothing moves. Agent-made
|
|
4605
|
+
* diagrams settle in under 15. Dozens of rigid lanes can converge slowly:
|
|
4606
|
+
* the cap keeps such inputs fast, and every round keeps all gaps, so
|
|
4607
|
+
* stopping early only leaves the placement a little less tidy.
|
|
4608
|
+
*/
|
|
4609
|
+
var MAX_PLACEMENT_ROUNDS = 32;
|
|
4610
|
+
/** A round that moves no center by more than this (px) ends placement. */
|
|
4611
|
+
var PLACEMENT_TOLERANCE = .01;
|
|
4612
|
+
/**
|
|
4613
|
+
* Pull of a segment touching a dummy, against 1 between two nodes. Graphviz
|
|
4614
|
+
* uses 2 and 8 (Gansner et al.) because it draws a spline through the
|
|
4615
|
+
* dummies; a connector here is drawn straight between its two ends, so the
|
|
4616
|
+
* ends must sit on the lane: a long connector is held as one rigid rod.
|
|
4617
|
+
*/
|
|
4618
|
+
var LANE_WEIGHT = 64;
|
|
4619
|
+
function segmentWeight(a, b) {
|
|
4620
|
+
return a.vertex && b.vertex ? 1 : LANE_WEIGHT;
|
|
4621
|
+
}
|
|
4601
4622
|
/** Orders vertices without recursion, preserving input order when unconstrained. */
|
|
4602
4623
|
function topologicalOrder(vertices) {
|
|
4603
4624
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -4633,17 +4654,17 @@ function reduceCrossings(ranks) {
|
|
|
4633
4654
|
const positions = /* @__PURE__ */ new Map();
|
|
4634
4655
|
const reorder = (rank, downward) => {
|
|
4635
4656
|
const scores = /* @__PURE__ */ new Map();
|
|
4636
|
-
for (const [index,
|
|
4637
|
-
const values = (downward ?
|
|
4638
|
-
scores.set(
|
|
4657
|
+
for (const [index, slot] of rank.entries()) {
|
|
4658
|
+
const values = (downward ? slot.up : slot.down).map((neighbor) => positions.get(neighbor));
|
|
4659
|
+
scores.set(slot, values.length ? values.reduce((a, b) => a + b, 0) / values.length : index);
|
|
4639
4660
|
}
|
|
4640
4661
|
rank.sort((a, b) => scores.get(a) - scores.get(b));
|
|
4641
|
-
rank.forEach((
|
|
4642
|
-
positions.set(
|
|
4662
|
+
rank.forEach((slot, index) => {
|
|
4663
|
+
positions.set(slot, index);
|
|
4643
4664
|
});
|
|
4644
4665
|
};
|
|
4645
|
-
for (const rank of ranks) rank.forEach((
|
|
4646
|
-
positions.set(
|
|
4666
|
+
for (const rank of ranks) rank.forEach((slot, index) => {
|
|
4667
|
+
positions.set(slot, index);
|
|
4647
4668
|
});
|
|
4648
4669
|
for (let pass = 0; pass < 4; pass++) {
|
|
4649
4670
|
for (let index = 1; index < ranks.length; index++) reorder(ranks[index], true);
|
|
@@ -4651,8 +4672,100 @@ function reduceCrossings(ranks) {
|
|
|
4651
4672
|
}
|
|
4652
4673
|
}
|
|
4653
4674
|
/**
|
|
4675
|
+
* Moves each slot of a rank as close to its target as the order and the
|
|
4676
|
+
* gaps allow, minimizing the weighted squared distance (pool adjacent
|
|
4677
|
+
* violators). Subtracting each slot's minimum offset from the first turns
|
|
4678
|
+
* the gap constraints into "non-decreasing", which isotonic regression
|
|
4679
|
+
* solves exactly in one pass.
|
|
4680
|
+
*/
|
|
4681
|
+
function placeRank(rank, targets, weights, nodeGap) {
|
|
4682
|
+
const offsets = [];
|
|
4683
|
+
let offset = 0;
|
|
4684
|
+
rank.forEach((slot, index) => {
|
|
4685
|
+
if (index > 0) {
|
|
4686
|
+
const prev = rank[index - 1];
|
|
4687
|
+
offset += (prev.breadth + slot.breadth) / 2 + nodeGap;
|
|
4688
|
+
}
|
|
4689
|
+
offsets.push(offset);
|
|
4690
|
+
});
|
|
4691
|
+
const blocks = [];
|
|
4692
|
+
rank.forEach((_, index) => {
|
|
4693
|
+
const weight = weights[index];
|
|
4694
|
+
blocks.push({
|
|
4695
|
+
sum: (targets[index] - offsets[index]) * weight,
|
|
4696
|
+
weight,
|
|
4697
|
+
count: 1
|
|
4698
|
+
});
|
|
4699
|
+
while (blocks.length > 1) {
|
|
4700
|
+
const last = blocks[blocks.length - 1];
|
|
4701
|
+
const prev = blocks[blocks.length - 2];
|
|
4702
|
+
if (prev.sum / prev.weight <= last.sum / last.weight) break;
|
|
4703
|
+
blocks.pop();
|
|
4704
|
+
prev.sum += last.sum;
|
|
4705
|
+
prev.weight += last.weight;
|
|
4706
|
+
prev.count += last.count;
|
|
4707
|
+
}
|
|
4708
|
+
});
|
|
4709
|
+
let index = 0;
|
|
4710
|
+
for (const block of blocks) {
|
|
4711
|
+
const value = block.sum / block.weight;
|
|
4712
|
+
for (let k = 0; k < block.count; k++, index++) rank[index].center = value + offsets[index];
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
/**
|
|
4716
|
+
* Assigns centers across the ranks, minimizing the weighted squared length
|
|
4717
|
+
* of every connector segment across ranks under the order and gap
|
|
4718
|
+
* constraints. Each step solves one rank exactly with the others fixed
|
|
4719
|
+
* (its targets are the weighted means of all its neighbors), sweeping down
|
|
4720
|
+
* and up: block coordinate descent on a convex problem, so it settles
|
|
4721
|
+
* instead of drifting.
|
|
4722
|
+
*/
|
|
4723
|
+
function assignCenters(ranks, nodeGap) {
|
|
4724
|
+
for (const rank of ranks) {
|
|
4725
|
+
let at = -(rank.reduce((sum, slot) => sum + slot.breadth, 0) + nodeGap * (rank.length - 1)) / 2;
|
|
4726
|
+
for (const slot of rank) {
|
|
4727
|
+
slot.center = at + slot.breadth / 2;
|
|
4728
|
+
at += slot.breadth + nodeGap;
|
|
4729
|
+
}
|
|
4730
|
+
}
|
|
4731
|
+
const solve = (rank) => {
|
|
4732
|
+
const before = rank.map((slot) => slot.center);
|
|
4733
|
+
const targets = [];
|
|
4734
|
+
const weights = [];
|
|
4735
|
+
for (const slot of rank) {
|
|
4736
|
+
let sum = 0;
|
|
4737
|
+
let weight = 0;
|
|
4738
|
+
for (const neighbor of [...slot.up, ...slot.down]) {
|
|
4739
|
+
const w = segmentWeight(slot, neighbor);
|
|
4740
|
+
sum += w * neighbor.center;
|
|
4741
|
+
weight += w;
|
|
4742
|
+
}
|
|
4743
|
+
targets.push(weight > 0 ? sum / weight : slot.center);
|
|
4744
|
+
weights.push(weight > 0 ? weight : 1);
|
|
4745
|
+
}
|
|
4746
|
+
placeRank(rank, targets, weights, nodeGap);
|
|
4747
|
+
let moved = 0;
|
|
4748
|
+
rank.forEach((slot, index) => {
|
|
4749
|
+
moved = Math.max(moved, Math.abs(slot.center - before[index]));
|
|
4750
|
+
});
|
|
4751
|
+
return moved;
|
|
4752
|
+
};
|
|
4753
|
+
for (let round = 0; round < MAX_PLACEMENT_ROUNDS; round++) {
|
|
4754
|
+
let moved = 0;
|
|
4755
|
+
for (let index = 0; index < ranks.length; index++) moved = Math.max(moved, solve(ranks[index]));
|
|
4756
|
+
for (let index = ranks.length - 2; index > 0; index--) moved = Math.max(moved, solve(ranks[index]));
|
|
4757
|
+
if (moved < PLACEMENT_TOLERANCE) break;
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
/**
|
|
4654
4761
|
* Produces top-left positions in CSS pixels without mutating the input.
|
|
4655
4762
|
* Cyclic edges are oriented along DFS reverse postorder before longest-path ranking.
|
|
4763
|
+
* An edge that skips ranks gets a lane of dummy slots, so no node sits on it,
|
|
4764
|
+
* and centers minimize weighted connector lengths (Sugiyama-style placement).
|
|
4765
|
+
* Rank gaps grow to fit edge labels (largest label per node pair).
|
|
4766
|
+
* Connectors are drawn straight between their ends, so a node with several
|
|
4767
|
+
* long edges can only sit on one lane: the others may still cross nodes, a
|
|
4768
|
+
* case the MCP's layout warnings report.
|
|
4656
4769
|
* Disconnected components occupy separate columns (rows for LR).
|
|
4657
4770
|
* Nodes must have unique IDs and finite, nonnegative dimensions and gaps.
|
|
4658
4771
|
*/
|
|
@@ -4666,10 +4779,26 @@ function layeredLayout(nodes, edges, options = {}) {
|
|
|
4666
4779
|
rank: 0
|
|
4667
4780
|
}));
|
|
4668
4781
|
const byId = new Map(vertices.map((vertex) => [vertex.node.id, vertex]));
|
|
4782
|
+
const position = new Map(vertices.map((vertex, index) => [vertex, index]));
|
|
4783
|
+
const pairKey = (a, b) => {
|
|
4784
|
+
const i = position.get(a);
|
|
4785
|
+
const j = position.get(b);
|
|
4786
|
+
return i < j ? `${i},${j}` : `${j},${i}`;
|
|
4787
|
+
};
|
|
4788
|
+
const labels = /* @__PURE__ */ new Map();
|
|
4669
4789
|
for (const edge of edges) {
|
|
4670
4790
|
const from = byId.get(edge.from);
|
|
4671
4791
|
const to = byId.get(edge.to);
|
|
4672
|
-
if (!from || !to || from === to
|
|
4792
|
+
if (!from || !to || from === to) continue;
|
|
4793
|
+
const key = pairKey(from, to);
|
|
4794
|
+
if (edge.label) {
|
|
4795
|
+
const known = labels.get(key);
|
|
4796
|
+
labels.set(key, {
|
|
4797
|
+
width: Math.max(known?.width ?? 0, edge.label.width),
|
|
4798
|
+
height: Math.max(known?.height ?? 0, edge.label.height)
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4801
|
+
if (from.outgoing.includes(to)) continue;
|
|
4673
4802
|
from.outgoing.push(to);
|
|
4674
4803
|
from.neighbors.add(to);
|
|
4675
4804
|
to.neighbors.add(from);
|
|
@@ -4684,8 +4813,8 @@ function layeredLayout(nodes, edges, options = {}) {
|
|
|
4684
4813
|
}
|
|
4685
4814
|
for (const vertex of order) for (const next of vertex.outgoing) next.rank = Math.max(next.rank, vertex.rank + 1);
|
|
4686
4815
|
const horizontal = options.direction === "LR";
|
|
4687
|
-
const
|
|
4688
|
-
const
|
|
4816
|
+
const breadthOf = (size) => horizontal ? size.height : size.width;
|
|
4817
|
+
const depthOf = (size) => horizontal ? size.width : size.height;
|
|
4689
4818
|
const nodeGap = options.nodeGap ?? 60;
|
|
4690
4819
|
const rankGap = options.rankGap ?? 100;
|
|
4691
4820
|
const origin = options.origin ?? {
|
|
@@ -4704,30 +4833,89 @@ function layeredLayout(nodes, edges, options = {}) {
|
|
|
4704
4833
|
component.push(neighbor);
|
|
4705
4834
|
}
|
|
4706
4835
|
const ranks = [];
|
|
4836
|
+
const slots = /* @__PURE__ */ new Map();
|
|
4707
4837
|
const members = new Set(component);
|
|
4708
4838
|
for (const vertex of vertices) {
|
|
4709
4839
|
if (!members.has(vertex)) continue;
|
|
4840
|
+
const slot = {
|
|
4841
|
+
vertex,
|
|
4842
|
+
breadth: breadthOf(vertex.node),
|
|
4843
|
+
depth: depthOf(vertex.node),
|
|
4844
|
+
up: [],
|
|
4845
|
+
down: [],
|
|
4846
|
+
center: 0
|
|
4847
|
+
};
|
|
4848
|
+
slots.set(vertex, slot);
|
|
4710
4849
|
ranks[vertex.rank] ??= [];
|
|
4711
|
-
ranks[vertex.rank].push(
|
|
4850
|
+
ranks[vertex.rank].push(slot);
|
|
4851
|
+
}
|
|
4852
|
+
const gapLabels = [];
|
|
4853
|
+
const gapLabelSpans = [];
|
|
4854
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4855
|
+
for (const vertex of component) for (const next of vertex.outgoing) {
|
|
4856
|
+
const key = pairKey(vertex, next);
|
|
4857
|
+
if (seen.has(key)) continue;
|
|
4858
|
+
seen.add(key);
|
|
4859
|
+
const label = labels.get(key);
|
|
4860
|
+
const span = next.rank - vertex.rank;
|
|
4861
|
+
const mid = (vertex.rank + next.rank) / 2;
|
|
4862
|
+
let prev = slots.get(vertex);
|
|
4863
|
+
for (let rank = vertex.rank + 1; rank < next.rank; rank++) {
|
|
4864
|
+
const dummy = {
|
|
4865
|
+
vertex: null,
|
|
4866
|
+
breadth: label ? breadthOf(label) : 0,
|
|
4867
|
+
depth: label && rank === mid ? depthOf(label) : 0,
|
|
4868
|
+
up: [prev],
|
|
4869
|
+
down: [],
|
|
4870
|
+
center: 0
|
|
4871
|
+
};
|
|
4872
|
+
prev.down.push(dummy);
|
|
4873
|
+
ranks[rank].push(dummy);
|
|
4874
|
+
prev = dummy;
|
|
4875
|
+
}
|
|
4876
|
+
const last = slots.get(next);
|
|
4877
|
+
prev.down.push(last);
|
|
4878
|
+
last.up.push(prev);
|
|
4879
|
+
if (label && span % 2 === 1) {
|
|
4880
|
+
const gap = Math.floor(mid);
|
|
4881
|
+
gapLabels[gap] = Math.max(gapLabels[gap] ?? 0, depthOf(label));
|
|
4882
|
+
if (span === 1) gapLabelSpans.push({
|
|
4883
|
+
a: slots.get(vertex),
|
|
4884
|
+
b: last,
|
|
4885
|
+
breadth: breadthOf(label)
|
|
4886
|
+
});
|
|
4887
|
+
}
|
|
4712
4888
|
}
|
|
4713
4889
|
reduceCrossings(ranks);
|
|
4714
|
-
|
|
4715
|
-
|
|
4890
|
+
assignCenters(ranks, nodeGap);
|
|
4891
|
+
let left = Infinity;
|
|
4892
|
+
let right = -Infinity;
|
|
4893
|
+
for (const rank of ranks) for (const slot of rank) {
|
|
4894
|
+
left = Math.min(left, slot.center - slot.breadth / 2);
|
|
4895
|
+
right = Math.max(right, slot.center + slot.breadth / 2);
|
|
4896
|
+
}
|
|
4897
|
+
for (const { a, b, breadth } of gapLabelSpans) {
|
|
4898
|
+
const mid = (a.center + b.center) / 2;
|
|
4899
|
+
left = Math.min(left, mid - breadth / 2);
|
|
4900
|
+
right = Math.max(right, mid + breadth / 2);
|
|
4901
|
+
}
|
|
4716
4902
|
let rankOffset = 0;
|
|
4717
4903
|
for (const [index, rank] of ranks.entries()) {
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
for (const
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4904
|
+
let rankDepth = 0;
|
|
4905
|
+
for (const slot of rank) rankDepth = Math.max(rankDepth, slot.depth);
|
|
4906
|
+
for (const slot of rank) {
|
|
4907
|
+
if (!slot.vertex) continue;
|
|
4908
|
+
const along = rankOffset + (rankDepth - slot.depth) / 2;
|
|
4909
|
+
const across = componentOffset + Math.round(slot.center - slot.breadth / 2 - left);
|
|
4910
|
+
result.set(slot.vertex.node.id, {
|
|
4911
|
+
x: origin.x + (horizontal ? along : across),
|
|
4912
|
+
y: origin.y + (horizontal ? across : along)
|
|
4725
4913
|
});
|
|
4726
|
-
offset += breadth(vertex) + nodeGap;
|
|
4727
4914
|
}
|
|
4728
|
-
|
|
4915
|
+
const labelDepth = gapLabels[index];
|
|
4916
|
+
rankOffset += rankDepth + (labelDepth === void 0 ? rankGap : Math.max(rankGap, labelDepth + 2 * LABEL_MARGIN));
|
|
4729
4917
|
}
|
|
4730
|
-
componentOffset +=
|
|
4918
|
+
componentOffset += Math.ceil(right - left) + nodeGap;
|
|
4731
4919
|
}
|
|
4732
4920
|
return result;
|
|
4733
4921
|
}
|
|
@@ -6590,10 +6778,18 @@ var Diagram = class {
|
|
|
6590
6778
|
if (nodes.length === 0) return 0;
|
|
6591
6779
|
const ids = new Set(nodes.map((el) => el.id));
|
|
6592
6780
|
const boxes = new Map(nodes.map((el) => [el.id, getConnectorBox(el)]));
|
|
6593
|
-
const edges = this.elements.flatMap((el) =>
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6781
|
+
const edges = this.elements.flatMap((el) => {
|
|
6782
|
+
if (!isConnector$1(el) || !el.startElementId || !el.endElementId || !ids.has(el.startElementId) || !ids.has(el.endElementId)) return [];
|
|
6783
|
+
const label = el.label ? getConnectorLabelSize(el) : void 0;
|
|
6784
|
+
return [{
|
|
6785
|
+
from: el.startElementId,
|
|
6786
|
+
to: el.endElementId,
|
|
6787
|
+
...label && { label: {
|
|
6788
|
+
width: label.w,
|
|
6789
|
+
height: label.h
|
|
6790
|
+
} }
|
|
6791
|
+
}];
|
|
6792
|
+
});
|
|
6597
6793
|
const origin = {
|
|
6598
6794
|
x: Math.min(...[...boxes.values()].map((b) => b.x)),
|
|
6599
6795
|
y: Math.min(...[...boxes.values()].map((b) => b.y))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markasso/mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"mcpName": "io.github.AlbertoBarrago/markasso",
|
|
5
5
|
"description": "MCP server that lets AI agents create, read and edit Markasso diagrams, offline or live on a shared board",
|
|
6
6
|
"type": "module",
|