@workover/mcp 0.9.0 → 0.10.1

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 (4) hide show
  1. package/README.md +14 -4
  2. package/index.mjs +40 -36
  3. package/lib.mjs +221 -34
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -11,22 +11,30 @@ npm i -g @workover/cli
11
11
  workover login
12
12
  ```
13
13
 
14
- Then add the server to Claude Code:
14
+ Then add the server to Claude Code, for every project (`--scope user`; without it the server is
15
+ only available in the directory you ran the command in):
15
16
 
16
17
  ```sh
17
- claude mcp add workover -- npx -y @workover/mcp
18
+ claude mcp add --scope user workover -- npx -y @workover/mcp@latest
19
+ workover install-claude # optional: a skill that points Claude Code at Workover links
18
20
  ```
19
21
 
20
22
  That's it. Ask Claude Code things like *"read my Workover doc about onboarding and tighten the intro"* — it reads the document and its proposed changes appear in Workover as tracked-change **suggestions** you accept or reject.
21
23
 
22
24
  ## Tools
23
25
 
26
+ **Every tool that takes a `docId` takes the document's link.** Pass the URL the person pasted
27
+ (`https://workover.io/app/<workspace>/docs/<id>`, anything after it is ignored), the UUID at the end
28
+ of it, or the numeric id. `url` and `doc` are accepted as names for it too. A link the signed-in
29
+ account cannot open comes back as "not found, or no access"; a `workover.dev` link used with a
30
+ production sign-in names the environment instead.
31
+
24
32
  - `workover_search_docs(query)` — find documents by title/content
25
33
  - `workover_read_doc(docId, tabId?)` — read a document's text, with the style guide attached
26
34
  - `workover_list_projects()` — list your projects
27
35
  - `workover_create_doc(projectId, title, markdown, categories?)` — create a document with its content written in, filed under the categories you name (a category that does not exist yet is created)
28
36
  - `workover_upload_image(docId, path, alt)` — put a local image into a document's media
29
- - `workover_list_images(docId, tabId?)` — the images in a document: file name, alt text and src. `docId` can be the document URL
37
+ - `workover_list_images(docId, tabId?)` — the images in a document: file name, alt text and src
30
38
  - `workover_set_image(docId, src, filename?, alt?)` — set an image's file name (its WordPress media name) and/or alt text, as the editor's Edit image dialog does. Needs `workover login --write`
31
39
  - `workover_propose_edit(docId, markdown, note, tabId?, reasoning?)` — propose a revised version (rendered as suggestions; never applied or published automatically)
32
40
  - `workover_edit_doc(docId, markdown, note, tabId?)` — edit a document directly, no review step. Needs `workover login --write`
@@ -97,7 +105,9 @@ made by an agent is never indistinguishable from one you typed.
97
105
 
98
106
  ## Configuration
99
107
 
100
- The API endpoint comes from your `workover login` (defaults to `https://api.workover.io`).
108
+ The API endpoint comes from your `workover login` (defaults to `https://api.workover.io`). The
109
+ sign-in is read on every call, so `workover login` takes effect without restarting the client.
110
+ `WORKOVER_CONFIG` names a different sign-in file, as in the CLI.
101
111
 
102
112
  ## Usage data
103
113
 
package/index.mjs CHANGED
@@ -19,24 +19,44 @@ import {
19
19
  telemetryEnabled,
20
20
  } from './telemetry.mjs';
21
21
 
22
+ // The CLI's sign-in file. WORKOVER_CONFIG names another one (a second environment), as in the CLI.
23
+ const CONFIG_FILE = process.env.WORKOVER_CONFIG || join(homedir(), '.workover', 'config.json');
24
+
22
25
  function loadAuth() {
23
26
  try {
24
- const cfg = JSON.parse(readFileSync(join(homedir(), '.workover', 'config.json'), 'utf8'));
27
+ const cfg = JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));
25
28
  return validAuth(cfg);
26
29
  } catch {
27
30
  return null; // not signed in
28
31
  }
29
32
  }
30
33
 
34
+ /**
35
+ * The sign-in is read per call, not once at start-up.
36
+ *
37
+ * Read once, a server started before `workover login` stayed signed out until Claude Code was
38
+ * restarted, so "run workover login" was advice that did not work in the session that got it. The
39
+ * file is a few hundred bytes; reading it per tool call costs nothing next to the request itself.
40
+ */
31
41
  const auth = loadAuth();
32
- const { api, apiPost } = makeApi({ auth: auth ?? { api: '', token: '' } });
33
- const dispatch = makeDispatch({ auth, api, apiPost, readFile: readFileSync });
42
+ const dispatch = (name, args) => {
43
+ const current = loadAuth();
44
+ const { api, apiPost } = makeApi({ auth: current ?? { api: '', token: '' } });
45
+ return makeDispatch({ auth: current, api, apiPost, readFile: readFileSync })(name, args);
46
+ };
47
+
48
+ /** The schema for a document argument. Every tool that names a document takes all three forms. */
49
+ const DOC_ARG = {
50
+ type: ['string', 'number'],
51
+ description:
52
+ 'The document: its link exactly as the person gave it (https://workover.io/app/<workspace>/docs/<id>, or workover.dev for staging), the UUID at the end of that link, or the numeric id ("#12345" → 12345).',
53
+ };
34
54
 
35
55
  const TOOLS = [
36
56
  {
37
57
  name: 'workover_search_docs',
38
58
  description:
39
- 'Search your Workover documents by title and content. Returns matching documents with their ids — use workover_read_doc to read one.',
59
+ 'Search your Workover documents by title and content. Returns matching documents with their ids — use workover_read_doc to read one. Not needed when you already have a document link: pass that to workover_read_doc.',
40
60
  inputSchema: {
41
61
  type: 'object',
42
62
  properties: { query: { type: 'string', description: 'What to search for.' } },
@@ -46,15 +66,11 @@ const TOOLS = [
46
66
  {
47
67
  name: 'workover_read_doc',
48
68
  description:
49
- "Read the full text of a Workover document by its id. The result also carries the workspace's style guide and, for a document with tabs, says which tab you are reading and what the others are.",
69
+ "Read the full text of a Workover document. Pass the document link the person pasted (workover.io/app/<workspace>/docs/<id>) as docId, as it is; a UUID or numeric id works too. The result also carries the workspace's style guide and, for a document with tabs, says which tab you are reading and what the others are.",
50
70
  inputSchema: {
51
71
  type: 'object',
52
72
  properties: {
53
- docId: {
54
- type: 'number',
55
- description:
56
- 'The numeric document id, as printed by workover_search_docs ("#12345" → 12345). Not the handle from a document URL.',
57
- },
73
+ docId: DOC_ARG,
58
74
  tabId: {
59
75
  type: 'number',
60
76
  description:
@@ -112,7 +128,7 @@ const TOOLS = [
112
128
  inputSchema: {
113
129
  type: 'object',
114
130
  properties: {
115
- docId: { type: 'number', description: 'The numeric document id.' },
131
+ docId: DOC_ARG,
116
132
  },
117
133
  required: ['docId'],
118
134
  },
@@ -124,7 +140,7 @@ const TOOLS = [
124
140
  inputSchema: {
125
141
  type: 'object',
126
142
  properties: {
127
- docId: { type: 'number', description: 'The numeric document id.' },
143
+ docId: DOC_ARG,
128
144
  title: { type: 'string', description: 'The tab title.' },
129
145
  parentId: {
130
146
  type: 'number',
@@ -171,11 +187,8 @@ const TOOLS = [
171
187
  inputSchema: {
172
188
  type: 'object',
173
189
  properties: {
174
- docId: {
175
- type: 'number',
176
- description: 'The numeric id of the document the image belongs to (not a URL handle).',
177
- },
178
- path: { type: 'string', description: 'Local file path to the image (png/jpg/webp).' },
190
+ docId: DOC_ARG,
191
+ path: { type: 'string', description: 'Local file path to the image (png/jpg/gif/webp, up to 5 MB).' },
179
192
  alt: { type: 'string', description: 'Alt text describing the image.' },
180
193
  },
181
194
  required: ['docId', 'path'],
@@ -188,10 +201,7 @@ const TOOLS = [
188
201
  inputSchema: {
189
202
  type: 'object',
190
203
  properties: {
191
- docId: {
192
- type: ['number', 'string'],
193
- description: 'The numeric document id, or the document URL.',
194
- },
204
+ docId: DOC_ARG,
195
205
  tabId: {
196
206
  type: 'number',
197
207
  description:
@@ -208,10 +218,7 @@ const TOOLS = [
208
218
  inputSchema: {
209
219
  type: 'object',
210
220
  properties: {
211
- docId: {
212
- type: ['number', 'string'],
213
- description: 'The numeric document id, or the document URL.',
214
- },
221
+ docId: DOC_ARG,
215
222
  src: {
216
223
  type: 'string',
217
224
  description: 'The image src, exactly as workover_list_images printed it.',
@@ -236,10 +243,7 @@ const TOOLS = [
236
243
  inputSchema: {
237
244
  type: 'object',
238
245
  properties: {
239
- docId: {
240
- type: 'number',
241
- description: 'The numeric id of the document to edit (not a URL handle).',
242
- },
246
+ docId: DOC_ARG,
243
247
  markdown: {
244
248
  type: 'string',
245
249
  description:
@@ -265,11 +269,7 @@ const TOOLS = [
265
269
  inputSchema: {
266
270
  type: 'object',
267
271
  properties: {
268
- docId: {
269
- type: 'number',
270
- description:
271
- 'The numeric id of the document to propose changes to (not a URL handle).',
272
- },
272
+ docId: DOC_ARG,
273
273
  markdown: {
274
274
  type: 'string',
275
275
  description: 'The complete revised document as markdown (not just the changed parts).',
@@ -298,7 +298,7 @@ const telemetry = telemetryEnabled(process.env, { auth });
298
298
  // Keep in step with package.json. It is what every telemetry event is stamped with, so a stale
299
299
  // value here does not break anything — it quietly attributes this release's behaviour to an older
300
300
  // one, which is worse, because the numbers still look fine.
301
- const VERSION = '0.9.0';
301
+ const VERSION = '0.10.1';
302
302
 
303
303
  /**
304
304
  * What the client is told about this server before it calls anything.
@@ -318,6 +318,10 @@ const VERSION = '0.9.0';
318
318
  */
319
319
  const INSTRUCTIONS = `Workover holds this team's documents and their STYLE GUIDE.
320
320
 
321
+ A Workover document link (https://workover.io/app/<workspace>/docs/<id>) is a document reference:
322
+ pass it as docId to any tool here, unchanged. Never call the Workover API yourself or read the
323
+ token file.
324
+
321
325
  Before writing or revising anything here, call workover_style_guide for the project you are
322
326
  writing for, and follow every rule it returns. Those rules are the team's house style — spelling
323
327
  variant, punctuation, banned words, tone — and writing that ignores them has to be corrected by
@@ -383,7 +387,7 @@ function report(tool, startedAt, ok, errorKind) {
383
387
  }),
384
388
  // The API attributes the event to whoever this token belongs to. Nothing here nominates an
385
389
  // identity, because a client that could would be a client that could claim somebody else's.
386
- { auth },
390
+ { auth: loadAuth() },
387
391
  );
388
392
  }
389
393
 
package/lib.mjs CHANGED
@@ -1,6 +1,8 @@
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 { realpathSync, statSync } from 'fs';
5
+ import { basename } from 'path';
4
6
 
5
7
  /** Flatten HTML to readable plain text: drop tags + named entities, collapse whitespace. */
6
8
  export const stripHtml = (h) =>
@@ -129,23 +131,150 @@ export const renderStyleFeedback = (style) => {
129
131
  return `\n\n${style.summary}`;
130
132
  };
131
133
 
132
- const HANDLE_RE = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
134
+ const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
135
+ const FULL_UUID_RE = new RegExp(`^${UUID_RE.source}$`, 'i');
133
136
 
134
137
  /**
135
- * A document's row id from a row id OR a document URL / handle, resolved through the api.
138
+ * Which document somebody meant, from whatever they pasted.
136
139
  *
137
- * The image tools take the link as it is, because the person asking for alt text pastes the URL of
138
- * the document they are looking at. Returns null when neither is there.
140
+ * 1234 / #1234 → { id: 1234 }
141
+ * https://workover.io/app/pellio/docs/<uuid> → { handle, host, workspace }
142
+ * …/docs/<uuid>/anything?tab=3#heading, workover.dev, → the same, with that host
143
+ * a preview host, or no scheme at all
144
+ * https://workover.io/app/projects/1234 → { id: 1234, host } (the old editor URL)
145
+ * <uuid> on its own → { handle }
146
+ *
147
+ * Returns null for anything else. The URL is what people paste because it is what the browser shows
148
+ * them, and on 2026-10-16 an agent handed one went digging through the source to turn it into a row
149
+ * id. Every command that names a document takes all of these, so nobody has to.
150
+ *
151
+ * `host` is kept so a link to one environment opened with a sign-in for another can be named as
152
+ * that, rather than reported as a missing document (see `environmentMismatch`).
139
153
  */
140
- export const resolveDocId = async (api, value) => {
141
- const id = rowId(value);
142
- if (id !== null) return id;
143
- const m = HANDLE_RE.exec(String(value ?? ''));
144
- if (!m) return null;
145
- const doc = await api(`/project/doc/by-handle/${encodeURIComponent(m[1].toLowerCase())}`);
146
- return doc?.id ?? null;
154
+ export const docRef = (value) => {
155
+ // Trim the wrapping that pasted links arrive in: <angle brackets>, quotes, a trailing full stop.
156
+ const s = String(value ?? '')
157
+ .trim()
158
+ .replace(/^[<"'([]+/, '')
159
+ .replace(/[>"')\].,;]+$/, '');
160
+ if (!s) return null;
161
+ const id = rowId(s);
162
+ if (id !== null) return { id };
163
+ if (FULL_UUID_RE.test(s)) return { handle: s.toLowerCase() };
164
+
165
+ const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(s);
166
+ if (hasScheme || /^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?\//i.test(s)) {
167
+ let url;
168
+ try {
169
+ url = new URL(hasScheme ? s : `https://${s}`);
170
+ } catch {
171
+ return null;
172
+ }
173
+ const host = url.hostname.toLowerCase();
174
+ const segs = url.pathname.split('/').filter(Boolean);
175
+ const at = segs.findIndex((seg) => FULL_UUID_RE.test(seg));
176
+ if (at !== -1) {
177
+ // /app/<workspace>/docs/<uuid>: the canonical document URL.
178
+ const workspace =
179
+ segs[0] === 'app' && segs[2] === 'docs' && at === 3 ? decodeURIComponent(segs[1]) : null;
180
+ return { handle: segs[at].toLowerCase(), host, ...(workspace ? { workspace } : {}) };
181
+ }
182
+ // /app/projects/<id>: the numeric editor route, kept for old links and bookmarks.
183
+ if (segs[0] === 'app' && segs[1] === 'projects' && rowId(segs[2] ?? '') !== null) {
184
+ return { id: rowId(segs[2]), host };
185
+ }
186
+ return null;
187
+ }
188
+
189
+ // Free text with a handle in it ("the doc 7cd7…"): take the handle.
190
+ const m = UUID_RE.exec(s);
191
+ return m ? { handle: m[0].toLowerCase() } : null;
147
192
  };
148
193
 
194
+ /** The web host each known API serves, for telling a user which environment a link belongs to. */
195
+ const WEB_FOR_API = {
196
+ 'api.workover.io': 'workover.io',
197
+ 'api.workover.dev': 'workover.dev',
198
+ 'api.workover.test': 'workover.test',
199
+ };
200
+
201
+ /**
202
+ * A sentence when a document link is for a different Workover than the one signed in to, else null.
203
+ *
204
+ * Only for hosts we know. A preview deploy's web and api hosts are not related by name, so they are
205
+ * left alone rather than guessed at — a wrong warning here would send someone to sign in somewhere
206
+ * they did not need to.
207
+ */
208
+ export const environmentMismatch = (ref, api) => {
209
+ if (!ref?.host || !api) return null;
210
+ let apiHost;
211
+ try {
212
+ apiHost = new URL(String(api)).hostname.toLowerCase();
213
+ } catch {
214
+ return null;
215
+ }
216
+ const signedInWeb = WEB_FOR_API[apiHost];
217
+ const linkHost = ref.host.replace(/^www\./, '');
218
+ const linkApi = Object.keys(WEB_FOR_API).find((k) => WEB_FOR_API[k] === linkHost);
219
+ if (!signedInWeb || !linkApi || signedInWeb === linkHost) return null;
220
+ return (
221
+ `That link is to ${linkHost}, but you are signed in to ${apiHost}. ` +
222
+ `Sign in there first (it replaces your current sign-in): WORKOVER_API=https://${linkApi} workover login`
223
+ );
224
+ };
225
+
226
+ /** The document argument a tool was given. `docId` is the schema's name; `url` / `doc` are what a
227
+ * model sometimes sends instead when it is holding a link, and refusing those would be pedantry. */
228
+ export const docArg = (args = {}) => args.docId ?? args.url ?? args.doc ?? args.link;
229
+
230
+ /** The message for a document argument that names no document at all. */
231
+ export const notADocErr = (got) =>
232
+ err(
233
+ `"${got ?? ''}" isn't a document id or a document URL. Pass the document link as the person gave it (https://workover.io/app/<workspace>/docs/<id>), the UUID at the end of it, or the numeric id.`,
234
+ );
235
+
236
+ /**
237
+ * A document's row id from a link, a UUID or a row id: `{ id }`, or `{ error }` (an MCP error
238
+ * result) saying what to do next.
239
+ *
240
+ * A link or UUID is resolved through `GET /project/doc/by-handle/<uuid>`, which applies the same
241
+ * access rules as reading the document by id. The failures are spelled out because an agent told
242
+ * only "error" goes looking for another way in, and on 2026-10-16 that meant reading the token file
243
+ * and grepping the Workover source for routes.
244
+ */
245
+ export const resolveDoc = async (api, value, apiBase) => {
246
+ const ref = docRef(value);
247
+ if (!ref) return { error: notADocErr(value) };
248
+ const mismatch = environmentMismatch(ref, apiBase);
249
+ if (mismatch) return { error: err(mismatch) };
250
+ if (ref.id) return { id: ref.id };
251
+ try {
252
+ const doc = await api(`/project/doc/by-handle/${encodeURIComponent(ref.handle)}`);
253
+ if (doc?.id) return { id: doc.id };
254
+ } catch (e) {
255
+ const message = String(e?.message || '');
256
+ if (/expired or was revoked/.test(message)) return { error: err(message) };
257
+ if (/\(410\)/.test(message))
258
+ return { error: err('That document is in the Trash. Ask the person to restore it in Workover.') };
259
+ if (e instanceof TypeError)
260
+ return { error: err(`Couldn't reach Workover${apiBase ? ` at ${apiBase}` : ''}.`) };
261
+ }
262
+ let where = '';
263
+ try {
264
+ where = apiBase ? ` (signed in to ${new URL(apiBase).host})` : '';
265
+ } catch {
266
+ where = '';
267
+ }
268
+ return {
269
+ error: err(
270
+ `No Workover document at that link that this sign-in can open${where}. Either it does not exist or this account has no access to it. Ask the person to check the link or share the document with them; do not look for another route.`,
271
+ ),
272
+ };
273
+ };
274
+
275
+ /** Kept for callers of the earlier helper: the row id, or null. */
276
+ export const resolveDocId = async (api, value) => (await resolveDoc(api, value)).id ?? null;
277
+
149
278
  const decodeAttr = (v) =>
150
279
  String(v ?? '')
151
280
  .replace(/&quot;/g, '"')
@@ -205,9 +334,55 @@ export const mimeForExt = (ext) => {
205
334
  const e = String(ext || '').toLowerCase();
206
335
  if (e === 'jpg' || e === 'jpeg') return 'image/jpeg';
207
336
  if (e === 'webp') return 'image/webp';
337
+ if (e === 'gif') return 'image/gif';
208
338
  return 'image/png';
209
339
  };
210
340
 
341
+ /** The extensions the API's media upload accepts (apps/api/src/utils/image-type.ts). */
342
+ export const UPLOAD_IMAGE_EXT = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
343
+ /** The API's multer cap (apps/api/src/config/multer-memory.config.ts); checked before reading. */
344
+ export const UPLOAD_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
345
+
346
+ /**
347
+ * Decide whether `workover_upload_image` may read a local path. The tool is driven by a model, and a
348
+ * model can be talked (by a document it just read, say) into "uploading" ~/.ssh/id_ed25519 or
349
+ * ~/.workover/config.json into a document anyone on the team can open. So: resolve symlinks first
350
+ * (a `shot.png` that links to a key is judged by what it points at), refuse anything inside a dot
351
+ * file or dot directory, accept only the image extensions the API takes, and check the size before
352
+ * reading a byte. Returns `{ path, ext }` (the real path) or `{ error }`.
353
+ */
354
+ export const vetImagePath = (p, { realpath = realpathSync, stat = statSync } = {}) => {
355
+ let real;
356
+ try {
357
+ real = realpath(p);
358
+ } catch {
359
+ return { error: `Couldn't read an image at ${p}.` };
360
+ }
361
+ if (real.split(/[\\/]/).some((part) => part.startsWith('.') && part !== '.' && part !== '..'))
362
+ return {
363
+ error: `Refusing to upload ${p}: it is a hidden file or inside a hidden directory. Save the image somewhere ordinary (e.g. the Desktop) and pass that path.`,
364
+ };
365
+ const name = basename(real);
366
+ const dot = name.lastIndexOf('.');
367
+ const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
368
+ if (!UPLOAD_IMAGE_EXT.includes(ext))
369
+ return {
370
+ error: `Refusing to upload ${p}: only ${UPLOAD_IMAGE_EXT.join(', ')} images can be uploaded.`,
371
+ };
372
+ let info;
373
+ try {
374
+ info = stat(real);
375
+ } catch {
376
+ return { error: `Couldn't read an image at ${p}.` };
377
+ }
378
+ if (!info.isFile()) return { error: `${p} is not a file.` };
379
+ if (info.size > UPLOAD_IMAGE_MAX_BYTES)
380
+ return {
381
+ error: `${p} is ${Math.ceil(info.size / 1024 / 1024)} MB; Workover takes images up to ${UPLOAD_IMAGE_MAX_BYTES / 1024 / 1024} MB.`,
382
+ };
383
+ return { path: real, ext };
384
+ };
385
+
211
386
  /**
212
387
  * Build the authenticated JSON API caller. `fetchImpl` is injectable for tests. The status→message
213
388
  * mapping is the contract the tools rely on (401/403 are friendly, other non-2xx is generic).
@@ -258,10 +433,12 @@ export function makeApi({ auth, fetchImpl = fetch }) {
258
433
  * short-circuits before any request; unknown tools and thrown errors become `err(...)`. `readFile`
259
434
  * and `fetchImpl` are injected so the upload path is testable without touching the disk/network.
260
435
  */
261
- export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }) {
436
+ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps }) {
262
437
  return async function dispatch(name, args = {}) {
263
438
  if (!auth)
264
- return err('Not signed in to Workover. Run `workover login` in your terminal first.');
439
+ return err(
440
+ 'Not signed in to Workover. Ask the person to run `workover login` in a terminal (or `npx -y @workover/cli@latest login`): it opens a browser for them to approve, and `--write` also allows direct edits. The next call here picks the sign-in up; no restart needed. Do not look for a token yourself.',
441
+ );
265
442
  try {
266
443
  if (name === 'workover_search_docs') {
267
444
  const { results = [] } = await api(
@@ -327,8 +504,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
327
504
  );
328
505
  }
329
506
  if (name === 'workover_list_tabs') {
330
- const docId = rowId(args.docId);
331
- if (docId === null) return badIdErr('document', args.docId);
507
+ const doc = await resolveDoc(api, docArg(args), auth.api);
508
+ if (doc.error) return doc.error;
509
+ const docId = doc.id;
332
510
  const tabs = await api(`/project/doc/${docId}/tabs`);
333
511
  if (!Array.isArray(tabs) || !tabs.length)
334
512
  return text(
@@ -345,8 +523,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
345
523
  );
346
524
  }
347
525
  if (name === 'workover_create_tab') {
348
- const docId = rowId(args.docId);
349
- if (docId === null) return badIdErr('document', args.docId);
526
+ const doc = await resolveDoc(api, docArg(args), auth.api);
527
+ if (doc.error) return doc.error;
528
+ const docId = doc.id;
350
529
  const title = String(args.title || '').trim();
351
530
  if (!title) return err('Provide a `title` for the new tab.');
352
531
  const parentId = args.parentId == null ? null : rowId(args.parentId);
@@ -361,8 +540,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
361
540
  );
362
541
  }
363
542
  if (name === 'workover_read_doc') {
364
- const docId = rowId(args.docId);
365
- if (docId === null) return badIdErr('document', args.docId);
543
+ const doc = await resolveDoc(api, docArg(args), auth.api);
544
+ if (doc.error) return doc.error;
545
+ const docId = doc.id;
366
546
  const tabId = args.tabId == null ? null : rowId(args.tabId);
367
547
  if (args.tabId != null && tabId === null)
368
548
  return badIdErr('tab', args.tabId);
@@ -493,18 +673,23 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
493
673
  if (name === 'workover_upload_image') {
494
674
  const p = String(args.path || '');
495
675
  if (!p) return err('Provide the local `path` to the image file.');
496
- const docId = rowId(args.docId);
497
- if (docId === null) return badIdErr('document', args.docId);
676
+ const doc = await resolveDoc(api, docArg(args), auth.api);
677
+ if (doc.error) return doc.error;
678
+ const docId = doc.id;
679
+ const vetted = vetImagePath(p, fsOps);
680
+ if (vetted.error) return err(vetted.error);
681
+ const { ext } = vetted;
498
682
  let buf;
499
683
  try {
500
- buf = readFile(p);
684
+ buf = readFile(vetted.path);
501
685
  } catch {
502
686
  return err(`Couldn't read an image at ${p}.`);
503
687
  }
504
- const ext = (p.split('.').pop() || 'png').toLowerCase();
688
+ if (buf.length > UPLOAD_IMAGE_MAX_BYTES)
689
+ return err(`${p} is larger than ${UPLOAD_IMAGE_MAX_BYTES / 1024 / 1024} MB.`);
505
690
  const mime = mimeForExt(ext);
506
691
  const form = new FormData();
507
- form.append('file', new Blob([buf], { type: mime }), p.split('/').pop() || `image.${ext}`);
692
+ form.append('file', new Blob([buf], { type: mime }), basename(vetted.path));
508
693
  if (args.alt) form.append('alt', String(args.alt));
509
694
  const res = await fetchImpl(`${auth.api}/project/doc/${docId}/media`, {
510
695
  method: 'POST',
@@ -518,9 +703,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
518
703
  );
519
704
  }
520
705
  if (name === 'workover_list_images') {
521
- const docId = await resolveDocId(api, args.docId);
522
- if (docId === null)
523
- return err(`"${args.docId ?? ''}" isn't a document id or a document URL.`);
706
+ const doc = await resolveDoc(api, docArg(args), auth.api);
707
+ if (doc.error) return doc.error;
708
+ const docId = doc.id;
524
709
  const tabId = args.tabId == null ? null : rowId(args.tabId);
525
710
  if (args.tabId != null && tabId === null) return badIdErr('tab', args.tabId);
526
711
  const live = await api(
@@ -552,9 +737,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
552
737
  );
553
738
  }
554
739
  if (name === 'workover_set_image') {
555
- const docId = await resolveDocId(api, args.docId);
556
- if (docId === null)
557
- return err(`"${args.docId ?? ''}" isn't a document id or a document URL.`);
740
+ const doc = await resolveDoc(api, docArg(args), auth.api);
741
+ if (doc.error) return doc.error;
742
+ const docId = doc.id;
558
743
  const src = String(args.src || '');
559
744
  if (!src) return err('Provide the image `src`, exactly as workover_list_images printed it.');
560
745
  const filename = typeof args.filename === 'string' ? args.filename : undefined;
@@ -584,8 +769,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
584
769
  if (name === 'workover_edit_doc') {
585
770
  const md = String(args.markdown || '').trim();
586
771
  if (!md) return err('Provide the full revised document as `markdown`.');
587
- const docId = rowId(args.docId);
588
- if (docId === null) return badIdErr('document', args.docId);
772
+ const doc = await resolveDoc(api, docArg(args), auth.api);
773
+ if (doc.error) return doc.error;
774
+ const docId = doc.id;
589
775
  const tabId = args.tabId == null ? null : rowId(args.tabId);
590
776
  if (args.tabId != null && tabId === null)
591
777
  return badIdErr('tab', args.tabId);
@@ -606,8 +792,9 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
606
792
  if (name === 'workover_propose_edit') {
607
793
  const md = String(args.markdown || '').trim();
608
794
  if (!md) return err('Provide the full revised document as `markdown`.');
609
- const docId = rowId(args.docId);
610
- if (docId === null) return badIdErr('document', args.docId);
795
+ const doc = await resolveDoc(api, docArg(args), auth.api);
796
+ if (doc.error) return doc.error;
797
+ const docId = doc.id;
611
798
  const tabId = args.tabId == null ? null : rowId(args.tabId);
612
799
  if (args.tabId != null && tabId === null)
613
800
  return badIdErr('tab', args.tabId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/mcp",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
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",