@workover/mcp 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/index.mjs +52 -68
  2. package/package.json +4 -1
package/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  // Workover MCP server (Phase 2 — read tools). Lets Claude Code / any MCP client read the signed-in
3
3
  // user's Workover documents. Auth = the token stored by `workover login` (~/.workover/config.json).
4
4
  // Read-only for now; propose-edits (as suggestions) lands in Phase 3. Never publishes to WordPress.
5
+ // The api caller + tool dispatch live in lib.mjs (injectable for tests); this file just wires reality.
5
6
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
7
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
8
  import {
@@ -11,36 +12,20 @@ import {
11
12
  import { readFileSync } from 'fs';
12
13
  import { homedir } from 'os';
13
14
  import { join } from 'path';
15
+ import { makeApi, makeDispatch, validAuth } from './lib.mjs';
14
16
 
15
17
  function loadAuth() {
16
18
  try {
17
19
  const cfg = JSON.parse(readFileSync(join(homedir(), '.workover', 'config.json'), 'utf8'));
18
- if (cfg?.token && cfg?.api) return cfg;
20
+ return validAuth(cfg);
19
21
  } catch {
20
- /* not signed in */
22
+ return null; // not signed in
21
23
  }
22
- return null;
23
24
  }
24
25
 
25
26
  const auth = loadAuth();
26
-
27
- async function api(path, init) {
28
- const res = await fetch(`${auth.api}${path}`, {
29
- ...init,
30
- headers: { authorization: `Bearer ${auth.token}`, ...(init?.headers || {}) },
31
- });
32
- if (res.status === 401) throw new Error('Your Workover login expired or was revoked. Run `workover login`.');
33
- if (res.status === 403) throw new Error('This token isn’t allowed to do that.');
34
- if (!res.ok) throw new Error(`Workover API error (${res.status}).`);
35
- return res.json();
36
- }
37
- const apiPost = (path, body) =>
38
- api(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
39
-
40
- const stripHtml = (h) =>
41
- (h || '').replace(/<[^>]+>/g, ' ').replace(/&[a-z]+;/g, ' ').replace(/\s+/g, ' ').trim();
42
- const text = (t) => ({ content: [{ type: 'text', text: t }] });
43
- const err = (t) => ({ content: [{ type: 'text', text: t }], isError: true });
27
+ const { api, apiPost } = makeApi({ auth: auth ?? { api: '', token: '' } });
28
+ const dispatch = makeDispatch({ auth, api, apiPost, readFile: readFileSync });
44
29
 
45
30
  const TOOLS = [
46
31
  {
@@ -58,7 +43,11 @@ const TOOLS = [
58
43
  description: 'Read the full text of a Workover document by its id.',
59
44
  inputSchema: {
60
45
  type: 'object',
61
- properties: { docId: { type: 'number', description: 'The document id.' } },
46
+ properties: { docId: {
47
+ type: 'number',
48
+ description:
49
+ 'The numeric document id, as printed by workover_search_docs ("#12345" → 12345). Not the handle from a document URL.',
50
+ } },
62
51
  required: ['docId'],
63
52
  },
64
53
  },
@@ -67,6 +56,41 @@ const TOOLS = [
67
56
  description: 'List the projects/workspaces you can access in Workover.',
68
57
  inputSchema: { type: 'object', properties: {} },
69
58
  },
59
+ {
60
+ name: 'workover_create_doc',
61
+ description:
62
+ "Create a new document in a Workover project (find the projectId with workover_list_projects). The body is added as a proposal, so it appears as tracked-change suggestions for the person to review and accept when they open the doc — nothing is published. Returns the new document's id and URL.",
63
+ inputSchema: {
64
+ type: 'object',
65
+ properties: {
66
+ projectId: {
67
+ type: 'number',
68
+ description:
69
+ 'The numeric id of the project to create the document in, as printed by workover_list_projects ("#7" → 7).',
70
+ },
71
+ title: { type: 'string', description: 'The document title.' },
72
+ markdown: { type: 'string', description: 'The document body as markdown.' },
73
+ },
74
+ required: ['projectId', 'title', 'markdown'],
75
+ },
76
+ },
77
+ {
78
+ name: 'workover_upload_image',
79
+ description:
80
+ "Upload an image (e.g. a product screenshot you captured) into a Workover document's media, and get back a URL to use in the document markdown as ![alt](url). Provide the local file path.",
81
+ inputSchema: {
82
+ type: 'object',
83
+ properties: {
84
+ docId: {
85
+ type: 'number',
86
+ description: 'The numeric id of the document the image belongs to (not a URL handle).',
87
+ },
88
+ path: { type: 'string', description: 'Local file path to the image (png/jpg/webp).' },
89
+ alt: { type: 'string', description: 'Alt text describing the image.' },
90
+ },
91
+ required: ['docId', 'path'],
92
+ },
93
+ },
70
94
  {
71
95
  name: 'workover_propose_edit',
72
96
  description:
@@ -74,7 +98,11 @@ const TOOLS = [
74
98
  inputSchema: {
75
99
  type: 'object',
76
100
  properties: {
77
- docId: { type: 'number', description: 'The document id to propose changes to.' },
101
+ docId: {
102
+ type: 'number',
103
+ description:
104
+ 'The numeric id of the document to propose changes to (not a URL handle).',
105
+ },
78
106
  markdown: {
79
107
  type: 'string',
80
108
  description: 'The complete revised document as markdown (not just the changed parts).',
@@ -97,52 +125,8 @@ const server = new Server(
97
125
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
98
126
 
99
127
  server.setRequestHandler(CallToolRequestSchema, async (req) => {
100
- if (!auth)
101
- return err('Not signed in to Workover. Run `workover login` in your terminal first.');
102
128
  const { name, arguments: args = {} } = req.params;
103
- try {
104
- if (name === 'workover_search_docs') {
105
- const { results = [] } = await api(
106
- `/search/documents?q=${encodeURIComponent(String(args.query || ''))}&limit=10`,
107
- );
108
- if (!results.length) return text('No matching documents.');
109
- return text(
110
- results
111
- .map(
112
- (r) =>
113
- `#${r.id} — ${r.title || 'Untitled'}${r.snippet ? `\n ${stripHtml(r.snippet)}` : ''}`,
114
- )
115
- .join('\n'),
116
- );
117
- }
118
- if (name === 'workover_read_doc') {
119
- const d = await api(`/project/doc/${Number(args.docId)}`);
120
- if (!d || !d.id) return err(`Document ${args.docId} not found (or no access).`);
121
- const body = d.bodyText || stripHtml(d.content) || '(empty document)';
122
- return text(`# ${d.title || 'Untitled'} (id ${d.id})\n\n${body}`);
123
- }
124
- if (name === 'workover_list_projects') {
125
- const projects = await api('/project');
126
- const list = Array.isArray(projects) ? projects : projects?.projects || [];
127
- if (!list.length) return text('No projects.');
128
- return text(list.map((p) => `#${p.id} — ${p.name || p.title || 'Project'}`).join('\n'));
129
- }
130
- if (name === 'workover_propose_edit') {
131
- const md = String(args.markdown || '').trim();
132
- if (!md) return err('Provide the full revised document as `markdown`.');
133
- const res = await apiPost(`/project/doc/${Number(args.docId)}/propose`, {
134
- markdown: md,
135
- note: args.note ? String(args.note) : undefined,
136
- source: 'Claude Code',
137
- });
138
- return text(
139
- `Proposed your changes to document #${args.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.`,
140
- );
141
- }
142
- return err(`Unknown tool: ${name}`);
143
- } catch (e) {
144
- return err(e?.message || 'Something went wrong.');
145
- }
129
+ return dispatch(name, args);
146
130
  });
147
131
 
148
132
  await server.connect(new StdioServerTransport());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.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",
@@ -31,5 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@modelcontextprotocol/sdk": "^1.12.0"
34
+ },
35
+ "scripts": {
36
+ "test": "node --test"
34
37
  }
35
38
  }