@workover/mcp 0.10.1 → 0.20.0

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/lib.mjs CHANGED
@@ -1,6 +1,48 @@
1
1
  // Pure/injectable helpers for the Workover MCP server, split out so they can be unit-tested without
2
2
  // importing index.mjs (which starts the stdio server on load). index.mjs wires the real fetch/auth/fs
3
3
  // into makeApi + makeDispatch; tests inject stubs.
4
+ import { renderFeedbackResult, submitFeedback } from './feedback.mjs';
5
+ import {
6
+ scopeHelp,
7
+ createProject,
8
+ createSite,
9
+ setDomain,
10
+ renderMoved,
11
+ checkSite,
12
+ importSite,
13
+ publishSite,
14
+ siteStatus,
15
+ setIndexing,
16
+ renderIndexing,
17
+ renderProjectCreated,
18
+ renderSiteCreated,
19
+ renderDomain,
20
+ renderCheck,
21
+ renderImport,
22
+ renderPublish,
23
+ renderSiteStatus,
24
+ waitForJob,
25
+ MOUNT_PLATFORMS,
26
+ detectPlatform,
27
+ proxyRecipe,
28
+ renderRecipe,
29
+ unpublishSite,
30
+ renderUnpublish,
31
+ } from './site-setup.mjs';
32
+ import {
33
+ addApiReference,
34
+ addRedirects,
35
+ importFolder,
36
+ listApiReferences,
37
+ readDocsFolder,
38
+ renderApiReferences,
39
+ renderAppearance,
40
+ renderFolderImport,
41
+ renderRedirects,
42
+ setAppearance,
43
+ syncApiReferences,
44
+ uploadWith,
45
+ } from './site-folder.mjs';
4
46
  import { realpathSync, statSync } from 'fs';
5
47
  import { basename } from 'path';
6
48
 
@@ -12,6 +54,33 @@ export const stripHtml = (h) =>
12
54
  .replace(/\s+/g, ' ')
13
55
  .trim();
14
56
 
57
+ /**
58
+ * The Mintlify components a docs-site document reads and writes as themselves (WO-1299).
59
+ *
60
+ * A test in apps/api (agent-docs.spec.ts) holds this list equal to the converter's own and to the
61
+ * editor's, so the syntax an agent is told about cannot drift from the syntax that round-trips.
62
+ */
63
+ export const MDX_COMPONENTS = [
64
+ 'Accordion', 'AccordionGroup', 'Badge', 'Callout', 'Card', 'CardGroup', 'Check', 'CodeGroup',
65
+ 'Color', 'Color.Item', 'Color.Row', 'Column', 'Columns', 'Danger', 'Expandable', 'FileTree',
66
+ 'Frame', 'GitHub.Repo', 'Icon', 'Info', 'MDX', 'Note', 'Panel', 'ParamField', 'Prompt',
67
+ 'RequestExample', 'ResponseExample', 'ResponseField', 'Step', 'Steps', 'Tab', 'Tabs', 'Tile',
68
+ 'Tip', 'Tooltip', 'Tree', 'Tree.File', 'Tree.Folder', 'Update', 'View', 'Visibility', 'Visible',
69
+ 'Warning',
70
+ ];
71
+
72
+ /** What an agent needs to know to write a docs-site document. Used in the tool descriptions. */
73
+ export const MDX_FORMAT_NOTE =
74
+ 'FORMAT: a document in a docs-site project (one with a published site or a Git sync) is Mintlify MDX, not plain markdown, and workover_read_doc says "Format: Mintlify MDX" when it is. Write in the same MDX you read: components as JSX (`<Note>text</Note>`, `<CardGroup cols={2}><Card title="Setup" icon="gear" href="/setup">text</Card></CardGroup>`, `<Steps><Step title="Install">text</Step></Steps>`, `<Tabs><Tab title="npm">text</Tab></Tabs>`, inline `<Icon icon="rocket" />`), math as `$x^2$` or a `$$` block, a snippet as `<Snippet file="snippets/x.mdx" />` or as it was printed, and `{{name}}` for a Workover variable. ' +
75
+ `Components: ${MDX_COMPONENTS.join(', ')}. ` +
76
+ 'Keep every block you do not mean to change exactly as it was printed, including tags and lines you do not recognise. A direct edit that would delete a component, snippet, math or embed is refused with a 422 naming them, unless allowBlockRemoval is set. In any other project documents are plain markdown, and a body with components is refused rather than written without them.';
77
+
78
+ /** The line workover_read_doc adds when the body is MDX, so the agent writes back what it read. */
79
+ export const formatLine = (format) =>
80
+ format === 'mdx'
81
+ ? 'Format: Mintlify MDX (this is a docs-site document; write it back as MDX, keeping its components).\n\n'
82
+ : '';
83
+
15
84
  /** Wrap a string as a successful MCP tool result. */
16
85
  export const text = (t) => ({ content: [{ type: 'text', text: t }] });
17
86
 
@@ -198,6 +267,34 @@ const WEB_FOR_API = {
198
267
  'api.workover.test': 'workover.test',
199
268
  };
200
269
 
270
+ /** The web app for a signed-in api (`https://workover.io`), or null for one this does not know. */
271
+ export const webForApiBase = (api) => {
272
+ try {
273
+ const web = WEB_FOR_API[new URL(String(api)).hostname.toLowerCase()];
274
+ return web ? `https://${web}` : null;
275
+ } catch {
276
+ return null;
277
+ }
278
+ };
279
+
280
+ /** The Help Center tools (site-setup.mjs), all behind the `site` scope. */
281
+ export const SITE_TOOLS = new Set([
282
+ 'workover_create_project',
283
+ 'workover_create_site',
284
+ 'workover_import_site',
285
+ 'workover_set_domain',
286
+ 'workover_check_site',
287
+ 'workover_publish_site',
288
+ 'workover_site_status',
289
+ 'workover_set_site_indexing',
290
+ 'workover_set_site_appearance',
291
+ 'workover_add_site_redirects',
292
+ 'workover_add_api_reference',
293
+ 'workover_sync_api_reference',
294
+ 'workover_proxy_setup',
295
+ 'workover_unpublish_site',
296
+ ]);
297
+
201
298
  /**
202
299
  * A sentence when a document link is for a different Workover than the one signed in to, else null.
203
300
  *
@@ -273,6 +370,50 @@ export const resolveDoc = async (api, value, apiBase) => {
273
370
  };
274
371
 
275
372
  /** Kept for callers of the earlier helper: the row id, or null. */
373
+ /**
374
+ * What `workover_propose_edit` did, from the api's `outcome` (WO-1748). An api older than the field
375
+ * answers without one, and is described the way every proposal used to be.
376
+ */
377
+ export function proposeOutcomeText(res, docId) {
378
+ const where = `${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}`;
379
+ const id = res?.id != null ? ` (suggestion #${res.id})` : '';
380
+ const check = 'workover_suggestion_status says whether the editor has shown it.';
381
+ if (res?.outcome === 'unchanged')
382
+ return `Nothing changed: the open suggestion on ${where}${id} already says exactly this. ${check}`;
383
+ if (res?.outcome === 'held')
384
+ return `Not applied: the open suggestion on ${where}${id} is out with Workover AI for a revision, and your text would be overwritten when that lands. Propose again once workover_suggestion_status says it is back.`;
385
+ if (res?.outcome === 'reoffered')
386
+ return `The open suggestion on ${where}${id} already says exactly this, and the editor had not been able to show it. It is offered again the next time someone who can review it opens the document; if it still cannot be shown, workover_suggestion_status says why.`;
387
+ const verb = res?.outcome === 'updated' ? 'Updated the open suggestion on' : 'Proposed your changes to';
388
+ return `${verb} ${where}${id}. They appear as tracked changes to accept or reject the next time someone who can review them opens the document in Workover. ${check}`;
389
+ }
390
+
391
+ /** The answer to `workover_suggestion_status`, from `GET /project/doc/:id/proposals/current`. */
392
+ export function suggestionStatusText(current, docId) {
393
+ if (!current)
394
+ return `Document #${docId} has no open suggestion. One raised earlier was accepted or dismissed, or none was raised.`;
395
+ const from = current.proposedBy?.name
396
+ ? `${current.proposedBy.name} via ${current.source}`
397
+ : current.source;
398
+ const lines = [
399
+ `Suggestion #${current.id} on document #${docId}, from ${from}, raised ${current.createdAt}${current.revisions ? `, revised ${current.revisions} time${current.revisions === 1 ? '' : 's'}` : ''}.`,
400
+ ];
401
+ if (current.tabField) lines.push(`Against tab "${current.tabField}".`);
402
+ if (current.status === 'refining')
403
+ lines.push('It is out with Workover AI for a revision, so it is not on the page right now.');
404
+ else if (current.editorRefusal)
405
+ lines.push(
406
+ `The editor could NOT show it as tracked changes, so nothing is on the page: ${current.editorRefusal}`,
407
+ 'Propose a version that avoids that, or send the same text again to have the editor try once more.',
408
+ );
409
+ else if (current.shownAt)
410
+ lines.push(`Shown in the editor at ${current.shownAt}, waiting for someone to accept or reject it.`);
411
+ else
412
+ lines.push('Not shown yet: it appears the next time someone who can review it opens the document.');
413
+ if (current.note) lines.push(`Note: ${current.note}`);
414
+ return lines.join('\n');
415
+ }
416
+
276
417
  export const resolveDocId = async (api, value) => (await resolveDoc(api, value)).id ?? null;
277
418
 
278
419
  const decodeAttr = (v) =>
@@ -433,7 +574,181 @@ export function makeApi({ auth, fetchImpl = fetch }) {
433
574
  * short-circuits before any request; unknown tools and thrown errors become `err(...)`. `readFile`
434
575
  * and `fetchImpl` are injected so the upload path is testable without touching the disk/network.
435
576
  */
436
- export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps }) {
577
+ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps, siteWait, clientInfo }) {
578
+ // The site tools' caller (site-setup.mjs): the same authenticated `api`, with a body as JSON.
579
+ const call = (path, { method, body } = {}) =>
580
+ api(path, {
581
+ method: method || 'GET',
582
+ ...(body ? { headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}),
583
+ });
584
+ // An MCP call should not hold the client for minutes: an import or publish still running after
585
+ // this is handed back as running, and asking again joins it on the server.
586
+ const wait = { timeoutMs: 50_000, ...(siteWait || {}) };
587
+ const web = webForApiBase(auth?.api);
588
+ // The CLI's lines, without the terminal's two-space margin.
589
+ const lines = (l) =>
590
+ text(
591
+ l
592
+ .map((x) => x.replace(/^ {2}/, ''))
593
+ .join('\n')
594
+ .replace(/^\n+/, '')
595
+ .trimEnd(),
596
+ );
597
+
598
+ /** The Help Center tools. Every one needs a token from `workover login --site`. */
599
+ async function siteTool(name, args) {
600
+ const projectId = args.projectId === undefined ? null : rowId(args.projectId);
601
+ if (name !== 'workover_create_project' && !(name === 'workover_site_status' && args.projectId === undefined)) {
602
+ if (projectId === null) return badIdErr('project', args.projectId);
603
+ }
604
+ try {
605
+ if (name === 'workover_create_project') {
606
+ const res = await createProject(call, {
607
+ workspace: args.workspace,
608
+ name: args.name,
609
+ address: args.address,
610
+ start: args.start ?? 'blank',
611
+ });
612
+ return lines(renderProjectCreated(res, { web }));
613
+ }
614
+ if (name === 'workover_create_site') {
615
+ const res = await createSite(call, { projectId, address: args.address });
616
+ return lines(renderSiteCreated(res));
617
+ }
618
+ if (name === 'workover_import_site' && typeof args.dir === 'string' && !args.checkOnly) {
619
+ const plan = readDocsFolder(args.dir);
620
+ const path = `/sites/project/${projectId}/import`;
621
+ const res = await importFolder(call, {
622
+ projectId,
623
+ plan,
624
+ waitFor: (first) => waitForJob(() => call(path), { first, ...wait }),
625
+ });
626
+ const out = lines(renderFolderImport(res, { projectId, plan }));
627
+ return res.status === 'failed' ? err(out.content[0].text) : out;
628
+ }
629
+ if (name === 'workover_set_site_appearance') {
630
+ const plan = typeof args.from === 'string' ? readDocsFolder(args.from) : null;
631
+ const pick = (keys) => Object.fromEntries(keys.filter((k) => typeof args[k] === 'string').map((k) => [k, args[k]]));
632
+ const appearance = { ...(plan?.appearance ?? {}), ...pick(['primary', 'primaryDark', 'searchPrompt']) };
633
+ const files = {
634
+ ...(plan?.assets ?? {}),
635
+ ...(typeof args.logo === 'string' ? { logoLight: args.logo } : {}),
636
+ ...pick(['logoDark', 'favicon', 'faviconDark']),
637
+ };
638
+ if (!Object.keys(appearance).length && !Object.keys(files).length)
639
+ return err('Name something to set: from (a docs folder), a color, or a logo or favicon file.');
640
+ const res = await setAppearance(call, uploadWith(api), { projectId, appearance, files });
641
+ return lines(renderAppearance(res));
642
+ }
643
+ if (name === 'workover_add_site_redirects') {
644
+ if (typeof args.from !== 'string') return err('Pass `from`: the docs folder, or its _site.json or docs.json.');
645
+ const res = await addRedirects(call, { projectId, redirects: readDocsFolder(args.from).redirects });
646
+ return lines(renderRedirects(res));
647
+ }
648
+ if (name === 'workover_add_api_reference') {
649
+ if (typeof args.spec !== 'string') return err('Pass `spec`: the https URL of the OpenAPI spec, or {api}/openapi.json.');
650
+ const res = await addApiReference(call, {
651
+ projectId,
652
+ spec: args.spec,
653
+ tab: typeof args.tab === 'string' ? args.tab : undefined,
654
+ group: typeof args.group === 'string' ? args.group : undefined,
655
+ directory: typeof args.directory === 'string' ? args.directory : undefined,
656
+ });
657
+ return lines(renderApiReferences(res, { projectId, verb: 'add' }));
658
+ }
659
+ if (name === 'workover_sync_api_reference') {
660
+ const res = args.checkOnly
661
+ ? await listApiReferences(call, { projectId })
662
+ : await syncApiReferences(call, { projectId });
663
+ const out = lines(renderApiReferences(res, { projectId, verb: args.checkOnly ? 'list' : 'sync' }));
664
+ return res.references.some((r) => r.outcome?.status === 'failed') ? err(out.content[0].text) : out;
665
+ }
666
+ if (name === 'workover_import_site') {
667
+ const state = args.checkOnly
668
+ ? await call(`/sites/project/${projectId}/import`)
669
+ : await importSite(call, { projectId, url: args.url, ...wait });
670
+ return state?.status === 'failed'
671
+ ? err(lines(renderImport(state, { projectId })).content[0].text)
672
+ : lines(renderImport(state, { projectId }));
673
+ }
674
+ if (name === 'workover_set_domain') {
675
+ const res = await setDomain(call, {
676
+ projectId,
677
+ address: args.domain,
678
+ preverify: args.preverify === true,
679
+ moveFrom: args.moveFrom ?? null,
680
+ });
681
+ if (res.disconnected)
682
+ return text('Disconnected the custom domain. The workover.site address keeps working. Remove its DNS records.');
683
+ const guess = res.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
684
+ if (res.movedFrom)
685
+ return lines([...renderMoved(res), ...renderDomain(res.domain, { projectId, ...guess })]);
686
+ return lines([
687
+ ...renderDomain(res.domain, { projectId, ...guess }),
688
+ 'Give the person every record above exactly as printed (type, name, value). Adding them at the DNS provider is their step.',
689
+ ]);
690
+ }
691
+ if (name === 'workover_check_site') {
692
+ const res = await checkSite(call, { projectId });
693
+ return lines(renderCheck(res, { projectId }));
694
+ }
695
+ if (name === 'workover_proxy_setup') {
696
+ const view = await call(`/sites/project/${projectId}`);
697
+ if (!view?.site) return err(`Project #${projectId} has no Help Center. workover_create_site adds one.`);
698
+ const domain = view.site.domain;
699
+ const asked = typeof args.platform === 'string' ? args.platform.toLowerCase() : null;
700
+ if (asked && !MOUNT_PLATFORMS.includes(asked)) return err(`No setup for "${asked}". One of: ${MOUNT_PLATFORMS.join(', ')}.`);
701
+ proxyRecipe(domain, MOUNT_PLATFORMS[0]); // throws, with what to do, when the site is not under a path
702
+ const guess = asked ? { platform: asked, evidence: null } : await detectPlatform(call, { projectId });
703
+ if (!guess.platform)
704
+ return err(`Could not tell where ${domain.hostname} runs from its headers. Ask the person, then pass platform: one of ${MOUNT_PLATFORMS.join(', ')}.`);
705
+ const recipe = proxyRecipe(domain, guess.platform);
706
+ return lines([
707
+ ...(asked ? [] : [`${domain.hostname} runs on ${recipe.label}${guess.evidence ? ` (${guess.evidence})` : ''}.`, '']),
708
+ ...renderRecipe(recipe),
709
+ '',
710
+ recipe.file
711
+ ? `If the website's code is in the repository you are working in, add this there (as ${recipe.file}${recipe.platform === 'vercel' || recipe.platform === 'netlify' ? ', its two rules first' : ''}); otherwise hand it to the person. Then workover_check_site says whether it works.`
712
+ : "Add this where it says (it cannot be a file of its own), or hand it to the person. Then workover_check_site says whether it works.",
713
+ ]);
714
+ }
715
+ if (name === 'workover_unpublish_site') {
716
+ await unpublishSite(call, { projectId });
717
+ return lines(renderUnpublish({ projectId }));
718
+ }
719
+ if (name === 'workover_publish_site') {
720
+ const state = args.checkOnly
721
+ ? await call(`/sites/project/${projectId}/publish`)
722
+ : await publishSite(call, { projectId, ...wait });
723
+ const site = state?.status === 'done' ? (await call(`/sites/project/${projectId}`))?.site : null;
724
+ const out = lines(renderPublish(state, { projectId, site }));
725
+ return state?.status === 'failed' ? err(out.content[0].text) : out;
726
+ }
727
+ if (name === 'workover_set_site_indexing') {
728
+ if (typeof args.index !== 'boolean') return err('Pass `index`: true to let search engines index the site, false to ask them not to.');
729
+ const res = await setIndexing(call, { projectId, index: args.index });
730
+ return lines(renderIndexing(res));
731
+ }
732
+ if (name === 'workover_site_status') {
733
+ if (projectId === null) {
734
+ const res = await call('/project');
735
+ const list = (Array.isArray(res) ? res : res?.projects || []).filter((p) => p.hasSite);
736
+ return text(
737
+ list.length
738
+ ? `Projects with a Help Center:\n${list.map((p) => `#${p.id}: ${p.name || p.title || 'Project'}`).join('\n')}`
739
+ : 'No project has a Help Center yet. workover_create_project makes one.',
740
+ );
741
+ }
742
+ const res = await siteStatus(call, { projectId });
743
+ return lines(renderSiteStatus(res, { projectId }));
744
+ }
745
+ } catch (e) {
746
+ const help = scopeHelp(e?.message);
747
+ return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
748
+ }
749
+ return err(`Unknown tool: ${name}`);
750
+ }
751
+
437
752
  return async function dispatch(name, args = {}) {
438
753
  if (!auth)
439
754
  return err(
@@ -600,7 +915,7 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
600
915
  const rules = await fetchRules(api, d.projectId);
601
916
 
602
917
  return text(
603
- `# ${d.title || 'Untitled'} (id ${d.id})\n\n${body}${tabNote}${renderStyleGuide(rules)}`,
918
+ `# ${d.title || 'Untitled'} (id ${d.id})\n\n${formatLine(live?.format)}${body}${tabNote}${renderStyleGuide(rules)}`,
604
919
  );
605
920
  }
606
921
  if (name === 'workover_list_projects') {
@@ -768,25 +1083,61 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
768
1083
  }
769
1084
  if (name === 'workover_edit_doc') {
770
1085
  const md = String(args.markdown || '').trim();
771
- if (!md) return err('Provide the full revised document as `markdown`.');
1086
+ // A rename rides on the direct-edit tool: `title` alone renames without touching the body.
1087
+ const wantsRename = args.title != null;
1088
+ const title = wantsRename ? String(args.title).trim().replace(/\s+/g, ' ') : '';
1089
+ if (!md && !wantsRename)
1090
+ return err(
1091
+ 'Provide the full revised document as `markdown`, a new name as `title`, or both.',
1092
+ );
1093
+ if (wantsRename && !title) return err('`title` cannot be empty. Omit it to keep the current name.');
1094
+ if (title.length > MAX_DOC_TITLE)
1095
+ return err(`\`title\` can be ${MAX_DOC_TITLE} characters at most (this one is ${title.length}).`);
772
1096
  const doc = await resolveDoc(api, docArg(args), auth.api);
773
1097
  if (doc.error) return doc.error;
774
1098
  const docId = doc.id;
775
1099
  const tabId = args.tabId == null ? null : rowId(args.tabId);
776
1100
  if (args.tabId != null && tabId === null)
777
1101
  return badIdErr('tab', args.tabId);
1102
+ if (!md) {
1103
+ // Title only: the body is not sent, so it cannot change.
1104
+ if (tabId != null)
1105
+ return err(
1106
+ '`title` renames the whole document, not a tab. Pass `title` without `tabId`, or pass `markdown` to write that tab.',
1107
+ );
1108
+ try {
1109
+ return text(renderRenameText(await renameDoc(api, docId, title)));
1110
+ } catch (e) {
1111
+ return err(renameRefusalText(e?.message));
1112
+ }
1113
+ }
778
1114
  const res = await apiPost(`/project/doc/${docId}/content`, {
779
1115
  markdown: md,
780
1116
  note: args.note ? String(args.note) : undefined,
781
1117
  source: 'Claude Code',
782
1118
  ...(tabId != null ? { tabId } : {}),
1119
+ // Removing a component, snippet, math or embed is refused unless the agent says it means
1120
+ // to (WO-1299). Only an explicit true counts.
1121
+ ...(args.allowBlockRemoval === true ? { allowBlockRemoval: true } : {}),
783
1122
  });
1123
+ const removed = Array.isArray(res?.removedBlocks) && res.removedBlocks.length
1124
+ ? `\n\nRemoved as asked: ${res.removedBlocks.join(', ')}.`
1125
+ : '';
1126
+ // The body first, then the name: a body the server refuses leaves the name alone too.
1127
+ let renamed = '';
1128
+ if (wantsRename) {
1129
+ try {
1130
+ renamed = `\n\n${renderRenameText(await renameDoc(api, docId, title))}`;
1131
+ } catch (e) {
1132
+ renamed = `\n\nThe body was written, but the rename was not: ${renameRefusalText(e?.message)}`;
1133
+ }
1134
+ }
784
1135
  return text(
785
1136
  `Edited ${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId} directly — the new text is in the document and there is nothing to accept.${res?.documentUrl ? `\n${res.documentUrl}` : ''}${
786
1137
  res?.replacedCharacters
787
1138
  ? `\n\nReplaced ${res.replacedCharacters} characters of existing text.`
788
1139
  : ''
789
- }${renderStyleFeedback(res?.style)}`,
1140
+ }${removed}${renamed}${renderStyleFeedback(res?.style)}`,
790
1141
  );
791
1142
  }
792
1143
  if (name === 'workover_propose_edit') {
@@ -809,12 +1160,136 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
809
1160
  : {}),
810
1161
  });
811
1162
  return text(
812
- `Proposed your changes to ${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}. They'll appear as suggestions to accept or reject when the document is open in Workover${res?.documentUrl ? `:\n${res.documentUrl}` : '.'}\n\nNothing is published until the person reviews and accepts.${renderStyleFeedback(res?.style)}`,
1163
+ `${proposeOutcomeText(res, docId)}${res?.documentUrl ? `\n${res.documentUrl}` : ''}\n\nNothing is published until the person reviews and accepts.${renderStyleFeedback(res?.style)}`,
813
1164
  );
814
1165
  }
1166
+ if (name === 'workover_suggestion_status') {
1167
+ // Whether a suggestion raised through workover_propose_edit reached the page (WO-1748):
1168
+ // before this the only answer was the propose call's own "they'll appear", which was said
1169
+ // whether or not the editor could show them.
1170
+ const doc = await resolveDoc(api, docArg(args), auth.api);
1171
+ if (doc.error) return doc.error;
1172
+ const docId = doc.id;
1173
+ const current = await api(`/project/doc/${docId}/proposals/current`);
1174
+ return text(suggestionStatusText(current, docId));
1175
+ }
1176
+ if (name === 'workover_doc_status') {
1177
+ // The document's WORKOVER status, read or set through the browser's rules (WO-1264). It
1178
+ // never publishes: the WordPress post is a separate thing, and the answer says so.
1179
+ const doc = await resolveDoc(api, docArg(args), auth.api);
1180
+ if (doc.error) return doc.error;
1181
+ const docId = doc.id;
1182
+ const wanted = typeof args.status === 'string' ? args.status.trim() : '';
1183
+ let res;
1184
+ try {
1185
+ res = wanted
1186
+ ? await api(`/project/doc/${docId}/status`, {
1187
+ method: 'PATCH',
1188
+ headers: { 'content-type': 'application/json' },
1189
+ body: JSON.stringify({ status: wanted }),
1190
+ })
1191
+ : await api(`/project/doc/${docId}/status`);
1192
+ } catch (e) {
1193
+ return err(statusRefusalText(e?.message));
1194
+ }
1195
+ return text(wanted ? renderStatusChangeText(res) : renderStatusListText(res));
1196
+ }
1197
+ if (name === 'workover_report_feedback') {
1198
+ // The version and client are this server's to state, not the agent's: they come from the
1199
+ // MCP handshake, so a report says which release and which client it came from.
1200
+ const info = typeof clientInfo === 'function' ? clientInfo() : {};
1201
+ try {
1202
+ const res = await submitFeedback(call, args, { surface: 'mcp', ...info });
1203
+ return lines(renderFeedbackResult(res));
1204
+ } catch (e) {
1205
+ return err(e?.message || 'The report was not sent.');
1206
+ }
1207
+ }
1208
+ if (SITE_TOOLS.has(name)) return await siteTool(name, args);
815
1209
  return err(`Unknown tool: ${name}`);
816
1210
  } catch (e) {
817
1211
  return err(e?.message || 'Something went wrong.');
818
1212
  }
819
1213
  };
820
1214
  }
1215
+
1216
+ /** The longest title a rename accepts; the API's `MAX_DOCUMENT_TITLE` (document-title.ts). */
1217
+ export const MAX_DOC_TITLE = 200;
1218
+
1219
+ /** `PATCH /project/doc/:docId/title`: the editor's rename, by document id. Never sends a body. */
1220
+ const renameDoc = (api, docId, title) =>
1221
+ api(`/project/doc/${docId}/title`, {
1222
+ method: 'PATCH',
1223
+ headers: { 'content-type': 'application/json' },
1224
+ body: JSON.stringify({ title }),
1225
+ });
1226
+
1227
+ /** What a rename did, in one sentence. */
1228
+ export const renderRenameText = (r) =>
1229
+ r?.changed === false
1230
+ ? `Document #${r.documentId} is already called "${r.title}". Nothing changed.`
1231
+ : `Renamed document #${r?.documentId} from "${r?.previous || 'Untitled'}" to "${r?.title}". The body was not changed, and neither was any linked WordPress post or its slug.${r?.documentUrl ? `\n${r.documentUrl}` : ''}`;
1232
+
1233
+ /** A refused rename: the API's reason, or a plain note when the server predates the route. */
1234
+ export const renameRefusalText = (message) => {
1235
+ const m = String(message || 'Workover refused the rename.');
1236
+ if (/login expired|Not signed in/i.test(m)) return m;
1237
+ if (/\(404\): Cannot PATCH /.test(m))
1238
+ return 'This Workover server cannot rename documents from here yet. It arrives with the next release; until then, rename it in the editor.';
1239
+ return `Refused: ${m.replace(/^Workover API error \((\d+)\):\s*/, '')}`;
1240
+ };
1241
+
1242
+ /** The WordPress side of a status answer: separate from the Workover status, and said so. */
1243
+ const wordpressNote = (r) =>
1244
+ r?.wordpress
1245
+ ? `WordPress post #${r.wordpress.postId} is ${r.wordpress.liveStatus || 'in an unknown status'}. The Workover status does not change it; a post goes live only from the document's WordPress tab, which this tool cannot do.`
1246
+ : 'This document is not linked to a WordPress post.';
1247
+
1248
+ /** `workover_doc_status` with no status: the current status and every status, allowed or why not. */
1249
+ export const renderStatusListText = (r) => {
1250
+ const lines = [
1251
+ `Document #${r.documentId} "${r.title || 'Untitled'}" is ${r.statusLabel} (${r.status}), in the ${r.workflow} workflow.`,
1252
+ ];
1253
+ if (r.pendingApproval)
1254
+ lines.push(`It is waiting on approval for "${r.pendingApproval.statusKey}" (request #${r.pendingApproval.id}).`);
1255
+ lines.push(wordpressNote(r), '', 'Statuses (key: label, then whether you may move it there):');
1256
+ for (const s of r.statuses) {
1257
+ const note =
1258
+ s.key === r.status
1259
+ ? 'current'
1260
+ : s.allowed
1261
+ ? s.needsApproval
1262
+ ? 'allowed; entering it opens an approval request'
1263
+ : 'allowed'
1264
+ : `not allowed: ${s.reason || 'no reason given'}`;
1265
+ lines.push(` ${s.key}: ${s.label} (${note})`);
1266
+ }
1267
+ lines.push('', 'Pass `status` with one of the keys to set it.');
1268
+ return lines.join('\n');
1269
+ };
1270
+
1271
+ /** `workover_doc_status` with a status: moved, moved and waiting on approval, or already there. */
1272
+ export const renderStatusChangeText = (r) => {
1273
+ const label = (key) => r.statuses?.find((s) => s.key === key)?.label || key;
1274
+ const lines = [];
1275
+ if (!r.changed) lines.push(`Document #${r.documentId} was already ${label(r.status)} (${r.status}). Nothing changed.`);
1276
+ else {
1277
+ lines.push(`Changed: document #${r.documentId} moved from ${label(r.previous)} to ${label(r.status)}.`);
1278
+ if (r.pendingApproval && r.pendingApproval.statusKey === r.status)
1279
+ lines.push(
1280
+ `It is now waiting on approval (request #${r.pendingApproval.id}); the approvers have been asked, and it moves on once they approve.`,
1281
+ );
1282
+ }
1283
+ lines.push(wordpressNote(r));
1284
+ return lines.join('\n');
1285
+ };
1286
+
1287
+ /** A refused status change: "Refused: <the API's reason>", or the sign-in message as it is. */
1288
+ export const statusRefusalText = (message) => {
1289
+ const m = String(message || 'Workover refused the change.');
1290
+ if (/login expired|Not signed in/i.test(m)) return m;
1291
+ // Nest's own 404 for a route it does not have: a server older than this tool (WO-1264).
1292
+ if (/\(404\): Cannot (GET|PATCH) /.test(m))
1293
+ return 'This Workover server does not support workover_doc_status yet. It arrives with the next release.';
1294
+ return `Refused: ${m.replace(/^Workover API error \((\d+)\):\s*/, '')}`;
1295
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/mcp",
3
- "version": "0.10.1",
3
+ "version": "0.20.0",
4
4
  "description": "Workover MCP server — let Claude Code and other MCP clients read and cowork on your Workover documents.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ScaleMath",
@@ -22,7 +22,10 @@
22
22
  "files": [
23
23
  "index.mjs",
24
24
  "lib.mjs",
25
+ "site-setup.mjs",
26
+ "site-folder.mjs",
25
27
  "telemetry.mjs",
28
+ "feedback.mjs",
26
29
  "README.md"
27
30
  ],
28
31
  "engines": {
@@ -32,7 +35,7 @@
32
35
  "access": "public"
33
36
  },
34
37
  "dependencies": {
35
- "@modelcontextprotocol/sdk": "^1.31.0"
38
+ "@modelcontextprotocol/sdk": "^1.32.2"
36
39
  },
37
40
  "scripts": {
38
41
  "test": "node --test"