@b3os/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 (73) hide show
  1. package/README.md +129 -43
  2. package/bin/b3os-mcp.js +14 -3
  3. package/dist/compact.d.ts +27 -0
  4. package/dist/compact.js +138 -0
  5. package/dist/compact.js.map +1 -0
  6. package/dist/handlers/_common.d.ts +150 -0
  7. package/dist/handlers/_common.js +329 -0
  8. package/dist/handlers/_common.js.map +1 -0
  9. package/dist/handlers/actions.d.ts +19 -0
  10. package/dist/handlers/actions.js +110 -0
  11. package/dist/handlers/actions.js.map +1 -0
  12. package/dist/handlers/render.d.ts +7 -0
  13. package/dist/handlers/render.js +72 -0
  14. package/dist/handlers/render.js.map +1 -0
  15. package/dist/handlers/routines.d.ts +20 -0
  16. package/dist/handlers/routines.js +128 -0
  17. package/dist/handlers/routines.js.map +1 -0
  18. package/dist/handlers/sandboxes.d.ts +2 -0
  19. package/dist/handlers/sandboxes.js +100 -0
  20. package/dist/handlers/sandboxes.js.map +1 -0
  21. package/dist/handlers/vision.d.ts +7 -0
  22. package/dist/handlers/vision.js +186 -0
  23. package/dist/handlers/vision.js.map +1 -0
  24. package/dist/index.d.ts +3 -2
  25. package/dist/index.js +3 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/main.js +88 -7
  28. package/dist/main.js.map +1 -1
  29. package/dist/server.d.ts +68 -1
  30. package/dist/server.js +175 -18
  31. package/dist/server.js.map +1 -1
  32. package/dist/stdio.d.ts +24 -1
  33. package/dist/stdio.js +89 -12
  34. package/dist/stdio.js.map +1 -1
  35. package/dist/table-types.d.ts +84 -0
  36. package/dist/table-types.js +4 -0
  37. package/dist/table-types.js.map +1 -0
  38. package/dist/table.d.ts +54 -0
  39. package/dist/table.gen.d.ts +7 -0
  40. package/dist/table.gen.js +3754 -0
  41. package/dist/table.gen.js.map +1 -0
  42. package/dist/table.js +240 -0
  43. package/dist/table.js.map +1 -0
  44. package/dist/tools.d.ts +61 -47
  45. package/dist/tools.js +231 -705
  46. package/dist/tools.js.map +1 -1
  47. package/package.json +16 -6
  48. package/src/compact.ts +127 -0
  49. package/src/handlers/_common.ts +433 -0
  50. package/src/handlers/actions.ts +144 -0
  51. package/src/handlers/render.ts +90 -0
  52. package/src/handlers/routines.ts +152 -0
  53. package/src/handlers/sandboxes.ts +110 -0
  54. package/src/handlers/vision.ts +213 -0
  55. package/src/index.ts +36 -0
  56. package/src/main.ts +79 -7
  57. package/src/server.ts +225 -19
  58. package/src/stdio.ts +107 -10
  59. package/src/table-types.ts +88 -0
  60. package/src/table.gen.ts +3812 -0
  61. package/src/table.ts +304 -0
  62. package/src/tools.ts +310 -785
  63. package/table/core.mjs +73 -0
  64. package/table/requests.json +1151 -0
  65. package/table/table.json +3763 -0
  66. package/table/tools/actions.mjs +55 -0
  67. package/table/tools/infer.mjs +52 -0
  68. package/table/tools/platform.mjs +76 -0
  69. package/table/tools/render.mjs +126 -0
  70. package/table/tools/routines.mjs +70 -0
  71. package/table/tools/sandboxes.mjs +269 -0
  72. package/table/tools/vision.mjs +316 -0
  73. package/table/tools.mjs +92 -0
@@ -0,0 +1,316 @@
1
+ // Vision tools of the MCP tool table (owner: vision, plan 1.2). table/tools.mjs composes every
2
+ // product's TOOLS with core.mjs; the field options are described there. Keep the entries in tools/list order:
3
+ // core tools follow CORE in core.mjs, the rest of this list keeps its order within the vision toolset.
4
+
5
+ import { WAIT_S } from "../core.mjs";
6
+
7
+ /** @type {import("../../scripts/gen-table.mjs").ToolSource[]} */
8
+ export const TOOLS = [
9
+ {
10
+ name: "vision_scrape",
11
+ group: "core",
12
+ title: "Scrape a web page",
13
+ description:
14
+ "Fetch one URL and return its main content as Markdown (or html, text, links, a screenshot, or JSON filled " +
15
+ "from a schema by the node's model). Answers from the cache when a fresh copy exists, uses a plain HTTP fetch " +
16
+ "when that is enough, and a real browser when the page needs JavaScript.",
17
+ op: "visionScrape",
18
+ body: {
19
+ url: {},
20
+ formats: {},
21
+ only_main_content: {},
22
+ engine: {},
23
+ wait_for_ms: {},
24
+ max_age_ms: {},
25
+ timeout_ms: {
26
+ description: null,
27
+ pinned:
28
+ "loop-v2 suite v2.4 pins vision_scrape's schema (bench/loop/v2/suite.json tools.sha256), and the spec's text " +
29
+ "came after it (ce0f53524): keep it out until the 11-10 window's loop-v2 runs are booked, then bump the suite",
30
+ },
31
+ profile: {
32
+ description:
33
+ "A profile ID or name to load cookies and storage from. Implies engine browser and takes one of the " +
34
+ "organization's concurrent sessions while it runs.",
35
+ },
36
+ mobile: {},
37
+ json: { collapse: true, keys: ["schema", "prompt"] },
38
+ respect_robots: {
39
+ description:
40
+ "Check robots.txt and Content Signals first: a URL they disallow answers 403 robots_disallowed (not " +
41
+ "billed). Off by default.",
42
+ },
43
+ },
44
+ args: {
45
+ max_chars: {
46
+ type: "integer",
47
+ minimum: 1000,
48
+ default: 100000,
49
+ description: "Truncate the text of the result to this many characters.",
50
+ },
51
+ },
52
+ hints: { readOnlyHint: true, openWorldHint: true },
53
+ },
54
+ {
55
+ name: "vision_map",
56
+ group: "core",
57
+ title: "List a site's URLs",
58
+ description:
59
+ "Discover the URLs of a site from its links and sitemaps, optionally ordered by relevance to a search phrase.",
60
+ op: "visionMap",
61
+ body: {
62
+ url: {},
63
+ search: {},
64
+ limit: { default: 200 },
65
+ include_subdomains: {},
66
+ sitemap: {},
67
+ respect_robots: {
68
+ description: "Refuse a start URL robots.txt disallows (403 robots_disallowed). Off by default.",
69
+ },
70
+ },
71
+ defaults: { limit: 200 },
72
+ why: { limit: "the URLs go into the model's context, so 200 rather than the API's 1000" },
73
+ hints: { readOnlyHint: true, openWorldHint: true },
74
+ },
75
+ {
76
+ name: "vision_crawl",
77
+ group: "core",
78
+ title: "Crawl a site",
79
+ description:
80
+ "Crawl a site breadth first from a URL (links and sitemaps, at most 500 pages) and return " +
81
+ "the pages as Markdown. Waits up to wait_s seconds; if the crawl is still running, call again with job_id.",
82
+ op: "visionCreateCrawl",
83
+ query: { wait: { from: "wait_s" } },
84
+ body: {
85
+ url: { required: false, description: "Where to start (omit when passing job_id)." },
86
+ limit: { default: 20 },
87
+ max_depth: {},
88
+ include_paths: {},
89
+ exclude_paths: {},
90
+ crawl_entire_domain: {},
91
+ allow_subdomains: {},
92
+ respect_robots: { description: "Skip pages robots.txt disallows and use its Crawl-delay. Off by default." },
93
+ },
94
+ defaults: { limit: 20, scrape: { formats: ["markdown"] } },
95
+ why: { limit: "every page goes into the model's context, so 20 rather than the API's 100" },
96
+ args: {
97
+ job_id: { type: "string", description: "A crawl_… id from an earlier call: keep waiting or read its pages." },
98
+ wait_s: WAIT_S,
99
+ max_chars_per_page: { type: "integer", minimum: 200, default: 4000, description: "Truncate each page's text." },
100
+ },
101
+ continueWith: { arg: "job_id", op: "visionGetCrawl", pages: "visionListCrawlPages" },
102
+ hints: { readOnlyHint: true, openWorldHint: true },
103
+ },
104
+ {
105
+ name: "vision_act",
106
+ group: "core",
107
+ title: "Drive a browser",
108
+ description:
109
+ "Run browser actions in a real Chrome session in one call (navigate, click, type, key, scroll, select, wait, " +
110
+ "evaluate, screenshot, markdown) and return each action's result. Without session_id a session is created for " +
111
+ "this call and closed after it; keep_session: true keeps it and returns its id for the next call.",
112
+ op: "visionAct",
113
+ path: { session_id: { required: false, description: "A brs_… session from an earlier call." } },
114
+ body: {
115
+ actions: {
116
+ required: false,
117
+ collapse: true,
118
+ description:
119
+ "Actions in order, each {kind, ...}: navigate {url}, click {target}, hover {target}, type {target?, text}, " +
120
+ "key {key}, scroll {target? | to | by}, select {target, value}, wait {ms | for}, evaluate {expression}, " +
121
+ "screenshot {target?, full_page?}, markdown {only_main_content?}. A target is {selector} or {text} or " +
122
+ "{role, name}.",
123
+ },
124
+ continue_on_error: {},
125
+ },
126
+ args: {
127
+ url: { type: "string", description: "Navigate here before the actions." },
128
+ profile: {
129
+ type: "string",
130
+ maxLength: 100,
131
+ description:
132
+ "A profile ID or name to load into the session this call creates (cookies and storage), so the actions " +
133
+ "run signed in. Not with session_id.",
134
+ },
135
+ keep_session: { type: "boolean", default: false, description: "Keep a session this call created open." },
136
+ },
137
+ uses: ["visionCreateSession", "visionCloseSession"],
138
+ hints: { readOnlyHint: false, openWorldHint: true },
139
+ },
140
+ {
141
+ name: "vision_search",
142
+ group: "vision",
143
+ title: "Search the web",
144
+ description:
145
+ "Search the web and return the top results (URL, title, description). With scrape, also return each " +
146
+ "result's page as Markdown. Use it to find pages to read when you have no URL.",
147
+ op: "visionSearch",
148
+ body: {
149
+ query: {},
150
+ limit: {},
151
+ country: {},
152
+ lang: {},
153
+ freshness: {},
154
+ scrape: {
155
+ collapse: true,
156
+ description:
157
+ "Scrape every result with these options, as in vision_scrape (formats, only_main_content, engine, " +
158
+ "max_age_ms, ...); headers, profile, actions and the json format are refused. Omit to get only the links.",
159
+ },
160
+ },
161
+ args: {
162
+ max_chars_per_result: {
163
+ type: "integer",
164
+ minimum: 200,
165
+ default: 4000,
166
+ description: "Truncate each scraped result's text.",
167
+ },
168
+ },
169
+ example: { query: "rust async runtime", limit: 3 },
170
+ hints: { readOnlyHint: true, openWorldHint: true },
171
+ },
172
+ {
173
+ name: "vision_batch",
174
+ group: "vision",
175
+ title: "Scrape many URLs",
176
+ description:
177
+ "Scrape a list of URLs as one batch job and return the pages as Markdown. Waits up to wait_s seconds; if " +
178
+ "the batch is still running, call again with job_id.",
179
+ op: "visionCreateBatch",
180
+ query: { wait: { from: "wait_s" } },
181
+ body: {
182
+ urls: { required: false, description: "The URLs to scrape (omit when passing job_id)." },
183
+ scrape: {
184
+ collapse: true,
185
+ description:
186
+ "Options for every page, as in vision_scrape (formats, only_main_content, engine, max_age_ms, " +
187
+ "respect_robots, ...). Default {formats: ['markdown']}.",
188
+ },
189
+ ignore_invalid_urls: {},
190
+ max_concurrency: {},
191
+ },
192
+ defaults: { scrape: { formats: ["markdown"] } },
193
+ args: {
194
+ job_id: { type: "string", description: "A batch_… id from an earlier call: keep waiting or read its pages." },
195
+ wait_s: WAIT_S,
196
+ max_chars_per_page: { type: "integer", minimum: 200, default: 4000, description: "Truncate each page's text." },
197
+ },
198
+ continueWith: { arg: "job_id", op: "visionGetBatch", pages: "visionListBatchPages" },
199
+ hints: { readOnlyHint: true, openWorldHint: true },
200
+ },
201
+ {
202
+ name: "vision_cancel_batch",
203
+ group: "vision",
204
+ title: "Cancel a batch",
205
+ description: "Cancel a running batch; pages already scraped stay listed (and billed).",
206
+ op: "visionCancelBatch",
207
+ path: { batch_id: {} },
208
+ hints: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
209
+ },
210
+ {
211
+ name: "vision_cancel_crawl",
212
+ group: "vision",
213
+ title: "Cancel a crawl",
214
+ description: "Cancel a running crawl; pages already scraped stay listed (and billed).",
215
+ op: "visionCancelCrawl",
216
+ path: { crawl_id: {} },
217
+ hints: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
218
+ },
219
+ {
220
+ name: "vision_create_session",
221
+ group: "vision",
222
+ title: "Open a browser session",
223
+ description:
224
+ "Open a Chrome session that stays up between vision_act calls (pass its id as session_id), optionally " +
225
+ "signed in from a saved profile. It closes after timeout_s or with vision_close_session.",
226
+ op: "visionCreateSession",
227
+ body: {
228
+ profile: {},
229
+ persist_profile: {},
230
+ viewport: { collapse: true },
231
+ locale: {},
232
+ timezone: {},
233
+ timeout_s: {},
234
+ block_ads: {},
235
+ block_resources: {},
236
+ metadata: { collapse: true, description: "Up to 16 string key-value pairs." },
237
+ },
238
+ hints: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
239
+ },
240
+ {
241
+ name: "vision_list_sessions",
242
+ group: "vision",
243
+ title: "List browser sessions",
244
+ description: "List this project's browser sessions (status filter, cursor paging).",
245
+ op: "visionListSessions",
246
+ query: { status: {}, limit: {}, cursor: {} },
247
+ hints: { readOnlyHint: true, openWorldHint: false },
248
+ },
249
+ {
250
+ name: "vision_get_session",
251
+ group: "vision",
252
+ title: "Get a browser session",
253
+ description: "Get a browser session's status, open pages, profile, usage and expiry.",
254
+ op: "visionGetSession",
255
+ path: { session_id: {} },
256
+ hints: { readOnlyHint: true, openWorldHint: false },
257
+ },
258
+ {
259
+ name: "vision_close_session",
260
+ group: "vision",
261
+ title: "Close a browser session",
262
+ description: "Close a browser session (and save its profile when it was opened with persist_profile).",
263
+ op: "visionCloseSession",
264
+ path: { session_id: {} },
265
+ hints: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
266
+ },
267
+ {
268
+ name: "vision_save_profile",
269
+ group: "vision",
270
+ title: "Save a session as a profile",
271
+ description:
272
+ "Save a session's cookies and storage (after signing in with vision_act) as a named profile that later " +
273
+ "scrapes and sessions can load; the state itself never passes through this conversation.",
274
+ op: "visionSaveSessionProfile",
275
+ path: { session_id: {} },
276
+ body: { name: {}, overwrite: {} },
277
+ hints: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
278
+ },
279
+ {
280
+ name: "vision_list_profiles",
281
+ group: "vision",
282
+ title: "List browser profiles",
283
+ description: "List saved browser profiles (names, domains, expiry; never their cookies).",
284
+ op: "visionListProfiles",
285
+ query: { limit: {}, cursor: {} },
286
+ hints: { readOnlyHint: true, openWorldHint: false },
287
+ },
288
+ {
289
+ name: "vision_get_profile",
290
+ group: "vision",
291
+ title: "Get a browser profile",
292
+ description: "Get a saved profile's name, domains, expiry and metadata (never its cookies).",
293
+ op: "visionGetProfile",
294
+ path: { profile_id: {} },
295
+ hints: { readOnlyHint: true, openWorldHint: false },
296
+ },
297
+ {
298
+ name: "vision_update_profile",
299
+ group: "vision",
300
+ title: "Update a browser profile",
301
+ description: "Rename a saved profile or change its domains, expiry or metadata (not its cookies).",
302
+ op: "visionUpdateProfile",
303
+ path: { profile_id: {} },
304
+ body: { name: {}, domains: {}, expires_at: {}, metadata: { collapse: true } },
305
+ hints: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
306
+ },
307
+ {
308
+ name: "vision_delete_profile",
309
+ group: "vision",
310
+ title: "Delete a browser profile",
311
+ description: "Delete a saved profile and its stored cookies and storage.",
312
+ op: "visionDeleteProfile",
313
+ path: { profile_id: {} },
314
+ hints: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
315
+ },
316
+ ];
@@ -0,0 +1,92 @@
1
+ // The B3OS MCP tool table: the one definition both MCP servers serve (ARCHITECTURE §5.5, research A11). The stdio
2
+ // server in this package and the edge's https://beta-api.b3os.org/mcp list and run exactly these tools.
3
+ //
4
+ // Each entry names one API operation (`op`, an operationId in packages/spec/dist/openapi.json). Tool arguments are
5
+ // the operation's own path parameters and JSON body fields, under the same names and with the same nesting, plus
6
+ // a few arguments the tool itself consumes (`args`: `job_id`, `wait_s`, `max_chars`, ...). scripts/gen-table.mjs
7
+ // copies each exposed field's schema from the spec (refs inlined, depth capped, long descriptions shortened), so the
8
+ // argument schemas cannot drift from the API, and writes src/table.gen.ts and table/table.json. What a tool does
9
+ // with the response (Markdown first, images, waiting on jobs) is src/table.ts, shared by both servers.
10
+ //
11
+ // This file composes the table (plan 1.2): core.mjs (platform-dx) holds the server instructions, the core group in
12
+ // tools/list order (CORE) and the order of the product modules (PRODUCTS); tools/<product>.mjs, owned by each
13
+ // product, defines that product's tools. TOOLS is the core tools in CORE order, then every other tool, product by
14
+ // product in PRODUCTS order and in file order within a product. scripts/gen-table.mjs imports it from here.
15
+ //
16
+ // Field options: `{}` copies the spec; `description` replaces the spec's; `required: true` makes it required in
17
+ // the tool even when the API has a default; `default` documents the value the tool sends when it is absent (a
18
+ // default, here or in a tool's `defaults`, that differs from the API's needs its reason in the tool's `why`);
19
+ // `ahead` (with an authored `schema`) names a field a workstream has added to its spec on its branch but that this
20
+ // branch's spec does not have yet: the authored schema is used, and gen-table.mjs lists such fields.
21
+ // `description: null` with `pinned` (why, and until when) leaves the spec's description out of a body field, so a
22
+ // tool's schema stays as a benchmark suite pinned it (bench/loop/v2/suite.json tools.sha256; test/pinned.test.ts).
23
+ // `example` (optional, per tool): the arguments test/table.test.ts and test/prism.test.ts call the tool with when
24
+ // they hold no sample for it, so a product adds a tool with its test case in its own file; gen-table.mjs checks it
25
+ // against the tool's inputSchema. table/requests.json (the recorded requests) is a shared snapshot: refresh it
26
+ // with `pnpm -C packages/mcp exec vitest run test/table.test.ts -u`.
27
+ // Groups: `core` is always listed (at most 15 tools, §5.5); the other groups are opt-in toolsets
28
+ // (`b3os-mcp --toolsets routines,infer`, `/mcp?toolsets=...`).
29
+
30
+ import { CORE, CORE_BUDGET, INSTRUCTIONS, MAX_DESCRIPTION_CHARS, PRODUCTS, RESULT_SIZE_CHARS } from "./core.mjs";
31
+ import { TOOLS as actions } from "./tools/actions.mjs";
32
+ import { TOOLS as infer } from "./tools/infer.mjs";
33
+ import { TOOLS as platform } from "./tools/platform.mjs";
34
+ import { TOOLS as render } from "./tools/render.mjs";
35
+ import { TOOLS as routines } from "./tools/routines.mjs";
36
+ import { TOOLS as sandboxes } from "./tools/sandboxes.mjs";
37
+ import { TOOLS as vision } from "./tools/vision.mjs";
38
+
39
+ export { INSTRUCTIONS, MAX_DESCRIPTION_CHARS, RESULT_SIZE_CHARS };
40
+
41
+ /** @type {Record<string, import("../scripts/gen-table.mjs").ToolSource[]>} */
42
+ export const MODULES = { actions, infer, platform, render, routines, sandboxes, vision };
43
+
44
+ /**
45
+ * Compose the table from the core list, the product order and the product modules. Every refusal names the file to
46
+ * fix (W3-0b-3): a CORE longer than the budget, a module PRODUCTS does not name (its tools would be dropped), a
47
+ * PRODUCTS entry with no module, one tool name in two modules, a `group: "core"` tool CORE does not list, or a CORE
48
+ * entry no module defines as a core tool. Returns the tools in table order and each tool's source file.
49
+ */
50
+ export function compose({ core = CORE, products = PRODUCTS, modules = MODULES, budget = CORE_BUDGET } = {}) {
51
+ const file = (p) => `table/tools/${p}.mjs`;
52
+ if (core.length > budget)
53
+ throw new Error(
54
+ `table/core.mjs: CORE lists ${core.length} tools; the core group holds at most ${budget} (CORE_BUDGET, ARCHITECTURE §5.5)`,
55
+ );
56
+ const unlisted = Object.keys(modules).filter((p) => !products.includes(p));
57
+ if (unlisted.length)
58
+ throw new Error(
59
+ `${file(unlisted[0])}: imported in table/tools.mjs MODULES but table/core.mjs PRODUCTS does not name ${unlisted[0]}, so its tools would be left out`,
60
+ );
61
+ const missing = products.filter((p) => !modules[p]);
62
+ if (missing.length)
63
+ throw new Error(`table/tools.mjs: PRODUCTS names ${missing.join(", ")} with no tools/<product>.mjs import`);
64
+ const byName = new Map();
65
+ for (const p of products)
66
+ for (const tool of modules[p]) {
67
+ if (byName.has(tool.name))
68
+ throw new Error(`${file(p)}: tool ${tool.name} is also defined in ${file(byName.get(tool.name).product)}`);
69
+ byName.set(tool.name, { tool, product: p });
70
+ }
71
+ for (const [name, { tool, product }] of byName)
72
+ if (tool.group === "core" && !core.includes(name))
73
+ throw new Error(`${file(product)}: ${name} has group core but table/core.mjs CORE does not list it`);
74
+ const coreTools = core.map((name) => {
75
+ const hit = byName.get(name);
76
+ if (!hit) throw new Error(`table/core.mjs: CORE lists ${name}, which no tools/<product>.mjs defines`);
77
+ if (hit.tool.group !== "core")
78
+ throw new Error(`${file(hit.product)}: ${name} is in table/core.mjs CORE but has group ${hit.tool.group}`);
79
+ return hit.tool;
80
+ });
81
+ const tools = [...coreTools, ...products.flatMap((p) => modules[p].filter((t) => t.group !== "core"))];
82
+ const sources = Object.fromEntries([...byName].map(([name, { product }]) => [name, file(product)]));
83
+ return { tools, sources };
84
+ }
85
+
86
+ const composed = compose();
87
+
88
+ /** @type {import("../scripts/gen-table.mjs").ToolSource[]} */
89
+ export const TOOLS = composed.tools;
90
+
91
+ /** Each tool's source file (`table/tools/<product>.mjs`), for the generator's messages. */
92
+ export const SOURCES = composed.sources;