@workover/mcp 0.10.1 → 0.19.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/README.md +36 -2
- package/feedback.mjs +123 -0
- package/index.mjs +313 -17
- package/lib.mjs +425 -4
- package/package.json +5 -2
- package/site-folder.mjs +778 -0
- package/site-setup.mjs +925 -0
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
|
*
|
|
@@ -433,7 +530,181 @@ export function makeApi({ auth, fetchImpl = fetch }) {
|
|
|
433
530
|
* short-circuits before any request; unknown tools and thrown errors become `err(...)`. `readFile`
|
|
434
531
|
* and `fetchImpl` are injected so the upload path is testable without touching the disk/network.
|
|
435
532
|
*/
|
|
436
|
-
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps }) {
|
|
533
|
+
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps, siteWait, clientInfo }) {
|
|
534
|
+
// The site tools' caller (site-setup.mjs): the same authenticated `api`, with a body as JSON.
|
|
535
|
+
const call = (path, { method, body } = {}) =>
|
|
536
|
+
api(path, {
|
|
537
|
+
method: method || 'GET',
|
|
538
|
+
...(body ? { headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}),
|
|
539
|
+
});
|
|
540
|
+
// An MCP call should not hold the client for minutes: an import or publish still running after
|
|
541
|
+
// this is handed back as running, and asking again joins it on the server.
|
|
542
|
+
const wait = { timeoutMs: 50_000, ...(siteWait || {}) };
|
|
543
|
+
const web = webForApiBase(auth?.api);
|
|
544
|
+
// The CLI's lines, without the terminal's two-space margin.
|
|
545
|
+
const lines = (l) =>
|
|
546
|
+
text(
|
|
547
|
+
l
|
|
548
|
+
.map((x) => x.replace(/^ {2}/, ''))
|
|
549
|
+
.join('\n')
|
|
550
|
+
.replace(/^\n+/, '')
|
|
551
|
+
.trimEnd(),
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
/** The Help Center tools. Every one needs a token from `workover login --site`. */
|
|
555
|
+
async function siteTool(name, args) {
|
|
556
|
+
const projectId = args.projectId === undefined ? null : rowId(args.projectId);
|
|
557
|
+
if (name !== 'workover_create_project' && !(name === 'workover_site_status' && args.projectId === undefined)) {
|
|
558
|
+
if (projectId === null) return badIdErr('project', args.projectId);
|
|
559
|
+
}
|
|
560
|
+
try {
|
|
561
|
+
if (name === 'workover_create_project') {
|
|
562
|
+
const res = await createProject(call, {
|
|
563
|
+
workspace: args.workspace,
|
|
564
|
+
name: args.name,
|
|
565
|
+
address: args.address,
|
|
566
|
+
start: args.start ?? 'blank',
|
|
567
|
+
});
|
|
568
|
+
return lines(renderProjectCreated(res, { web }));
|
|
569
|
+
}
|
|
570
|
+
if (name === 'workover_create_site') {
|
|
571
|
+
const res = await createSite(call, { projectId, address: args.address });
|
|
572
|
+
return lines(renderSiteCreated(res));
|
|
573
|
+
}
|
|
574
|
+
if (name === 'workover_import_site' && typeof args.dir === 'string' && !args.checkOnly) {
|
|
575
|
+
const plan = readDocsFolder(args.dir);
|
|
576
|
+
const path = `/sites/project/${projectId}/import`;
|
|
577
|
+
const res = await importFolder(call, {
|
|
578
|
+
projectId,
|
|
579
|
+
plan,
|
|
580
|
+
waitFor: (first) => waitForJob(() => call(path), { first, ...wait }),
|
|
581
|
+
});
|
|
582
|
+
const out = lines(renderFolderImport(res, { projectId, plan }));
|
|
583
|
+
return res.status === 'failed' ? err(out.content[0].text) : out;
|
|
584
|
+
}
|
|
585
|
+
if (name === 'workover_set_site_appearance') {
|
|
586
|
+
const plan = typeof args.from === 'string' ? readDocsFolder(args.from) : null;
|
|
587
|
+
const pick = (keys) => Object.fromEntries(keys.filter((k) => typeof args[k] === 'string').map((k) => [k, args[k]]));
|
|
588
|
+
const appearance = { ...(plan?.appearance ?? {}), ...pick(['primary', 'primaryDark', 'searchPrompt']) };
|
|
589
|
+
const files = {
|
|
590
|
+
...(plan?.assets ?? {}),
|
|
591
|
+
...(typeof args.logo === 'string' ? { logoLight: args.logo } : {}),
|
|
592
|
+
...pick(['logoDark', 'favicon', 'faviconDark']),
|
|
593
|
+
};
|
|
594
|
+
if (!Object.keys(appearance).length && !Object.keys(files).length)
|
|
595
|
+
return err('Name something to set: from (a docs folder), a color, or a logo or favicon file.');
|
|
596
|
+
const res = await setAppearance(call, uploadWith(api), { projectId, appearance, files });
|
|
597
|
+
return lines(renderAppearance(res));
|
|
598
|
+
}
|
|
599
|
+
if (name === 'workover_add_site_redirects') {
|
|
600
|
+
if (typeof args.from !== 'string') return err('Pass `from`: the docs folder, or its _site.json or docs.json.');
|
|
601
|
+
const res = await addRedirects(call, { projectId, redirects: readDocsFolder(args.from).redirects });
|
|
602
|
+
return lines(renderRedirects(res));
|
|
603
|
+
}
|
|
604
|
+
if (name === 'workover_add_api_reference') {
|
|
605
|
+
if (typeof args.spec !== 'string') return err('Pass `spec`: the https URL of the OpenAPI spec, or {api}/openapi.json.');
|
|
606
|
+
const res = await addApiReference(call, {
|
|
607
|
+
projectId,
|
|
608
|
+
spec: args.spec,
|
|
609
|
+
tab: typeof args.tab === 'string' ? args.tab : undefined,
|
|
610
|
+
group: typeof args.group === 'string' ? args.group : undefined,
|
|
611
|
+
directory: typeof args.directory === 'string' ? args.directory : undefined,
|
|
612
|
+
});
|
|
613
|
+
return lines(renderApiReferences(res, { projectId, verb: 'add' }));
|
|
614
|
+
}
|
|
615
|
+
if (name === 'workover_sync_api_reference') {
|
|
616
|
+
const res = args.checkOnly
|
|
617
|
+
? await listApiReferences(call, { projectId })
|
|
618
|
+
: await syncApiReferences(call, { projectId });
|
|
619
|
+
const out = lines(renderApiReferences(res, { projectId, verb: args.checkOnly ? 'list' : 'sync' }));
|
|
620
|
+
return res.references.some((r) => r.outcome?.status === 'failed') ? err(out.content[0].text) : out;
|
|
621
|
+
}
|
|
622
|
+
if (name === 'workover_import_site') {
|
|
623
|
+
const state = args.checkOnly
|
|
624
|
+
? await call(`/sites/project/${projectId}/import`)
|
|
625
|
+
: await importSite(call, { projectId, url: args.url, ...wait });
|
|
626
|
+
return state?.status === 'failed'
|
|
627
|
+
? err(lines(renderImport(state, { projectId })).content[0].text)
|
|
628
|
+
: lines(renderImport(state, { projectId }));
|
|
629
|
+
}
|
|
630
|
+
if (name === 'workover_set_domain') {
|
|
631
|
+
const res = await setDomain(call, {
|
|
632
|
+
projectId,
|
|
633
|
+
address: args.domain,
|
|
634
|
+
preverify: args.preverify === true,
|
|
635
|
+
moveFrom: args.moveFrom ?? null,
|
|
636
|
+
});
|
|
637
|
+
if (res.disconnected)
|
|
638
|
+
return text('Disconnected the custom domain. The workover.site address keeps working. Remove its DNS records.');
|
|
639
|
+
const guess = res.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
|
|
640
|
+
if (res.movedFrom)
|
|
641
|
+
return lines([...renderMoved(res), ...renderDomain(res.domain, { projectId, ...guess })]);
|
|
642
|
+
return lines([
|
|
643
|
+
...renderDomain(res.domain, { projectId, ...guess }),
|
|
644
|
+
'Give the person every record above exactly as printed (type, name, value). Adding them at the DNS provider is their step.',
|
|
645
|
+
]);
|
|
646
|
+
}
|
|
647
|
+
if (name === 'workover_check_site') {
|
|
648
|
+
const res = await checkSite(call, { projectId });
|
|
649
|
+
return lines(renderCheck(res, { projectId }));
|
|
650
|
+
}
|
|
651
|
+
if (name === 'workover_proxy_setup') {
|
|
652
|
+
const view = await call(`/sites/project/${projectId}`);
|
|
653
|
+
if (!view?.site) return err(`Project #${projectId} has no Help Center. workover_create_site adds one.`);
|
|
654
|
+
const domain = view.site.domain;
|
|
655
|
+
const asked = typeof args.platform === 'string' ? args.platform.toLowerCase() : null;
|
|
656
|
+
if (asked && !MOUNT_PLATFORMS.includes(asked)) return err(`No setup for "${asked}". One of: ${MOUNT_PLATFORMS.join(', ')}.`);
|
|
657
|
+
proxyRecipe(domain, MOUNT_PLATFORMS[0]); // throws, with what to do, when the site is not under a path
|
|
658
|
+
const guess = asked ? { platform: asked, evidence: null } : await detectPlatform(call, { projectId });
|
|
659
|
+
if (!guess.platform)
|
|
660
|
+
return err(`Could not tell where ${domain.hostname} runs from its headers. Ask the person, then pass platform: one of ${MOUNT_PLATFORMS.join(', ')}.`);
|
|
661
|
+
const recipe = proxyRecipe(domain, guess.platform);
|
|
662
|
+
return lines([
|
|
663
|
+
...(asked ? [] : [`${domain.hostname} runs on ${recipe.label}${guess.evidence ? ` (${guess.evidence})` : ''}.`, '']),
|
|
664
|
+
...renderRecipe(recipe),
|
|
665
|
+
'',
|
|
666
|
+
recipe.file
|
|
667
|
+
? `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.`
|
|
668
|
+
: "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.",
|
|
669
|
+
]);
|
|
670
|
+
}
|
|
671
|
+
if (name === 'workover_unpublish_site') {
|
|
672
|
+
await unpublishSite(call, { projectId });
|
|
673
|
+
return lines(renderUnpublish({ projectId }));
|
|
674
|
+
}
|
|
675
|
+
if (name === 'workover_publish_site') {
|
|
676
|
+
const state = args.checkOnly
|
|
677
|
+
? await call(`/sites/project/${projectId}/publish`)
|
|
678
|
+
: await publishSite(call, { projectId, ...wait });
|
|
679
|
+
const site = state?.status === 'done' ? (await call(`/sites/project/${projectId}`))?.site : null;
|
|
680
|
+
const out = lines(renderPublish(state, { projectId, site }));
|
|
681
|
+
return state?.status === 'failed' ? err(out.content[0].text) : out;
|
|
682
|
+
}
|
|
683
|
+
if (name === 'workover_set_site_indexing') {
|
|
684
|
+
if (typeof args.index !== 'boolean') return err('Pass `index`: true to let search engines index the site, false to ask them not to.');
|
|
685
|
+
const res = await setIndexing(call, { projectId, index: args.index });
|
|
686
|
+
return lines(renderIndexing(res));
|
|
687
|
+
}
|
|
688
|
+
if (name === 'workover_site_status') {
|
|
689
|
+
if (projectId === null) {
|
|
690
|
+
const res = await call('/project');
|
|
691
|
+
const list = (Array.isArray(res) ? res : res?.projects || []).filter((p) => p.hasSite);
|
|
692
|
+
return text(
|
|
693
|
+
list.length
|
|
694
|
+
? `Projects with a Help Center:\n${list.map((p) => `#${p.id}: ${p.name || p.title || 'Project'}`).join('\n')}`
|
|
695
|
+
: 'No project has a Help Center yet. workover_create_project makes one.',
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
const res = await siteStatus(call, { projectId });
|
|
699
|
+
return lines(renderSiteStatus(res, { projectId }));
|
|
700
|
+
}
|
|
701
|
+
} catch (e) {
|
|
702
|
+
const help = scopeHelp(e?.message);
|
|
703
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
704
|
+
}
|
|
705
|
+
return err(`Unknown tool: ${name}`);
|
|
706
|
+
}
|
|
707
|
+
|
|
437
708
|
return async function dispatch(name, args = {}) {
|
|
438
709
|
if (!auth)
|
|
439
710
|
return err(
|
|
@@ -600,7 +871,7 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
600
871
|
const rules = await fetchRules(api, d.projectId);
|
|
601
872
|
|
|
602
873
|
return text(
|
|
603
|
-
`# ${d.title || 'Untitled'} (id ${d.id})\n\n${body}${tabNote}${renderStyleGuide(rules)}`,
|
|
874
|
+
`# ${d.title || 'Untitled'} (id ${d.id})\n\n${formatLine(live?.format)}${body}${tabNote}${renderStyleGuide(rules)}`,
|
|
604
875
|
);
|
|
605
876
|
}
|
|
606
877
|
if (name === 'workover_list_projects') {
|
|
@@ -768,25 +1039,61 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
768
1039
|
}
|
|
769
1040
|
if (name === 'workover_edit_doc') {
|
|
770
1041
|
const md = String(args.markdown || '').trim();
|
|
771
|
-
|
|
1042
|
+
// A rename rides on the direct-edit tool: `title` alone renames without touching the body.
|
|
1043
|
+
const wantsRename = args.title != null;
|
|
1044
|
+
const title = wantsRename ? String(args.title).trim().replace(/\s+/g, ' ') : '';
|
|
1045
|
+
if (!md && !wantsRename)
|
|
1046
|
+
return err(
|
|
1047
|
+
'Provide the full revised document as `markdown`, a new name as `title`, or both.',
|
|
1048
|
+
);
|
|
1049
|
+
if (wantsRename && !title) return err('`title` cannot be empty. Omit it to keep the current name.');
|
|
1050
|
+
if (title.length > MAX_DOC_TITLE)
|
|
1051
|
+
return err(`\`title\` can be ${MAX_DOC_TITLE} characters at most (this one is ${title.length}).`);
|
|
772
1052
|
const doc = await resolveDoc(api, docArg(args), auth.api);
|
|
773
1053
|
if (doc.error) return doc.error;
|
|
774
1054
|
const docId = doc.id;
|
|
775
1055
|
const tabId = args.tabId == null ? null : rowId(args.tabId);
|
|
776
1056
|
if (args.tabId != null && tabId === null)
|
|
777
1057
|
return badIdErr('tab', args.tabId);
|
|
1058
|
+
if (!md) {
|
|
1059
|
+
// Title only: the body is not sent, so it cannot change.
|
|
1060
|
+
if (tabId != null)
|
|
1061
|
+
return err(
|
|
1062
|
+
'`title` renames the whole document, not a tab. Pass `title` without `tabId`, or pass `markdown` to write that tab.',
|
|
1063
|
+
);
|
|
1064
|
+
try {
|
|
1065
|
+
return text(renderRenameText(await renameDoc(api, docId, title)));
|
|
1066
|
+
} catch (e) {
|
|
1067
|
+
return err(renameRefusalText(e?.message));
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
778
1070
|
const res = await apiPost(`/project/doc/${docId}/content`, {
|
|
779
1071
|
markdown: md,
|
|
780
1072
|
note: args.note ? String(args.note) : undefined,
|
|
781
1073
|
source: 'Claude Code',
|
|
782
1074
|
...(tabId != null ? { tabId } : {}),
|
|
1075
|
+
// Removing a component, snippet, math or embed is refused unless the agent says it means
|
|
1076
|
+
// to (WO-1299). Only an explicit true counts.
|
|
1077
|
+
...(args.allowBlockRemoval === true ? { allowBlockRemoval: true } : {}),
|
|
783
1078
|
});
|
|
1079
|
+
const removed = Array.isArray(res?.removedBlocks) && res.removedBlocks.length
|
|
1080
|
+
? `\n\nRemoved as asked: ${res.removedBlocks.join(', ')}.`
|
|
1081
|
+
: '';
|
|
1082
|
+
// The body first, then the name: a body the server refuses leaves the name alone too.
|
|
1083
|
+
let renamed = '';
|
|
1084
|
+
if (wantsRename) {
|
|
1085
|
+
try {
|
|
1086
|
+
renamed = `\n\n${renderRenameText(await renameDoc(api, docId, title))}`;
|
|
1087
|
+
} catch (e) {
|
|
1088
|
+
renamed = `\n\nThe body was written, but the rename was not: ${renameRefusalText(e?.message)}`;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
784
1091
|
return text(
|
|
785
1092
|
`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
1093
|
res?.replacedCharacters
|
|
787
1094
|
? `\n\nReplaced ${res.replacedCharacters} characters of existing text.`
|
|
788
1095
|
: ''
|
|
789
|
-
}${renderStyleFeedback(res?.style)}`,
|
|
1096
|
+
}${removed}${renamed}${renderStyleFeedback(res?.style)}`,
|
|
790
1097
|
);
|
|
791
1098
|
}
|
|
792
1099
|
if (name === 'workover_propose_edit') {
|
|
@@ -812,9 +1119,123 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
812
1119
|
`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)}`,
|
|
813
1120
|
);
|
|
814
1121
|
}
|
|
1122
|
+
if (name === 'workover_doc_status') {
|
|
1123
|
+
// The document's WORKOVER status, read or set through the browser's rules (WO-1264). It
|
|
1124
|
+
// never publishes: the WordPress post is a separate thing, and the answer says so.
|
|
1125
|
+
const doc = await resolveDoc(api, docArg(args), auth.api);
|
|
1126
|
+
if (doc.error) return doc.error;
|
|
1127
|
+
const docId = doc.id;
|
|
1128
|
+
const wanted = typeof args.status === 'string' ? args.status.trim() : '';
|
|
1129
|
+
let res;
|
|
1130
|
+
try {
|
|
1131
|
+
res = wanted
|
|
1132
|
+
? await api(`/project/doc/${docId}/status`, {
|
|
1133
|
+
method: 'PATCH',
|
|
1134
|
+
headers: { 'content-type': 'application/json' },
|
|
1135
|
+
body: JSON.stringify({ status: wanted }),
|
|
1136
|
+
})
|
|
1137
|
+
: await api(`/project/doc/${docId}/status`);
|
|
1138
|
+
} catch (e) {
|
|
1139
|
+
return err(statusRefusalText(e?.message));
|
|
1140
|
+
}
|
|
1141
|
+
return text(wanted ? renderStatusChangeText(res) : renderStatusListText(res));
|
|
1142
|
+
}
|
|
1143
|
+
if (name === 'workover_report_feedback') {
|
|
1144
|
+
// The version and client are this server's to state, not the agent's: they come from the
|
|
1145
|
+
// MCP handshake, so a report says which release and which client it came from.
|
|
1146
|
+
const info = typeof clientInfo === 'function' ? clientInfo() : {};
|
|
1147
|
+
try {
|
|
1148
|
+
const res = await submitFeedback(call, args, { surface: 'mcp', ...info });
|
|
1149
|
+
return lines(renderFeedbackResult(res));
|
|
1150
|
+
} catch (e) {
|
|
1151
|
+
return err(e?.message || 'The report was not sent.');
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
if (SITE_TOOLS.has(name)) return await siteTool(name, args);
|
|
815
1155
|
return err(`Unknown tool: ${name}`);
|
|
816
1156
|
} catch (e) {
|
|
817
1157
|
return err(e?.message || 'Something went wrong.');
|
|
818
1158
|
}
|
|
819
1159
|
};
|
|
820
1160
|
}
|
|
1161
|
+
|
|
1162
|
+
/** The longest title a rename accepts; the API's `MAX_DOCUMENT_TITLE` (document-title.ts). */
|
|
1163
|
+
export const MAX_DOC_TITLE = 200;
|
|
1164
|
+
|
|
1165
|
+
/** `PATCH /project/doc/:docId/title`: the editor's rename, by document id. Never sends a body. */
|
|
1166
|
+
const renameDoc = (api, docId, title) =>
|
|
1167
|
+
api(`/project/doc/${docId}/title`, {
|
|
1168
|
+
method: 'PATCH',
|
|
1169
|
+
headers: { 'content-type': 'application/json' },
|
|
1170
|
+
body: JSON.stringify({ title }),
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
/** What a rename did, in one sentence. */
|
|
1174
|
+
export const renderRenameText = (r) =>
|
|
1175
|
+
r?.changed === false
|
|
1176
|
+
? `Document #${r.documentId} is already called "${r.title}". Nothing changed.`
|
|
1177
|
+
: `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}` : ''}`;
|
|
1178
|
+
|
|
1179
|
+
/** A refused rename: the API's reason, or a plain note when the server predates the route. */
|
|
1180
|
+
export const renameRefusalText = (message) => {
|
|
1181
|
+
const m = String(message || 'Workover refused the rename.');
|
|
1182
|
+
if (/login expired|Not signed in/i.test(m)) return m;
|
|
1183
|
+
if (/\(404\): Cannot PATCH /.test(m))
|
|
1184
|
+
return 'This Workover server cannot rename documents from here yet. It arrives with the next release; until then, rename it in the editor.';
|
|
1185
|
+
return `Refused: ${m.replace(/^Workover API error \((\d+)\):\s*/, '')}`;
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
/** The WordPress side of a status answer: separate from the Workover status, and said so. */
|
|
1189
|
+
const wordpressNote = (r) =>
|
|
1190
|
+
r?.wordpress
|
|
1191
|
+
? `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.`
|
|
1192
|
+
: 'This document is not linked to a WordPress post.';
|
|
1193
|
+
|
|
1194
|
+
/** `workover_doc_status` with no status: the current status and every status, allowed or why not. */
|
|
1195
|
+
export const renderStatusListText = (r) => {
|
|
1196
|
+
const lines = [
|
|
1197
|
+
`Document #${r.documentId} "${r.title || 'Untitled'}" is ${r.statusLabel} (${r.status}), in the ${r.workflow} workflow.`,
|
|
1198
|
+
];
|
|
1199
|
+
if (r.pendingApproval)
|
|
1200
|
+
lines.push(`It is waiting on approval for "${r.pendingApproval.statusKey}" (request #${r.pendingApproval.id}).`);
|
|
1201
|
+
lines.push(wordpressNote(r), '', 'Statuses (key: label, then whether you may move it there):');
|
|
1202
|
+
for (const s of r.statuses) {
|
|
1203
|
+
const note =
|
|
1204
|
+
s.key === r.status
|
|
1205
|
+
? 'current'
|
|
1206
|
+
: s.allowed
|
|
1207
|
+
? s.needsApproval
|
|
1208
|
+
? 'allowed; entering it opens an approval request'
|
|
1209
|
+
: 'allowed'
|
|
1210
|
+
: `not allowed: ${s.reason || 'no reason given'}`;
|
|
1211
|
+
lines.push(` ${s.key}: ${s.label} (${note})`);
|
|
1212
|
+
}
|
|
1213
|
+
lines.push('', 'Pass `status` with one of the keys to set it.');
|
|
1214
|
+
return lines.join('\n');
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1217
|
+
/** `workover_doc_status` with a status: moved, moved and waiting on approval, or already there. */
|
|
1218
|
+
export const renderStatusChangeText = (r) => {
|
|
1219
|
+
const label = (key) => r.statuses?.find((s) => s.key === key)?.label || key;
|
|
1220
|
+
const lines = [];
|
|
1221
|
+
if (!r.changed) lines.push(`Document #${r.documentId} was already ${label(r.status)} (${r.status}). Nothing changed.`);
|
|
1222
|
+
else {
|
|
1223
|
+
lines.push(`Changed: document #${r.documentId} moved from ${label(r.previous)} to ${label(r.status)}.`);
|
|
1224
|
+
if (r.pendingApproval && r.pendingApproval.statusKey === r.status)
|
|
1225
|
+
lines.push(
|
|
1226
|
+
`It is now waiting on approval (request #${r.pendingApproval.id}); the approvers have been asked, and it moves on once they approve.`,
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
lines.push(wordpressNote(r));
|
|
1230
|
+
return lines.join('\n');
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
/** A refused status change: "Refused: <the API's reason>", or the sign-in message as it is. */
|
|
1234
|
+
export const statusRefusalText = (message) => {
|
|
1235
|
+
const m = String(message || 'Workover refused the change.');
|
|
1236
|
+
if (/login expired|Not signed in/i.test(m)) return m;
|
|
1237
|
+
// Nest's own 404 for a route it does not have: a server older than this tool (WO-1264).
|
|
1238
|
+
if (/\(404\): Cannot (GET|PATCH) /.test(m))
|
|
1239
|
+
return 'This Workover server does not support workover_doc_status yet. It arrives with the next release.';
|
|
1240
|
+
return `Refused: ${m.replace(/^Workover API error \((\d+)\):\s*/, '')}`;
|
|
1241
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workover/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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.
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.32.2"
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"test": "node --test"
|