@superdoc-dev/mcp 0.1.0-next.1 → 0.1.0-next.2

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/dist/index.js +146 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -48750,10 +48750,10 @@ import { readFile, writeFile } from "node:fs/promises";
48750
48750
  import { randomBytes } from "node:crypto";
48751
48751
  import { resolve as resolve3, basename as basename2 } from "node:path";
48752
48752
 
48753
- // ../../packages/superdoc/dist/chunks/src-DBTSAwZm.es.js
48753
+ // ../../packages/superdoc/dist/chunks/src-D3mGOQvT.es.js
48754
48754
  init_rolldown_runtime_B2q5OVn9_es();
48755
- var exports_src_DBTSAwZm_es = {};
48756
- __export(exports_src_DBTSAwZm_es, {
48755
+ var exports_src_D3mGOQvT_es = {};
48756
+ __export(exports_src_D3mGOQvT_es, {
48757
48757
  zt: () => defineNode,
48758
48758
  z: () => cM,
48759
48759
  yt: () => map$12,
@@ -115435,7 +115435,7 @@ if (glo[importIdentifier] === true) {
115435
115435
  }
115436
115436
  glo[importIdentifier] = true;
115437
115437
 
115438
- // ../../packages/superdoc/dist/chunks/src-DBTSAwZm.es.js
115438
+ // ../../packages/superdoc/dist/chunks/src-D3mGOQvT.es.js
115439
115439
  function isNodeType(node2, name) {
115440
115440
  return node2.type.name === name;
115441
115441
  }
@@ -140721,8 +140721,26 @@ function executeListComments(adapter, query) {
140721
140721
  return adapter.list(query);
140722
140722
  }
140723
140723
  function normalizeSelector(selector) {
140724
- if ("type" in selector)
140724
+ if ("type" in selector) {
140725
+ if (selector.type === "text") {
140726
+ const text4 = selector;
140727
+ return {
140728
+ type: "text",
140729
+ pattern: text4.pattern,
140730
+ ...text4.mode != null && { mode: text4.mode },
140731
+ ...text4.caseSensitive != null && { caseSensitive: text4.caseSensitive }
140732
+ };
140733
+ }
140734
+ if (selector.type === "node") {
140735
+ const node2 = selector;
140736
+ return {
140737
+ type: "node",
140738
+ ...node2.nodeType != null && { nodeType: node2.nodeType },
140739
+ ...node2.kind != null && { kind: node2.kind }
140740
+ };
140741
+ }
140725
140742
  return selector;
140743
+ }
140726
140744
  return {
140727
140745
  type: "node",
140728
140746
  nodeType: selector.nodeType
@@ -141920,10 +141938,25 @@ function toBlockAddress(candidate) {
141920
141938
  nodeId: candidate.nodeId
141921
141939
  };
141922
141940
  }
141941
+ function resolveParagraphAliasId(node2, primaryId) {
141942
+ if (node2.type.name !== "paragraph")
141943
+ return;
141944
+ const attrs = node2.attrs;
141945
+ const sdBlockId = toId(attrs?.sdBlockId);
141946
+ if (sdBlockId && sdBlockId !== primaryId)
141947
+ return sdBlockId;
141948
+ }
141923
141949
  function buildBlockIndex(editor) {
141924
141950
  const candidates = [];
141925
141951
  const byId = /* @__PURE__ */ new Map;
141926
141952
  const ambiguous = /* @__PURE__ */ new Set;
141953
+ function registerKey(key$1, candidate) {
141954
+ if (byId.has(key$1)) {
141955
+ ambiguous.add(key$1);
141956
+ byId.delete(key$1);
141957
+ } else if (!ambiguous.has(key$1))
141958
+ byId.set(key$1, candidate);
141959
+ }
141927
141960
  editor.state.doc.descendants((node2, pos) => {
141928
141961
  const nodeType = mapBlockNodeType(node2);
141929
141962
  if (!nodeType)
@@ -141939,12 +141972,10 @@ function buildBlockIndex(editor) {
141939
141972
  nodeId
141940
141973
  };
141941
141974
  candidates.push(candidate);
141942
- const key$1 = `${candidate.nodeType}:${candidate.nodeId}`;
141943
- if (byId.has(key$1)) {
141944
- ambiguous.add(key$1);
141945
- byId.delete(key$1);
141946
- } else if (!ambiguous.has(key$1))
141947
- byId.set(key$1, candidate);
141975
+ registerKey(`${nodeType}:${nodeId}`, candidate);
141976
+ const aliasId = resolveParagraphAliasId(node2, nodeId);
141977
+ if (aliasId)
141978
+ registerKey(`${nodeType}:${aliasId}`, candidate);
141948
141979
  });
141949
141980
  return {
141950
141981
  candidates,
@@ -141958,14 +141989,17 @@ function findBlockById(index2, address) {
141958
141989
  }
141959
141990
  function findBlockByNodeIdOnly(index2, nodeId) {
141960
141991
  const matches2 = index2.candidates.filter((candidate) => candidate.nodeId === nodeId);
141961
- if (matches2.length === 0)
141962
- throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Block with nodeId "${nodeId}" was not found.`, { nodeId });
141992
+ if (matches2.length === 1)
141993
+ return matches2[0];
141963
141994
  if (matches2.length > 1)
141964
141995
  throw new DocumentApiAdapterError("AMBIGUOUS_TARGET", `Multiple blocks share nodeId "${nodeId}".`, {
141965
141996
  nodeId,
141966
141997
  count: matches2.length
141967
141998
  });
141968
- return matches2[0];
141999
+ for (const [key$1, candidate] of index2.byId)
142000
+ if (key$1.endsWith(`:${nodeId}`))
142001
+ return candidate;
142002
+ throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Block with nodeId "${nodeId}" was not found.`, { nodeId });
141969
142003
  }
141970
142004
  function isTextBlockCandidate(candidate) {
141971
142005
  const node2 = candidate.node;
@@ -143140,8 +143174,7 @@ function createParagraphAdapter(editor, input2, options) {
143140
143174
  clearIndexCache(editor);
143141
143175
  try {
143142
143176
  const paragraph2 = resolveCreatedParagraph(editor, paragraphId);
143143
- const trackedChangeRefs = mode === "tracked" ? collectTrackInsertRefsInRange(editor, paragraph2.pos, paragraph2.end) : undefined;
143144
- return buildParagraphCreateSuccess(paragraph2.nodeId, trackedChangeRefs);
143177
+ return buildParagraphCreateSuccess(paragraphId, mode === "tracked" ? collectTrackInsertRefsInRange(editor, paragraph2.pos, paragraph2.end) : undefined);
143145
143178
  } catch {
143146
143179
  return buildParagraphCreateSuccess(paragraphId);
143147
143180
  }
@@ -143251,8 +143284,7 @@ function createHeadingAdapter(editor, input2, options) {
143251
143284
  clearIndexCache(editor);
143252
143285
  try {
143253
143286
  const heading3 = resolveCreatedHeading(editor, headingId);
143254
- const trackedChangeRefs = mode === "tracked" ? collectTrackInsertRefsInRange(editor, heading3.pos, heading3.end) : undefined;
143255
- return buildHeadingCreateSuccess(heading3.nodeId, trackedChangeRefs);
143287
+ return buildHeadingCreateSuccess(headingId, mode === "tracked" ? collectTrackInsertRefsInRange(editor, heading3.pos, heading3.end) : undefined);
143256
143288
  } catch {
143257
143289
  return buildHeadingCreateSuccess(headingId);
143258
143290
  }
@@ -144131,6 +144163,9 @@ function formatStrikethroughAdapter(editor, input2, options) {
144131
144163
  return formatMarkAdapter(editor, "strike", "format.strikethrough", input2, options);
144132
144164
  }
144133
144165
  function findBlocksByTypeAndId(blockIndex, nodeType, nodeId) {
144166
+ const byIdMatch = blockIndex.byId.get(`${nodeType}:${nodeId}`);
144167
+ if (byIdMatch)
144168
+ return [byIdMatch];
144134
144169
  return blockIndex.candidates.filter((candidate) => candidate.nodeType === nodeType && candidate.nodeId === nodeId);
144135
144170
  }
144136
144171
  function getNodeAdapter(editor, address) {
@@ -144162,14 +144197,20 @@ function resolveBlockById(editor, nodeId, nodeType) {
144162
144197
  };
144163
144198
  }
144164
144199
  const matches2 = blockIndex.candidates.filter((candidate) => candidate.nodeId === nodeId);
144165
- if (matches2.length === 0)
144166
- throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Node not found for id "${nodeId}".`);
144200
+ if (matches2.length === 1)
144201
+ return {
144202
+ candidate: matches2[0],
144203
+ resolvedType: matches2[0].nodeType
144204
+ };
144167
144205
  if (matches2.length > 1)
144168
144206
  throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Multiple nodes share id "${nodeId}". Provide nodeType to disambiguate.`);
144169
- return {
144170
- candidate: matches2[0],
144171
- resolvedType: matches2[0].nodeType
144172
- };
144207
+ for (const [key$1, candidate] of blockIndex.byId)
144208
+ if (key$1.endsWith(`:${nodeId}`))
144209
+ return {
144210
+ candidate,
144211
+ resolvedType: candidate.nodeType
144212
+ };
144213
+ throw new DocumentApiAdapterError("TARGET_NOT_FOUND", `Node not found for id "${nodeId}".`);
144173
144214
  }
144174
144215
  function getNodeByIdAdapter(editor, input2) {
144175
144216
  const { nodeId, nodeType } = input2;
@@ -208233,8 +208274,8 @@ function stubFalse() {
208233
208274
  return false;
208234
208275
  }
208235
208276
  var stubFalse_default = stubFalse;
208236
- var freeExports$2 = typeof exports_src_DBTSAwZm_es == "object" && exports_src_DBTSAwZm_es && !exports_src_DBTSAwZm_es.nodeType && exports_src_DBTSAwZm_es;
208237
- var freeModule$2 = freeExports$2 && typeof module_src_DBTSAwZm_es == "object" && module_src_DBTSAwZm_es && !module_src_DBTSAwZm_es.nodeType && module_src_DBTSAwZm_es;
208277
+ var freeExports$2 = typeof exports_src_D3mGOQvT_es == "object" && exports_src_D3mGOQvT_es && !exports_src_D3mGOQvT_es.nodeType && exports_src_D3mGOQvT_es;
208278
+ var freeModule$2 = freeExports$2 && typeof module_src_D3mGOQvT_es == "object" && module_src_D3mGOQvT_es && !module_src_D3mGOQvT_es.nodeType && module_src_D3mGOQvT_es;
208238
208279
  var Buffer$1 = freeModule$2 && freeModule$2.exports === freeExports$2 ? _root_default.Buffer : undefined;
208239
208280
  var isBuffer_default = (Buffer$1 ? Buffer$1.isBuffer : undefined) || stubFalse_default;
208240
208281
  var argsTag$1 = "[object Arguments]";
@@ -208274,8 +208315,8 @@ function baseUnary(func) {
208274
208315
  };
208275
208316
  }
208276
208317
  var _baseUnary_default = baseUnary;
208277
- var freeExports$1 = typeof exports_src_DBTSAwZm_es == "object" && exports_src_DBTSAwZm_es && !exports_src_DBTSAwZm_es.nodeType && exports_src_DBTSAwZm_es;
208278
- var freeModule$1 = freeExports$1 && typeof module_src_DBTSAwZm_es == "object" && module_src_DBTSAwZm_es && !module_src_DBTSAwZm_es.nodeType && module_src_DBTSAwZm_es;
208318
+ var freeExports$1 = typeof exports_src_D3mGOQvT_es == "object" && exports_src_D3mGOQvT_es && !exports_src_D3mGOQvT_es.nodeType && exports_src_D3mGOQvT_es;
208319
+ var freeModule$1 = freeExports$1 && typeof module_src_D3mGOQvT_es == "object" && module_src_D3mGOQvT_es && !module_src_D3mGOQvT_es.nodeType && module_src_D3mGOQvT_es;
208279
208320
  var freeProcess = freeModule$1 && freeModule$1.exports === freeExports$1 && _freeGlobal_default.process;
208280
208321
  var _nodeUtil_default = function() {
208281
208322
  try {
@@ -208656,8 +208697,8 @@ Stack.prototype.get = _stackGet_default;
208656
208697
  Stack.prototype.has = _stackHas_default;
208657
208698
  Stack.prototype.set = _stackSet_default;
208658
208699
  var _Stack_default = Stack;
208659
- var freeExports = typeof exports_src_DBTSAwZm_es == "object" && exports_src_DBTSAwZm_es && !exports_src_DBTSAwZm_es.nodeType && exports_src_DBTSAwZm_es;
208660
- var freeModule = freeExports && typeof module_src_DBTSAwZm_es == "object" && module_src_DBTSAwZm_es && !module_src_DBTSAwZm_es.nodeType && module_src_DBTSAwZm_es;
208700
+ var freeExports = typeof exports_src_D3mGOQvT_es == "object" && exports_src_D3mGOQvT_es && !exports_src_D3mGOQvT_es.nodeType && exports_src_D3mGOQvT_es;
208701
+ var freeModule = freeExports && typeof module_src_D3mGOQvT_es == "object" && module_src_D3mGOQvT_es && !module_src_D3mGOQvT_es.nodeType && module_src_D3mGOQvT_es;
208661
208702
  var Buffer4 = freeModule && freeModule.exports === freeExports ? _root_default.Buffer : undefined;
208662
208703
  var allocUnsafe = Buffer4 ? Buffer4.allocUnsafe : undefined;
208663
208704
  function cloneBuffer(buffer4, isDeep) {
@@ -219972,6 +220013,23 @@ function executeListComments2(adapter, query2) {
219972
220013
  // ../../packages/document-api/src/find/find.ts
219973
220014
  function normalizeSelector2(selector) {
219974
220015
  if ("type" in selector) {
220016
+ if (selector.type === "text") {
220017
+ const text4 = selector;
220018
+ return {
220019
+ type: "text",
220020
+ pattern: text4.pattern,
220021
+ ...text4.mode != null && { mode: text4.mode },
220022
+ ...text4.caseSensitive != null && { caseSensitive: text4.caseSensitive }
220023
+ };
220024
+ }
220025
+ if (selector.type === "node") {
220026
+ const node3 = selector;
220027
+ return {
220028
+ type: "node",
220029
+ ...node3.nodeType != null && { nodeType: node3.nodeType },
220030
+ ...node3.kind != null && { kind: node3.kind }
220031
+ };
220032
+ }
219975
220033
  return selector;
219976
220034
  }
219977
220035
  return { type: "node", nodeType: selector.nodeType };
@@ -225307,10 +225365,27 @@ function toBlockAddress2(candidate) {
225307
225365
  nodeId: candidate.nodeId
225308
225366
  };
225309
225367
  }
225368
+ function resolveParagraphAliasId2(node3, primaryId) {
225369
+ if (node3.type.name !== "paragraph")
225370
+ return;
225371
+ const attrs = node3.attrs;
225372
+ const sdBlockId = toId2(attrs?.sdBlockId);
225373
+ if (sdBlockId && sdBlockId !== primaryId)
225374
+ return sdBlockId;
225375
+ return;
225376
+ }
225310
225377
  function buildBlockIndex2(editor) {
225311
225378
  const candidates = [];
225312
225379
  const byId = new Map;
225313
225380
  const ambiguous = new Set;
225381
+ function registerKey(key2, candidate) {
225382
+ if (byId.has(key2)) {
225383
+ ambiguous.add(key2);
225384
+ byId.delete(key2);
225385
+ } else if (!ambiguous.has(key2)) {
225386
+ byId.set(key2, candidate);
225387
+ }
225388
+ }
225314
225389
  editor.state.doc.descendants((node3, pos) => {
225315
225390
  const nodeType = mapBlockNodeType2(node3);
225316
225391
  if (!nodeType)
@@ -225326,12 +225401,10 @@ function buildBlockIndex2(editor) {
225326
225401
  nodeId
225327
225402
  };
225328
225403
  candidates.push(candidate);
225329
- const key2 = `${candidate.nodeType}:${candidate.nodeId}`;
225330
- if (byId.has(key2)) {
225331
- ambiguous.add(key2);
225332
- byId.delete(key2);
225333
- } else if (!ambiguous.has(key2)) {
225334
- byId.set(key2, candidate);
225404
+ registerKey(`${nodeType}:${nodeId}`, candidate);
225405
+ const aliasId = resolveParagraphAliasId2(node3, nodeId);
225406
+ if (aliasId) {
225407
+ registerKey(`${nodeType}:${aliasId}`, candidate);
225335
225408
  }
225336
225409
  });
225337
225410
  return { candidates, byId };
@@ -225343,16 +225416,19 @@ function findBlockById2(index2, address2) {
225343
225416
  }
225344
225417
  function findBlockByNodeIdOnly2(index2, nodeId) {
225345
225418
  const matches3 = index2.candidates.filter((candidate) => candidate.nodeId === nodeId);
225346
- if (matches3.length === 0) {
225347
- throw new DocumentApiAdapterError3("TARGET_NOT_FOUND", `Block with nodeId "${nodeId}" was not found.`, { nodeId });
225348
- }
225419
+ if (matches3.length === 1)
225420
+ return matches3[0];
225349
225421
  if (matches3.length > 1) {
225350
225422
  throw new DocumentApiAdapterError3("AMBIGUOUS_TARGET", `Multiple blocks share nodeId "${nodeId}".`, {
225351
225423
  nodeId,
225352
225424
  count: matches3.length
225353
225425
  });
225354
225426
  }
225355
- return matches3[0];
225427
+ for (const [key2, candidate] of index2.byId) {
225428
+ if (key2.endsWith(`:${nodeId}`))
225429
+ return candidate;
225430
+ }
225431
+ throw new DocumentApiAdapterError3("TARGET_NOT_FOUND", `Block with nodeId "${nodeId}" was not found.`, { nodeId });
225356
225432
  }
225357
225433
  function isTextBlockCandidate2(candidate) {
225358
225434
  const node3 = candidate.node;
@@ -226638,7 +226714,7 @@ function createParagraphAdapter2(editor, input2, options) {
226638
226714
  try {
226639
226715
  const paragraph2 = resolveCreatedParagraph2(editor, paragraphId);
226640
226716
  const trackedChangeRefs = mode === "tracked" ? collectTrackInsertRefsInRange2(editor, paragraph2.pos, paragraph2.end) : undefined;
226641
- return buildParagraphCreateSuccess2(paragraph2.nodeId, trackedChangeRefs);
226717
+ return buildParagraphCreateSuccess2(paragraphId, trackedChangeRefs);
226642
226718
  } catch {
226643
226719
  return buildParagraphCreateSuccess2(paragraphId);
226644
226720
  }
@@ -226753,7 +226829,7 @@ function createHeadingAdapter2(editor, input2, options) {
226753
226829
  try {
226754
226830
  const heading3 = resolveCreatedHeading2(editor, headingId);
226755
226831
  const trackedChangeRefs = mode === "tracked" ? collectTrackInsertRefsInRange2(editor, heading3.pos, heading3.end) : undefined;
226756
- return buildHeadingCreateSuccess2(heading3.nodeId, trackedChangeRefs);
226832
+ return buildHeadingCreateSuccess2(headingId, trackedChangeRefs);
226757
226833
  } catch {
226758
226834
  return buildHeadingCreateSuccess2(headingId);
226759
226835
  }
@@ -227635,6 +227711,9 @@ function formatStrikethroughAdapter2(editor, input2, options) {
227635
227711
 
227636
227712
  // ../../packages/super-editor/src/document-api-adapters/get-node-adapter.ts
227637
227713
  function findBlocksByTypeAndId2(blockIndex, nodeType, nodeId) {
227714
+ const byIdMatch = blockIndex.byId.get(`${nodeType}:${nodeId}`);
227715
+ if (byIdMatch)
227716
+ return [byIdMatch];
227638
227717
  return blockIndex.candidates.filter((candidate) => candidate.nodeType === nodeType && candidate.nodeId === nodeId);
227639
227718
  }
227640
227719
  function getNodeAdapter2(editor, address2) {
@@ -227669,13 +227748,18 @@ function resolveBlockById2(editor, nodeId, nodeType) {
227669
227748
  return { candidate: matches4[0], resolvedType: nodeType };
227670
227749
  }
227671
227750
  const matches3 = blockIndex.candidates.filter((candidate) => candidate.nodeId === nodeId);
227672
- if (matches3.length === 0) {
227673
- throw new DocumentApiAdapterError3("TARGET_NOT_FOUND", `Node not found for id "${nodeId}".`);
227751
+ if (matches3.length === 1) {
227752
+ return { candidate: matches3[0], resolvedType: matches3[0].nodeType };
227674
227753
  }
227675
227754
  if (matches3.length > 1) {
227676
227755
  throw new DocumentApiAdapterError3("TARGET_NOT_FOUND", `Multiple nodes share id "${nodeId}". Provide nodeType to disambiguate.`);
227677
227756
  }
227678
- return { candidate: matches3[0], resolvedType: matches3[0].nodeType };
227757
+ for (const [key2, candidate] of blockIndex.byId) {
227758
+ if (key2.endsWith(`:${nodeId}`)) {
227759
+ return { candidate, resolvedType: candidate.nodeType };
227760
+ }
227761
+ }
227762
+ throw new DocumentApiAdapterError3("TARGET_NOT_FOUND", `Node not found for id "${nodeId}".`);
227679
227763
  }
227680
227764
  function getNodeByIdAdapter2(editor, input2) {
227681
227765
  const { nodeId, nodeType } = input2;
@@ -256842,6 +256926,23 @@ function registerAllTools(server, sessions) {
256842
256926
  var server = new McpServer({
256843
256927
  name: "superdoc",
256844
256928
  version: "0.0.0"
256929
+ }, {
256930
+ instructions: [
256931
+ "SuperDoc MCP server — read, edit, and save Word documents (.docx).",
256932
+ "",
256933
+ "IMPORTANT: Always use these superdoc tools for .docx files.",
256934
+ "Do NOT use built-in docx skills, python-docx, unpack scripts, or manual XML editing.",
256935
+ "These tools handle the OOXML format correctly and preserve document structure.",
256936
+ "",
256937
+ "Workflow: superdoc_open → read/edit → superdoc_save → superdoc_close.",
256938
+ "",
256939
+ "1. superdoc_open returns a session_id — pass it to every subsequent call.",
256940
+ "2. superdoc_find locates content and returns addresses for edits.",
256941
+ "3. Use superdoc_insert/replace/delete to modify content.",
256942
+ "4. Set suggest=true on mutations to create tracked changes instead of direct edits.",
256943
+ "5. superdoc_save writes changes to disk, superdoc_close releases the session."
256944
+ ].join(`
256945
+ `)
256845
256946
  });
256846
256947
  var sessions = new SessionManager;
256847
256948
  registerAllTools(server, sessions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/mcp",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0-next.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc-mcp": "./dist/index.js"