viviscape-mcp 2.7.0 → 2.8.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 CHANGED
@@ -116,6 +116,7 @@ The server exposes tools across these domains:
116
116
  - **Bulk** - `tasks_bulk_add` (many tasks in one request)
117
117
  - **Time logs** - `timelog_add`, `timelog_update`
118
118
  - **Notes** - `note_add`, `note_get`, `note_update`, `note_remove`, `notes_mine`, `notes_query`, `notes_account`, `note_revisions`
119
+ - **Second Brain** - `kb_search` (semantic search over tickets, plans, notes, products, resolutions and SOPs), `kb_sop` (list/get/save an SOP), `kb_status`, `kb_reindex`
119
120
  - **Note filing** - `note_companies`, `note_users`, `note_tags`, `note_attachments`, `notebook`, `notebook_users` (each takes an `action`)
120
121
  - **Files** - `project_files` (list/upload/update/delete/download), `task_files`
121
122
  - **Insights** - hours by person/service/project, AI summary, person stats, time totals
@@ -194,6 +195,42 @@ Overview tab, stored as HTML by the rich-text editor. It **replaces** the field
194
195
  outright, so read the current value with `task_get` and send the merged text
195
196
  rather than only the new lines.
196
197
 
198
+ ### Task plans
199
+
200
+ `task_add` and `task_update` take a `plan` field: the plan of action for the
201
+ task or ticket -- the ordered steps an agent intends to take **before** it
202
+ starts, so the work is inspectable and the next agent can pick it up. It shows
203
+ up in the portal on the task's Plan tab, immediately left of Solution.
204
+
205
+ Read it back with `task_get`, or across a set of tasks by asking a list tool
206
+ for it (`fields: ["task_id", "task", "plan"]`) -- the default field set is
207
+ light and leaves it out. Like `notes`, it **replaces** the field outright, so
208
+ send the merged text rather than only the new steps. Omitting the argument
209
+ leaves an existing plan untouched.
210
+
211
+ The three long-text fields divide up as: `plan` = what will be done,
212
+ `notes` = the extended instructions and scenario, `solution` = the outcome.
213
+
214
+ ### Second Brain
215
+
216
+ `kb_search` reads the account knowledge base: the semantic index over tickets
217
+ (description, plan, notes, solution), notes, products, distilled resolutions and
218
+ SOPs. Consult it *before* planning work — it answers whether the thing has been
219
+ solved here before.
220
+
221
+ Two traps:
222
+
223
+ - An empty result is **not** proof the knowledge is absent. Search answers with
224
+ no hits, not an error, when Second Brain is switched off for the account or
225
+ its AI token budget is inside the reserve. `kb_status` distinguishes the two.
226
+ - A `kb_sop` save is *queued* for indexing, not indexed on the spot, so it does
227
+ not turn up in `kb_search` until the next ingest tick.
228
+
229
+ Ticket and note knowledge is ingested automatically. An SOP is the only
230
+ knowledge an agent authors directly, so `kb_sop` save is how a lesson from one
231
+ ticket becomes reusable — search `source_types: ["sop"]` first and update the
232
+ existing SOP rather than filing a near-duplicate.
233
+
197
234
  ### Repeat-safe creates
198
235
 
199
236
  No create route accepts an idempotency key, so a retried agent step silently
@@ -295,6 +295,41 @@ export declare class ViviScapeClient {
295
295
  service_id?: number;
296
296
  }>;
297
297
  }): Promise<unknown>;
298
+ /**
299
+ * Semantic search over the account knowledge base -- tickets and their plans,
300
+ * notes, products, distilled resolutions, and SOPs.
301
+ *
302
+ * Answers an empty list, not an error, when Second Brain is disabled for the
303
+ * account or its AI token budget is inside the reserve, so "no hits" is NOT
304
+ * proof the knowledge is absent. Check kbStatus() before concluding that.
305
+ */
306
+ kbSearch(query: string, opts?: {
307
+ top_k?: number;
308
+ company_id?: number;
309
+ product_id?: string;
310
+ source_types?: string[];
311
+ visibility?: string[];
312
+ }): Promise<unknown>;
313
+ kbStatus(): Promise<unknown>;
314
+ kbFreshness(): Promise<unknown>;
315
+ listSops(opts?: {
316
+ product_id?: string;
317
+ status?: string;
318
+ }): Promise<unknown>;
319
+ getSop(sopId: string): Promise<unknown>;
320
+ /**
321
+ * Create or update an SOP -- the durable, deliberately authored half of the
322
+ * brain, and the way an agent contributes knowledge that outlives one ticket.
323
+ * The server stamps account and creator, then queues the SOP for indexing, so
324
+ * a save becomes searchable on the next ingest tick rather than immediately.
325
+ * Passing sop_id updates in place; omitting it creates.
326
+ */
327
+ saveSop(sop: Record<string, unknown>): Promise<unknown>;
328
+ /**
329
+ * Queue one source for (re)indexing. The portal already enqueues on write,
330
+ * so this is for repairing a document that never made it into the brain.
331
+ */
332
+ kbEnqueue(sourceType: string, sourceKey: string, priority?: number): Promise<unknown>;
298
333
  getHoursByPerson(data: Record<string, unknown>): Promise<unknown>;
299
334
  getTimeLogsByDateRange(data: Record<string, unknown>): Promise<unknown>;
300
335
  getPersonStats(data: Record<string, unknown>): Promise<unknown>;
@@ -88,6 +88,8 @@ function buildTaskPayload(data, ctx) {
88
88
  };
89
89
  if (data.notes)
90
90
  payload.notes = data.notes;
91
+ if (data.plan)
92
+ payload.plan = data.plan;
91
93
  if (data.company_id)
92
94
  payload.company_id = data.company_id;
93
95
  if (data.assigned_to) {
@@ -108,6 +110,8 @@ function buildTaskUpdatePayload(data) {
108
110
  mapped.description = data.description;
109
111
  if (data.notes !== undefined)
110
112
  mapped.notes = data.notes;
113
+ if (data.plan !== undefined)
114
+ mapped.plan = data.plan;
111
115
  if (data.status !== undefined)
112
116
  mapped.status = data.status;
113
117
  if (data.priority !== undefined) {
@@ -1061,6 +1065,64 @@ export class ViviScapeClient {
1061
1065
  })),
1062
1066
  });
1063
1067
  }
1068
+ // -- Second Brain (knowledge base) ---------------------------
1069
+ /**
1070
+ * Semantic search over the account knowledge base -- tickets and their plans,
1071
+ * notes, products, distilled resolutions, and SOPs.
1072
+ *
1073
+ * Answers an empty list, not an error, when Second Brain is disabled for the
1074
+ * account or its AI token budget is inside the reserve, so "no hits" is NOT
1075
+ * proof the knowledge is absent. Check kbStatus() before concluding that.
1076
+ */
1077
+ async kbSearch(query, opts = {}) {
1078
+ return this.post('kb/search', {
1079
+ query,
1080
+ top_k: opts.top_k && opts.top_k > 0 ? opts.top_k : 8,
1081
+ company_id: opts.company_id,
1082
+ product_id: opts.product_id,
1083
+ source_types: opts.source_types,
1084
+ visibility: opts.visibility,
1085
+ });
1086
+ }
1087
+ async kbStatus() {
1088
+ return this.get('kb/account/status');
1089
+ }
1090
+ async kbFreshness() {
1091
+ return this.get('kb/freshness');
1092
+ }
1093
+ async listSops(opts = {}) {
1094
+ const qs = [
1095
+ opts.product_id ? `product_id=${encodeURIComponent(opts.product_id)}` : '',
1096
+ opts.status ? `status=${encodeURIComponent(opts.status)}` : '',
1097
+ ].filter(Boolean).join('&');
1098
+ return this.get(`kb/sop/list${qs ? '?' + qs : ''}`);
1099
+ }
1100
+ async getSop(sopId) {
1101
+ return this.get(`kb/sop/${sopId}`);
1102
+ }
1103
+ /**
1104
+ * Create or update an SOP -- the durable, deliberately authored half of the
1105
+ * brain, and the way an agent contributes knowledge that outlives one ticket.
1106
+ * The server stamps account and creator, then queues the SOP for indexing, so
1107
+ * a save becomes searchable on the next ingest tick rather than immediately.
1108
+ * Passing sop_id updates in place; omitting it creates.
1109
+ */
1110
+ async saveSop(sop) {
1111
+ return this.post('kb/sop/save', sop);
1112
+ }
1113
+ /**
1114
+ * Queue one source for (re)indexing. The portal already enqueues on write,
1115
+ * so this is for repairing a document that never made it into the brain.
1116
+ */
1117
+ async kbEnqueue(sourceType, sourceKey, priority = 5) {
1118
+ return this.post('kb/enqueue', {
1119
+ account_id: this.accountId,
1120
+ source_type: sourceType,
1121
+ source_key: sourceKey,
1122
+ operation: 'upsert',
1123
+ priority,
1124
+ });
1125
+ }
1064
1126
  // -- Insights -----------------------------------------------
1065
1127
  async getHoursByPerson(data) {
1066
1128
  const userId = Number(data.user_id) || this.userId;
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ const pageArgs = {
57
57
  updated_since: z.string().optional()
58
58
  .describe('Only rows touched at or after this time (ISO 8601). Filtered in-process; rows with no timestamp are kept.'),
59
59
  fields: z.array(z.string()).optional()
60
- .describe('Columns to return. Omit for a PM-relevant default; ["all"] for every column.'),
60
+ .describe('Columns to return. Omit for a PM-relevant default; ["all"] for every column. The default set is light: ask for e.g. ["task_id","task","plan"] to read plans across a set of tasks.'),
61
61
  limit: z.number().optional().describe('Max rows to return (default 50)'),
62
62
  offset: z.number().optional().describe('Rows to skip, for paging (default 0)'),
63
63
  };
@@ -378,6 +378,7 @@ server.tool('task_add', 'Add a task to a project. The API requires a full Group_
378
378
  title: z.string().describe('Task title'),
379
379
  description: z.string().optional().describe('Task description'),
380
380
  notes: z.string().optional().describe('Task notes'),
381
+ plan: z.string().optional().describe('Plan of action for the new task -- the ordered steps to be taken before the work starts. Use notes for the extended instructions and scenario.'),
381
382
  assigned_to: z.number().optional().describe('User ID to assign the task to. The signed-in user is always recorded as creator.'),
382
383
  company_id: z.number().optional().describe('Company ID associated with the project'),
383
384
  service_id: z.number().optional().describe('Service ID classifying the work type'),
@@ -416,11 +417,12 @@ server.tool('task_add', 'Add a task to a project. The API requires a full Group_
416
417
  });
417
418
  return { content: [{ type: 'text', text: json(result) }] };
418
419
  });
419
- server.tool('task_update', 'Update a task. Fetches existing task first and merges changes.', {
420
+ server.tool('task_update', 'Update a task. Fetches existing task first and merges changes. This is where an agent records its plan -- see the plan argument.', {
420
421
  task_id: z.number().describe('Task ID to update'),
421
422
  title: z.string().optional().describe('Task title'),
422
423
  description: z.string().optional(),
423
424
  notes: z.string().optional().describe('Task notes -- the free-form working notes on the task Overview tab, held in HTML by the editor. Replaces the field outright, so read the current value with task_get and send the merged text rather than only the new lines.'),
425
+ plan: z.string().optional().describe('Plan of action for the task -- the ordered steps an agent intends to take BEFORE it starts, so the work is inspectable and the next agent can pick it up. Held in HTML by the Plan tab editor; plain text is accepted and stored as typed. Replaces the field outright, so read the current value with task_get and send the merged text rather than only the new steps. Use notes for the extended instructions and scenario, and solution for the outcome. Omit the argument to leave an existing plan untouched.'),
424
426
  assigned_to: z.number().optional().describe('User ID to assign to'),
425
427
  priority: z.enum(PRIORITIES).optional().describe('Priority (platform values)'),
426
428
  status: z.enum(TASK_STATUSES).optional().describe('Task status (platform values)'),
@@ -1100,6 +1102,74 @@ server.tool('insights_all_users_time', 'Get time totals for all users', {}, asyn
1100
1102
  const result = await requireClient().getAllUsersTime();
1101
1103
  return { content: [{ type: 'text', text: json(result) }] };
1102
1104
  });
1105
+ server.tool('kb_search', 'Search the account Second Brain -- the semantic index over tickets (their description, plan, notes and solution), notes, products, distilled resolutions and SOPs. This is the memory to consult BEFORE planning work: it answers "has this been solved here before, and how". Rows carry source_type + source_key, so a hit on a ticket names the task id to open with task_get, and a hit on an SOP names the sop_id to read with kb_sop. score is 1 - cosine distance, so higher is closer. IMPORTANT: an empty result is not proof the knowledge is absent -- the route answers with no hits when Second Brain is switched off for the account or its AI token budget is inside the reserve. Check kb_status when a search of an established account comes back empty.', {
1106
+ query: z.string().describe('What to look for, in natural language -- this is embedded, so a question or a sentence retrieves better than a bare keyword'),
1107
+ top_k: z.number().optional().describe('How many chunks to return (default 8)'),
1108
+ company_id: z.number().optional().describe('Restrict to knowledge tied to one company'),
1109
+ product_id: z.string().optional().describe('Restrict to knowledge tied to one product (GUID)'),
1110
+ source_types: z.array(z.enum(['ticket', 'note', 'product', 'resolution', 'sop'])).optional()
1111
+ .describe('Restrict to these kinds of source. Omit for all of them.'),
1112
+ visibility: z.array(z.string()).optional()
1113
+ .describe('Visibility bands to search; defaults to ["staff"]. Personal note knowledge is never reachable here.'),
1114
+ }, async ({ query, top_k, company_id, product_id, source_types, visibility }) => {
1115
+ const result = await requireClient().kbSearch(query, { top_k, company_id, product_id, source_types, visibility });
1116
+ return { content: [{ type: 'text', text: json(result) }] };
1117
+ });
1118
+ server.tool('kb_status', 'Report whether Second Brain is switched on for this account and how current its index is. Read this when kb_search comes back empty on an account that plainly has history: search answers with no hits (not an error) when the brain is disabled or the AI token budget is inside its reserve, and the freshness figures show what is still queued for ingest.', {}, async () => {
1119
+ const c = requireClient();
1120
+ const [status, freshness] = await Promise.all([c.kbStatus(), c.kbFreshness()]);
1121
+ return { content: [{ type: 'text', text: json({ status, freshness }) }] };
1122
+ });
1123
+ server.tool('kb_sop', 'List, read, or write SOPs -- the durable, deliberately authored half of the Second Brain, and the way an agent contributes knowledge meant to outlive one ticket (a runbook, a recurring fix, a house convention). Ticket and note knowledge is ingested automatically; an SOP is the only knowledge an agent authors directly. save creates when sop_id is omitted and updates in place when it is given, and it returns the sop_id either way. A saved SOP is QUEUED for indexing rather than indexed on the spot, so kb_search will not surface it until the next ingest tick. Prefer updating the existing SOP over filing a near-duplicate: search first with kb_search source_types ["sop"]. New SOPs land as status "draft" so a person can approve them.', {
1124
+ action: z.enum(['list', 'get', 'save']).describe('What to do'),
1125
+ sop_id: z.string().optional().describe('SOP ID (get; and on save, to update that SOP in place instead of creating one)'),
1126
+ title: z.string().optional().describe('SOP title (save, required)'),
1127
+ body: z.string().optional().describe('The procedure itself (save). Plain text or light markdown; this is what gets embedded and retrieved.'),
1128
+ triggers: z.string().optional().describe('When this SOP applies -- the symptoms, phrases or conditions that should pull it up (save)'),
1129
+ product_id: z.string().optional().describe('Product this SOP belongs to (GUID), for both filtering a list and tagging a save'),
1130
+ source_task_id: z.number().optional().describe('The task or ticket this SOP was written from (save) -- keeps the provenance of the procedure'),
1131
+ status: z.enum(['draft', 'approved', 'archived']).optional()
1132
+ .describe('On list, filter by status. On save, the status to store -- leave unset when creating so it lands as a draft for review.'),
1133
+ visibility: z.enum(['staff', 'customer']).optional()
1134
+ .describe('Who may retrieve this SOP (save). Defaults to staff; use customer only for text fit to leave the building.'),
1135
+ }, async ({ action, sop_id, title, body, triggers, product_id, source_task_id, status, visibility }) => {
1136
+ const c = requireClient();
1137
+ let result;
1138
+ if (action === 'list') {
1139
+ result = await c.listSops({ product_id, status });
1140
+ }
1141
+ else if (action === 'get') {
1142
+ result = await c.getSop(need(action, 'sop_id', sop_id));
1143
+ }
1144
+ else {
1145
+ // The server requires a title and fills account/creator itself. Only send
1146
+ // what was supplied: an omitted field must not blank a stored one.
1147
+ const sop = { title: need(action, 'title', title) };
1148
+ if (sop_id !== undefined)
1149
+ sop.sop_id = sop_id;
1150
+ if (body !== undefined)
1151
+ sop.body = body;
1152
+ if (triggers !== undefined)
1153
+ sop.triggers = triggers;
1154
+ if (product_id !== undefined)
1155
+ sop.product_id = product_id;
1156
+ if (source_task_id !== undefined)
1157
+ sop.source_task_id = source_task_id;
1158
+ if (status !== undefined)
1159
+ sop.status = status;
1160
+ if (visibility !== undefined)
1161
+ sop.visibility = visibility;
1162
+ result = await c.saveSop(sop);
1163
+ }
1164
+ return { content: [{ type: 'text', text: json(result) }] };
1165
+ });
1166
+ server.tool('kb_reindex', 'Queue one source document for re-indexing into the Second Brain. The portal enqueues on every write already, so reach for this only to repair a document that never made it in -- a ticket whose plan or solution kb_search cannot find, say. source_key is the task id for a ticket, the note/product/SOP GUID otherwise.', {
1167
+ source_type: z.enum(['ticket', 'note', 'product', 'resolution', 'sop']).describe('Kind of source to reindex'),
1168
+ source_key: z.string().describe('Task id (ticket) or GUID (note, product, resolution, sop)'),
1169
+ }, async ({ source_type, source_key }) => {
1170
+ const result = await requireClient().kbEnqueue(source_type, source_key);
1171
+ return { content: [{ type: 'text', text: json(result) }] };
1172
+ });
1103
1173
  // ============================================================
1104
1174
  // START
1105
1175
  // ============================================================
@@ -90,7 +90,7 @@ export function filterTasks(rows, f) {
90
90
  if (f.assignee_id && !assigneeIds(row).includes(f.assignee_id))
91
91
  return false;
92
92
  if (f.search) {
93
- const hay = `${lower(row.task)} ${lower(row.description)} ${lower(row.notes)}`;
93
+ const hay = `${lower(row.task)} ${lower(row.description)} ${lower(row.notes)} ${lower(row.plan)}`;
94
94
  if (!hay.includes(f.search.toLowerCase()))
95
95
  return false;
96
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viviscape-mcp",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "MCP server for the ViviScape API — CRM, projects, companies, notes, and insights, authenticated as the signed-in ViviScape user",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",