@operad-io/mcp 0.1.1 → 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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@operad-io/mcp",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
7
7
  "./stdio": "./src/stdio.ts"
8
8
  },
9
9
  "dependencies": {
10
- "@operad-io/engine": "0.1.1"
10
+ "@operad-io/engine": "0.2.0"
11
11
  },
12
12
  "description": "operad: the MCP server and channel",
13
13
  "repository": {
package/src/channel.ts CHANGED
@@ -10,12 +10,14 @@
10
10
  * differs or its waiting flag turns on, and never repeats the row it last sent.
11
11
  */
12
12
 
13
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
14
- import { dirname } from "node:path";
13
+ import { readFile } from "node:fs/promises";
14
+ import { writeJsonAtomic } from "@operad-io/engine/platform";
15
15
  import {
16
16
  CHANNEL_NOTIFY_KINDS,
17
17
  DEFAULT_MCP_CHANNEL,
18
+ isMissingFile,
18
19
  messageOf,
20
+ parseObjectId,
19
21
  type ChannelNotifyKind,
20
22
  ViewError,
21
23
  type LogBackend,
@@ -30,9 +32,6 @@ import {
30
32
  /** The experiment capability Claude Code reads a channel declaration from. */
31
33
  export const CHANNEL_CAPABILITY = "claude/channel";
32
34
 
33
- /** The capability this server never declares: it relays no permission prompts. */
34
- export const CHANNEL_PERMISSION_CAPABILITY = "claude/channel/permission";
35
-
36
35
  /** The notification method a channel event is sent with. */
37
36
  export const CHANNEL_METHOD = "notifications/claude/channel";
38
37
 
@@ -127,10 +126,7 @@ interface SeenRow {
127
126
 
128
127
  /** Reads a run's object key, such as `task:42`. */
129
128
  function objectOf(key: string | undefined): ObjectRef | undefined {
130
- if (key === undefined) return undefined;
131
- const at = key.indexOf(":");
132
- if (at <= 0 || at === key.length - 1) return undefined;
133
- return { type: key.slice(0, at), id: key.slice(at + 1) };
129
+ return key === undefined ? undefined : parseObjectId(key);
134
130
  }
135
131
 
136
132
  function rowKey(type: string, id: string): string {
@@ -355,7 +351,7 @@ class ClaudeChannel implements ChannelHandle {
355
351
  try {
356
352
  text = await readFile(this.sentFile, "utf8");
357
353
  } catch (error) {
358
- if ((error as { code?: unknown }).code === "ENOENT") return;
354
+ if (isMissingFile(error)) return;
359
355
  this.onLog(`channel: the sent rows could not be read: ${messageOf(error)}`);
360
356
  return;
361
357
  }
@@ -383,10 +379,9 @@ class ClaudeChannel implements ChannelHandle {
383
379
  private async saveSent(): Promise<void> {
384
380
  if (this.sentFile === undefined) return;
385
381
  try {
386
- await mkdir(dirname(this.sentFile), { recursive: true });
387
- const temp = `${this.sentFile}.${process.pid}.tmp`;
388
- await writeFile(temp, JSON.stringify(Object.fromEntries(this.sent)));
389
- await rename(temp, this.sentFile);
382
+ await writeJsonAtomic(this.sentFile, Object.fromEntries(this.sent), {
383
+ newline: false,
384
+ });
390
385
  } catch (error) {
391
386
  this.onLog(`channel: the sent rows could not be saved: ${messageOf(error)}`);
392
387
  }
package/src/format.ts CHANGED
@@ -9,6 +9,7 @@ import type {
9
9
  ViewSectionContent,
10
10
  ViewTypeInfo,
11
11
  } from "@operad-io/engine";
12
+ import { formatElapsed, isRecord } from "@operad-io/engine";
12
13
  import type { MachineLoad } from "@operad-io/engine/platform";
13
14
  import type { McpViewObject } from "./policy.ts";
14
15
 
@@ -66,11 +67,12 @@ export function typesMarkdown(types: readonly ViewTypeInfo[]): string {
66
67
  function actionMarkdown(action: ViewObject["actions"][number]): string[] {
67
68
  const key = action.key === undefined ? "" : ` (${action.key})`;
68
69
  const lines = [`- \`${action.name}\`${key}`];
69
- lines.push(` - on: \`${action.on}\``);
70
+ lines.push(` - on: ${action.on === undefined ? "none" : `\`${action.on}\``}`);
70
71
  lines.push(
71
72
  ` - note: ${action.note === undefined ? "none" : `\`${action.note}\`${action.noteRequired ? " (required)" : ""}`}`,
72
73
  );
73
74
  lines.push(` - confirm: ${action.confirm ? "yes" : "no"}`);
75
+ if (action.command !== undefined) lines.push(` - command: ${action.command}`);
74
76
  if (action.creates !== undefined) lines.push(` - creates: \`${action.creates}\``);
75
77
  if (action.args === undefined) {
76
78
  lines.push(" - args: none");
@@ -118,6 +120,17 @@ export function showMarkdown(object: ViewObject | McpViewObject): string {
118
120
  }
119
121
  }
120
122
 
123
+ if (object.skills !== undefined) {
124
+ lines.push("", "## Skills");
125
+ if (object.skills.length === 0) {
126
+ lines.push("No skills.");
127
+ } else {
128
+ for (const skill of object.skills) {
129
+ lines.push(`- \`/${skill.name}\`${skill.description === undefined ? "" : `: ${skill.description}`}`);
130
+ }
131
+ }
132
+ }
133
+
121
134
  lines.push("", "## Actions");
122
135
  if (object.actions.length === 0) {
123
136
  lines.push("No actions are available now.");
@@ -149,17 +162,22 @@ export function sectionMarkdown(content: ViewSectionContent): string {
149
162
  return `${content.markdown}${separator}Next cursor: \`${content.next}\`\n`;
150
163
  }
151
164
 
152
- /** The history tool's Markdown is the history section's Markdown. */
153
- export function historyMarkdown(content: ViewSectionContent): string {
154
- return sectionMarkdown(content);
155
- }
156
-
157
165
  function pendingItemMarkdown(item: PendingItem): string[] {
158
166
  const lines = [`## ${item.runId} (${item.flow})`];
159
167
  lines.push(`- step: ${item.step ?? "-"}`);
160
168
  lines.push(`- waiting: ${item.prompt}`);
161
169
  if (item.choices.length > 0) {
162
170
  lines.push(`- choices: ${item.choices.join(", ")}`);
171
+ for (const choice of item.choices) {
172
+ const info = item.choiceInfo?.[choice];
173
+ if (info === undefined) continue;
174
+ const parts: string[] = [];
175
+ if (info.label !== undefined) parts.push(`label ${info.label}`);
176
+ if (info.hint !== undefined) parts.push(info.hint);
177
+ if (info.role !== undefined) parts.push(info.role);
178
+ if (info.note !== undefined) parts.push(`note ${info.note}`);
179
+ if (parts.length > 0) lines.push(` - ${choice}: ${parts.join("; ")}`);
180
+ }
163
181
  }
164
182
  if (item.actions.length > 0) {
165
183
  lines.push(
@@ -182,15 +200,6 @@ export function pendingMarkdown(pending: readonly PendingItem[]): string {
182
200
  return `${lines.join("\n")}\n`;
183
201
  }
184
202
 
185
- function elapsed(ms: number): string {
186
- if (ms < 1000) return `${ms}ms`;
187
- const whole = Math.floor(ms / 1000);
188
- if (whole < 60) return `${(ms / 1000).toFixed(1)}s`;
189
- const minutes = Math.floor(whole / 60);
190
- const rest = whole % 60;
191
- return `${minutes}m ${rest}s`;
192
- }
193
-
194
203
  /** Every active run as a Markdown table. */
195
204
  export function runningMarkdown(
196
205
  running: readonly RunningItem[],
@@ -204,8 +213,84 @@ export function runningMarkdown(
204
213
  ];
205
214
  for (const item of running) {
206
215
  lines.push(
207
- `| ${cell(item.object ?? item.runId)} | ${cell(item.title ?? "")} | ${cell(item.flow)} | ${cell(item.stepLabel ?? "-")} | ${item.stepElapsedMs === null ? "-" : elapsed(item.stepElapsedMs)}${item.queuedMs === undefined || item.queuedMs <= 0 ? "" : ` (queued ${elapsed(item.queuedMs)})`} | ${elapsed(item.elapsedMs)} |`,
216
+ `| ${cell(item.object ?? item.runId)} | ${cell(item.title ?? "")} | ${cell(item.flow)} | ${cell(item.stepLabel ?? "-")} | ${item.stepElapsedMs === null ? "-" : formatElapsed(item.stepElapsedMs)}${item.queuedMs === undefined || item.queuedMs <= 0 ? "" : ` (queued ${formatElapsed(item.queuedMs)})`} | ${formatElapsed(item.elapsedMs)} |`,
208
217
  );
209
218
  }
210
219
  return `${lines.join("\n")}\n\n${loadLine}`;
211
220
  }
221
+
222
+ function textValue(value: unknown): string {
223
+ return typeof value === "string" ? value : "";
224
+ }
225
+
226
+ function numberValue(value: unknown): string {
227
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : "?";
228
+ }
229
+
230
+ /** Whether a result or a backlink says its note came from untrusted content. */
231
+ function untrustedOf(value: Readonly<Record<string, unknown>>): boolean {
232
+ if (value["untrusted"] === true) return true;
233
+ const fields = value["fields"];
234
+ if (!isRecord(fields)) return false;
235
+ const values = fields["untrusted"];
236
+ return (
237
+ Array.isArray(values) &&
238
+ values.some((item) => typeof item === "string" && item.trim().toLowerCase() === "true")
239
+ );
240
+ }
241
+
242
+ /** One search result as the lines a reader scans, and the directory notes. */
243
+ export function searchMarkdown(value: unknown): string {
244
+ if (!isRecord(value) || !Array.isArray(value["hits"])) return valueText(value);
245
+ const query = textValue(value["query"]);
246
+ const hits = value["hits"].filter(isRecord);
247
+ const lines = [`# Search: ${query}`, ""];
248
+ if (hits.length === 0) {
249
+ lines.push("No results.");
250
+ } else {
251
+ for (const hit of hits) {
252
+ const where = [hit["scope"], hit["path"], `lines ${numberValue(hit["lineStart"])}-${numberValue(hit["lineEnd"])}`]
253
+ .filter((part) => typeof part === "string" && part.length > 0)
254
+ .join(" · ");
255
+ const mark = untrustedOf(hit) ? " (untrusted)" : "";
256
+ lines.push(`- \`${textValue(hit["id"])}\` — ${textValue(hit["title"])} (${where})${mark}`);
257
+ const snippet = textValue(hit["snippet"]);
258
+ if (snippet.length > 0) lines.push(` ${snippet}`);
259
+ }
260
+ }
261
+ const about = Array.isArray(value["about"]) ? value["about"].filter(isRecord) : [];
262
+ if (about.length > 0) {
263
+ lines.push("", "## Directory notes");
264
+ for (const note of about) {
265
+ lines.push(`### ${textValue(note["title"])}`, "", textValue(note["text"]));
266
+ }
267
+ }
268
+ return `${lines.join("\n")}\n`;
269
+ }
270
+
271
+ /** One document, or the line range that was asked for. */
272
+ export function readMarkdown(value: unknown): string {
273
+ if (!isRecord(value)) return valueText(value);
274
+ const lines = [`# ${textValue(value["title"])}`, ""];
275
+ lines.push(`- id: \`${textValue(value["id"])}\``);
276
+ const path = textValue(value["path"]);
277
+ if (path.length > 0) lines.push(`- path: ${path}`);
278
+ lines.push(
279
+ `- lines: ${numberValue(value["lineStart"])}-${numberValue(value["lineEnd"])} of ${numberValue(value["totalLines"])}`,
280
+ );
281
+ const text = textValue(value["text"]);
282
+ if (text.length > 0) lines.push("", text);
283
+ const backlinks = Array.isArray(value["backlinks"]) ? value["backlinks"].filter(isRecord) : [];
284
+ if (backlinks.length > 0) {
285
+ lines.push("", "## Backlinks");
286
+ for (const entry of backlinks) {
287
+ const line = typeof entry["line"] === "number" && Number.isFinite(entry["line"]) ? ` line ${entry["line"]}` : "";
288
+ const mark = untrustedOf(entry) ? " (untrusted)" : "";
289
+ const excerpt = textValue(entry["excerpt"]);
290
+ lines.push(
291
+ `- \`${textValue(entry["path"])}\`${line}${mark}${excerpt.length > 0 ? ` — ${excerpt}` : ""}`,
292
+ );
293
+ }
294
+ }
295
+ return `${lines.join("\n")}\n`;
296
+ }
package/src/index.ts CHANGED
@@ -15,7 +15,6 @@ export {
15
15
  CHANNEL_CAPABILITY,
16
16
  CHANNEL_INSTRUCTIONS,
17
17
  CHANNEL_METHOD,
18
- CHANNEL_PERMISSION_CAPABILITY,
19
18
  ChannelNotifyError,
20
19
  ChannelTypeError,
21
20
  type ChannelReason,
package/src/server.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import { readFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
- import { Kernel, ViewError, cancelRun, createViews, defaultOperadHome, isRecord, listPending, loadPluginRegistry, messageOf, openConfigLog, openPluginStore, readConfig, recordAnswer, storeRootOf, type ActionInfo, type LogBackend, type OperadConfig, type PluginRegistry, type Views } from "@operad-io/engine";
6
+ import { Kernel, ViewError, defaultOperadHome, isRecord, listPending, loadTriggerRules, messageOf, openHome, type ActionInfo, type LogBackend, type OperadConfig, type PluginRegistry, type Views } from "@operad-io/engine";
7
7
  import { InvalidToolArguments } from "./arguments.ts";
8
8
  import { actionInfoNamed, actionMayRun, mcpPolicy } from "./policy.ts";
9
9
  import {
@@ -181,63 +181,41 @@ async function openContext(
181
181
  onLog: (message: string) => void | Promise<void>,
182
182
  installOnEnable: readonly string[] | undefined,
183
183
  ): Promise<OpenContext> {
184
- const config: OperadConfig = await readConfig(home);
185
- const storeRoot = storeRootOf(config);
186
- const store = openPluginStore({
187
- backend: config.store.backend,
188
- root: storeRoot,
189
- });
190
- const log = openConfigLog(config);
191
- let loaded: PluginRegistry | undefined;
192
- const registry = await loadPluginRegistry({
184
+ const opened = await openHome({
193
185
  home,
194
186
  cwd,
195
- store,
196
- ...(installOnEnable === undefined ? {} : { installOnEnable }),
197
- onCancelRun: (runId, graph) =>
198
- cancelRun({
199
- log,
200
- flow: (name) => loaded?.flow(name)?.flow,
201
- runId,
202
- graph,
203
- clock,
204
- source: "mcp",
205
- }),
206
- onAnswer: async (runId, choice, note, actor) => {
207
- await recordAnswer({
208
- log,
209
- runId,
210
- choice,
211
- ...(note === undefined ? {} : { note }),
212
- actor,
213
- });
214
- },
215
- onLog: (message) => {
216
- void onLog(message);
217
- },
218
- });
219
- loaded = registry;
220
- const views = createViews({
221
- registry,
222
- store,
223
- log,
224
- cwd,
225
187
  clock,
188
+ ...(installOnEnable === undefined ? {} : { installOnEnable }),
189
+ cancelSource: "mcp",
226
190
  onLog: (message) => {
227
191
  void onLog(message);
228
192
  },
229
- });
230
- const kernel = new Kernel({
231
- log,
232
- registry,
233
- home,
234
- storeRoot,
235
- clock,
236
- onLog: (message) => {
237
- void onLog(message);
193
+ // An action may emit an event. Route it like an event from any other
194
+ // client; a rule file that does not read is reported and records only.
195
+ loadRules: async (registry) => {
196
+ try {
197
+ return await loadTriggerRules({
198
+ home,
199
+ registry,
200
+ onLog: (message) => {
201
+ void onLog(message);
202
+ },
203
+ });
204
+ } catch (error) {
205
+ await onLog(messageOf(error));
206
+ return [];
207
+ }
238
208
  },
239
209
  });
240
- return { views, log, registry, kernel, mcp: config.mcp, cwd, storeRoot };
210
+ return {
211
+ views: opened.views,
212
+ log: opened.log,
213
+ registry: opened.registry,
214
+ kernel: opened.kernel,
215
+ mcp: opened.config.mcp,
216
+ cwd: opened.cwd,
217
+ storeRoot: opened.storeRoot,
218
+ };
241
219
  }
242
220
 
243
221
  function toolContext(
@@ -255,10 +233,15 @@ function toolContext(
255
233
  };
256
234
  }
257
235
 
258
- function requireEmptyParams(params: unknown): void {
236
+ /**
237
+ * A request parameter object. The MCP specification lets any request carry
238
+ * `_meta`, a list request carry `cursor`, and its schema leaves params open to
239
+ * other keys, so nothing beyond the object shape is refused here.
240
+ */
241
+ function requireParamsObject(params: unknown): void {
259
242
  if (params === undefined || params === null) return;
260
- if (!isRecord(params) || Object.keys(params).length > 0) {
261
- throw new RpcError(RPC_ERRORS.params, "this method takes no parameters");
243
+ if (!isRecord(params)) {
244
+ throw new RpcError(RPC_ERRORS.params, "this method takes an object of parameters");
262
245
  }
263
246
  }
264
247
 
@@ -331,10 +314,10 @@ async function dispatch(
331
314
  : instructionsFor(context.mcp, context.registry.actions()),
332
315
  };
333
316
  case "ping":
334
- requireEmptyParams(params);
317
+ requireParamsObject(params);
335
318
  return {};
336
319
  case "tools/list":
337
- requireEmptyParams(params);
320
+ requireParamsObject(params);
338
321
  return { tools: TOOLS };
339
322
  case "tools/call":
340
323
  return callTool(params, context);
package/src/tools.ts CHANGED
@@ -15,6 +15,7 @@ import type {
15
15
  import {
16
16
  fileProperties,
17
17
  HISTORY_SECTION,
18
+ KERNEL_VERBS,
18
19
  listPending,
19
20
  listRunning,
20
21
  listTypes,
@@ -26,10 +27,11 @@ import {
26
27
  import { machineLoad, type MachineLoad } from "@operad-io/engine/platform";
27
28
  import { InvalidToolArguments, validateArguments } from "./arguments.ts";
28
29
  import {
29
- historyMarkdown,
30
30
  listMarkdown,
31
31
  pendingMarkdown,
32
+ readMarkdown,
32
33
  runningMarkdown,
34
+ searchMarkdown,
33
35
  sectionMarkdown,
34
36
  showMarkdown,
35
37
  typesMarkdown,
@@ -67,25 +69,6 @@ export interface ToolDefinition {
67
69
  readonly inputSchema: InputSchema;
68
70
  }
69
71
 
70
- /** Kernel command names; a plugin verb is never reachable through MCP. */
71
- const KERNEL_VERBS = new Set([
72
- "init",
73
- "serve",
74
- "pending",
75
- "history",
76
- "running",
77
- "flows",
78
- "trigger",
79
- "list",
80
- "show",
81
- "plugin",
82
- "secret",
83
- "http",
84
- "pair",
85
- "run-internal",
86
- "mcp",
87
- ]);
88
-
89
72
  /** The tools this server offers, in the order it lists them. */
90
73
  export const TOOLS = [
91
74
  {
@@ -129,7 +112,7 @@ export const TOOLS = [
129
112
  },
130
113
  {
131
114
  name: "show",
132
- description: "Show one object's row, sections and available actions.",
115
+ description: "Show one object's row, sections, skills and available actions.",
133
116
  inputSchema: {
134
117
  type: "object",
135
118
  required: ["id"],
@@ -247,6 +230,67 @@ export const TOOLS = [
247
230
  },
248
231
  },
249
232
  },
233
+ {
234
+ name: "search",
235
+ description:
236
+ "Search the shared wiki, this bot's memory and this bot's chats. Try several phrasings before answering that you do not know. Each result says its document id and line range; read the document with `read`.",
237
+ inputSchema: {
238
+ type: "object",
239
+ required: ["query"],
240
+ additionalProperties: false,
241
+ properties: {
242
+ query: {
243
+ type: "string",
244
+ minLength: 1,
245
+ description: "Words to look for. A phrase may be Chinese or mixed Chinese and English.",
246
+ },
247
+ scope: {
248
+ type: "string",
249
+ minLength: 1,
250
+ description: "One of wiki, memory or chats; a comma-separated list also works. The default is all three.",
251
+ },
252
+ scopes: {
253
+ type: "array",
254
+ items: { type: "string", minLength: 1 },
255
+ description: "The scopes to search, as a list instead of `scope`.",
256
+ },
257
+ fields: {
258
+ type: "object",
259
+ description:
260
+ "Frontmatter fields a result must have, such as {\"tags\":\"project\"}; a list means any of its values.",
261
+ },
262
+ limit: {
263
+ type: "integer",
264
+ description: "The most results to return, from 1 to 100; 20 by default.",
265
+ },
266
+ },
267
+ },
268
+ },
269
+ {
270
+ name: "read",
271
+ description:
272
+ "Read a document a search returned, or a line range of it. Lines start at 1.",
273
+ inputSchema: {
274
+ type: "object",
275
+ required: ["id"],
276
+ additionalProperties: false,
277
+ properties: {
278
+ id: {
279
+ type: "string",
280
+ minLength: 1,
281
+ description: "A document id from a search result.",
282
+ },
283
+ from: {
284
+ type: "integer",
285
+ description: "The first line to return, starting at 1.",
286
+ },
287
+ to: {
288
+ type: "integer",
289
+ description: "The last line to return.",
290
+ },
291
+ },
292
+ },
293
+ },
250
294
  {
251
295
  name: "command",
252
296
  description: "Run a plugin verb the way the CLI does.",
@@ -358,6 +402,23 @@ function structuredValue(value: unknown): object {
358
402
  return { value };
359
403
  }
360
404
 
405
+ /** Runs one of the memory plugin's search verbs with JSON arguments. */
406
+ async function runMemoryVerb(
407
+ context: ToolContext,
408
+ verb: "search" | "read",
409
+ input: Readonly<Record<string, unknown>>,
410
+ ): Promise<unknown> {
411
+ const argv = ["memory", verb];
412
+ const run = await context.registry.runCommand(argv, {
413
+ ...(context.cwd === undefined ? {} : { cwd: context.cwd }),
414
+ input: JSON.stringify(input),
415
+ });
416
+ if (run === undefined) {
417
+ throw new Error("the memory plugin is not loaded; enable it with `operad plugin enable memory`");
418
+ }
419
+ return run.value;
420
+ }
421
+
361
422
  /**
362
423
  * Runs one read tool. The arguments are already checked against the table's
363
424
  * input schema by the caller.
@@ -529,14 +590,44 @@ export async function runTool(
529
590
  const content = await context.views.section(id, HISTORY_SECTION);
530
591
  const result = { id, ...content };
531
592
  return {
532
- content: [text(historyMarkdown(result))],
593
+ content: [text(sectionMarkdown(result))],
533
594
  structuredContent: result,
534
595
  };
535
596
  }
597
+ case "search": {
598
+ const input: Record<string, unknown> = { query: String(args.query) };
599
+ if (args.scope !== undefined) input["scope"] = String(args.scope);
600
+ if (args.scopes !== undefined) input["scopes"] = args.scopes;
601
+ if (args.fields !== undefined) input["fields"] = args.fields;
602
+ if (args.limit !== undefined) input["limit"] = args.limit;
603
+ try {
604
+ const value = await runMemoryVerb(context, "search", input);
605
+ return {
606
+ content: [text(searchMarkdown(value))],
607
+ structuredContent: structuredValue(value),
608
+ };
609
+ } catch (error) {
610
+ return toolError(messageOf(error));
611
+ }
612
+ }
613
+ case "read": {
614
+ const input: Record<string, unknown> = { id: String(args.id) };
615
+ if (args.from !== undefined) input["from"] = args.from;
616
+ if (args.to !== undefined) input["to"] = args.to;
617
+ try {
618
+ const value = await runMemoryVerb(context, "read", input);
619
+ return {
620
+ content: [text(readMarkdown(value))],
621
+ structuredContent: structuredValue(value),
622
+ };
623
+ } catch (error) {
624
+ return toolError(messageOf(error));
625
+ }
626
+ }
536
627
  case "command": {
537
628
  const plugin = String(args.plugin);
538
629
  const verb = String(args.verb);
539
- if (KERNEL_VERBS.has(plugin)) {
630
+ if (KERNEL_VERBS.some((name) => name === plugin)) {
540
631
  return toolError(
541
632
  `"${plugin}" is a kernel verb; it is not reachable through MCP`,
542
633
  );
@@ -551,7 +642,7 @@ export async function runTool(
551
642
  resolved.plugin !== plugin ||
552
643
  resolved.command !== verb
553
644
  ) {
554
- if (KERNEL_VERBS.has(verb)) {
645
+ if (KERNEL_VERBS.some((name) => name === verb)) {
555
646
  return toolError(
556
647
  `"${verb}" is a kernel verb; it is not reachable through MCP`,
557
648
  );