@burdenoff/mcp-libs 2026.1101.7 → 2026.1106.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.
@@ -1,15 +1,23 @@
1
1
  'use strict';
2
2
 
3
+ var zod = require('zod');
3
4
  require('graphql-request');
4
5
  require('cross-fetch');
5
6
  require('@modelcontextprotocol/sdk/server/mcp.js');
6
7
  require('@modelcontextprotocol/sdk/types.js');
7
8
  require('crypto');
8
- require('zod');
9
9
 
10
- // src/core/auth/store.ts
10
+ // src/modules/sandbox/tools.ts
11
11
 
12
12
  // src/core/errors.ts
13
+ var McpUserError = class extends Error {
14
+ hint;
15
+ constructor(message, opts) {
16
+ super(message);
17
+ this.name = "McpUserError";
18
+ this.hint = opts?.hint;
19
+ }
20
+ };
13
21
  var McpInternalError = class extends Error {
14
22
  cause;
15
23
  constructor(message, cause) {
@@ -38,96 +46,984 @@ function mcpToolName(productName, ...parts) {
38
46
  }
39
47
 
40
48
  // src/core/result.ts
49
+ function jsonResult(data, structured) {
50
+ const result = {
51
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
52
+ };
53
+ return result;
54
+ }
41
55
  function errorResult(message, hint) {
42
56
  const text = hint ? `${message}
43
57
 
44
58
  Hint: ${hint}` : message;
45
59
  return { content: [{ type: "text", text }], isError: true };
46
60
  }
61
+ var SANDBOX_FIELDS = `
62
+ id name description template mode status
63
+ crdName podName namespace runtimeClass
64
+ containers { name image ports { containerPort name protocol } env { name value } command args resources { requestsCpu requestsMemory limitsCpu limitsMemory } }
65
+ containerStatuses { name ready port restartCount }
66
+ resources { cpuRequest cpuLimit memoryRequest memoryLimit }
67
+ storage { mode sizeGi mountPath retainOnDelete }
68
+ network { exposeService internalUrl containerUrls serviceName }
69
+ ttlSeconds expiresAt metadata errorMessage
70
+ workspaceId createdBy createdAt updatedAt stoppedAt
71
+ `;
72
+ var LIST_SANDBOXES = `
73
+ query ListSandboxes($filter: SandboxFilterInput, $pagination: SandboxPaginationInput, $context: ContextInput!) {
74
+ listSandboxes(filter: $filter, pagination: $pagination, context: $context) {
75
+ items { ${SANDBOX_FIELDS} }
76
+ total hasMore
77
+ }
78
+ }
79
+ `;
80
+ var GET_SANDBOX = `
81
+ query GetSandbox($id: ID!, $context: ContextInput!) {
82
+ getSandbox(id: $id, context: $context) { ${SANDBOX_FIELDS} }
83
+ }
84
+ `;
85
+ var CREATE_SANDBOX = `
86
+ mutation CreateSandbox($input: CreateSandboxInput!) {
87
+ createSandbox(input: $input) { ${SANDBOX_FIELDS} }
88
+ }
89
+ `;
90
+ var DELETE_SANDBOX = `
91
+ mutation DeleteSandbox($id: ID!, $context: ContextInput!) {
92
+ deleteSandbox(id: $id, context: $context)
93
+ }
94
+ `;
95
+ var STOP_SANDBOX = `
96
+ mutation StopSandbox($id: ID!, $context: ContextInput!) {
97
+ stopSandbox(id: $id, context: $context) { ${SANDBOX_FIELDS} }
98
+ }
99
+ `;
100
+ var EXTEND_SANDBOX_TTL = `
101
+ mutation ExtendSandboxTTL($id: ID!, $additionalSeconds: Int!, $context: ContextInput!) {
102
+ extendSandboxTTL(id: $id, additionalSeconds: $additionalSeconds, context: $context) { ${SANDBOX_FIELDS} }
103
+ }
104
+ `;
105
+ var SANDBOX_TEMPLATE_FIELDS = `
106
+ id name description template isDefault ttlSeconds
107
+ containers { name image }
108
+ resources { cpuRequest cpuLimit memoryRequest memoryLimit }
109
+ storage { mode sizeGi mountPath retainOnDelete }
110
+ config metadata allowedImages
111
+ workspaceId createdBy createdAt updatedAt
112
+ `;
113
+ var LIST_SANDBOX_TEMPLATES = `
114
+ query ListSandboxTemplates($context: ContextInput!, $template: SandboxTemplate, $pagination: SandboxPaginationInput) {
115
+ listSandboxTemplates(context: $context, template: $template, pagination: $pagination) {
116
+ items { ${SANDBOX_TEMPLATE_FIELDS} } total hasMore
117
+ }
118
+ }
119
+ `;
120
+ var GET_SANDBOX_TEMPLATE = `
121
+ query GetSandboxTemplate($context: ContextInput!, $id: ID!) {
122
+ getSandboxTemplate(context: $context, id: $id) { ${SANDBOX_TEMPLATE_FIELDS} }
123
+ }
124
+ `;
125
+ var CREATE_SANDBOX_TEMPLATE = `
126
+ mutation CreateSandboxTemplate($input: CreateSandboxTemplateInput!) {
127
+ createSandboxTemplate(input: $input) { ${SANDBOX_TEMPLATE_FIELDS} }
128
+ }
129
+ `;
130
+ var UPDATE_SANDBOX_TEMPLATE = `
131
+ mutation UpdateSandboxTemplate($input: UpdateSandboxTemplateInput!) {
132
+ updateSandboxTemplate(input: $input) { ${SANDBOX_TEMPLATE_FIELDS} }
133
+ }
134
+ `;
135
+ var DELETE_SANDBOX_TEMPLATE = `
136
+ mutation DeleteSandboxTemplate($context: ContextInput!, $id: ID!) {
137
+ deleteSandboxTemplate(context: $context, id: $id)
138
+ }
139
+ `;
140
+ var AVAILABLE_SANDBOX_TAGS = `
141
+ query AvailableSandboxTags($query: String, $limit: Int) {
142
+ availableSandboxTags(query: $query, limit: $limit) { id key label color }
143
+ }
144
+ `;
145
+ var GET_SANDBOX_TAGS = `
146
+ query GetSandboxTags($input: GetSandboxTagsInput!) {
147
+ getSandboxTags(input: $input) {
148
+ id entityId entityType tagId source assignedAt assignedBy
149
+ }
150
+ }
151
+ `;
152
+ var CREATE_SANDBOX_TAG = `
153
+ mutation CreateSandboxTag($input: CreateSandboxTagInput!) {
154
+ createSandboxTag(input: $input) { id key label color }
155
+ }
156
+ `;
157
+ var TAG_SANDBOX = `
158
+ mutation TagSandbox($input: TagSandboxInput!) {
159
+ tagSandbox(input: $input) {
160
+ id entityId tagId source assignedAt
161
+ }
162
+ }
163
+ `;
164
+ var UNTAG_SANDBOX = `
165
+ mutation UntagSandbox($input: UntagSandboxInput!) {
166
+ untagSandbox(input: $input)
167
+ }
168
+ `;
169
+ var REPLACE_SANDBOX_TAGS = `
170
+ mutation ReplaceSandboxTags($input: ReplaceSandboxTagsInput!) {
171
+ replaceSandboxTags(input: $input) {
172
+ id entityId tagId source assignedAt
173
+ }
174
+ }
175
+ `;
176
+ var LIST_ALL_SANDBOXES = `
177
+ query ListAllSandboxes($context: ContextInput!, $filter: SandboxFilterInput, $pagination: SandboxPaginationInput) {
178
+ listAllSandboxes(context: $context, filter: $filter, pagination: $pagination) {
179
+ items { ${SANDBOX_FIELDS} } total hasMore
180
+ }
181
+ }
182
+ `;
183
+ var LIST_SANDBOX_NODES = `
184
+ query ListSandboxNodes($context: ContextInput!) {
185
+ listSandboxNodes(context: $context) {
186
+ name status allocatableCpu allocatableMemory sandboxPodCount labels
187
+ }
188
+ }
189
+ `;
190
+ var GET_ACTIVE_SANDBOXES = `
191
+ query GetActiveSandboxes($context: ContextInput!) {
192
+ getActiveSandboxes(context: $context) { ${SANDBOX_FIELDS} }
193
+ }
194
+ `;
195
+ var GET_RECENT_SANDBOX_ACTIVITY = `
196
+ query GetRecentSandboxActivity($context: ContextInput!, $limit: Int) {
197
+ getRecentSandboxActivity(context: $context, limit: $limit) {
198
+ items { id action actorId status sandboxName sandboxId createdAt }
199
+ total
200
+ }
201
+ }
202
+ `;
203
+ var GET_SANDBOX_STATS = `
204
+ query GetSandboxStats($context: ContextInput!) {
205
+ getSandboxStats(context: $context) {
206
+ activeSandboxes activeUserSandboxes activeInternalSandboxes
207
+ totalCreated totalDeleted totalUserCreated totalInternalCreated
208
+ runningNow provisioningNow stoppedNow expiredCount failedCount
209
+ totalCpuUsed totalMemoryUsed
210
+ }
211
+ }
212
+ `;
213
+ var GET_SANDBOX_LOGS = `
214
+ query GetSandboxLogs($context: ContextInput!, $id: ID!, $containerName: String!, $tailLines: Int) {
215
+ getSandboxLogs(context: $context, id: $id, containerName: $containerName, tailLines: $tailLines)
216
+ }
217
+ `;
218
+ var GET_SANDBOX_CONFIG = `
219
+ query GetSandboxConfig($context: ContextInput!) {
220
+ getSandboxConfig(context: $context) {
221
+ id defaultTtlSeconds maxTtlSeconds allowedTemplates
222
+ maxConcurrentPerUser maxConcurrentPerWorkspace
223
+ defaultCpuRequest defaultCpuLimit defaultMemoryRequest defaultMemoryLimit
224
+ workspaceId updatedAt
225
+ }
226
+ }
227
+ `;
228
+ var UPDATE_SANDBOX_CONFIG = `
229
+ mutation UpdateSandboxConfig($input: UpdateSandboxConfigInput!) {
230
+ updateSandboxConfig(input: $input) {
231
+ id defaultTtlSeconds maxTtlSeconds allowedTemplates
232
+ maxConcurrentPerUser maxConcurrentPerWorkspace
233
+ defaultCpuRequest defaultCpuLimit defaultMemoryRequest defaultMemoryLimit
234
+ workspaceId updatedAt
235
+ }
236
+ }
237
+ `;
238
+ var GET_SANDBOX_ARTIFACT_BYTES = `
239
+ query GetSandboxArtifactBytes($input: SandboxArtifactBytesInput!) {
240
+ getSandboxArtifactBytes(input: $input) { filename mimeType size contentBase64 }
241
+ }
242
+ `;
243
+ var PROXY_SANDBOX_REQUEST = `
244
+ mutation ProxySandboxRequest($input: ProxySandboxRequestInput!) {
245
+ proxySandboxRequest(input: $input) { status body }
246
+ }
247
+ `;
47
248
 
48
249
  // src/modules/sandbox/tools.ts
49
- function stubbedTool(server, toolName, title, description, featureNote, inputSchema, altSuggestions) {
250
+ var NO_WORKSPACE = "No workspace selected. Call auth_select_workspace first: every sandbox operation is scoped to the active workspace.";
251
+ var INPUT_CONTEXT_OPERATIONS = [
252
+ CREATE_SANDBOX,
253
+ CREATE_SANDBOX_TEMPLATE,
254
+ UPDATE_SANDBOX_TEMPLATE,
255
+ UPDATE_SANDBOX_CONFIG,
256
+ PROXY_SANDBOX_REQUEST
257
+ ];
258
+ function withSandboxContext(document, variables, workspaceId) {
259
+ const declaresContext = document.includes("$context");
260
+ const inputContext = INPUT_CONTEXT_OPERATIONS.includes(document);
261
+ if (!declaresContext && !inputContext) return variables;
262
+ if (!workspaceId) throw new McpUserError(NO_WORKSPACE);
263
+ const context = { workspaceId };
264
+ if (declaresContext) return { ...variables, context };
265
+ const input = variables.input ?? {};
266
+ return { ...variables, input: { ...input, context } };
267
+ }
268
+ function registerSandboxTools(server, ctx, track) {
269
+ const wsRequest = (document, variables = {}) => ctx.gql.workspace.request(
270
+ document,
271
+ withSandboxContext(document, variables, ctx.auth.read()?.workspaceId)
272
+ );
50
273
  server.registerTool(
51
- toolName,
274
+ track(mcpToolName(ctx.productName, "sandbox_list")),
52
275
  {
53
- title,
54
- description: `${description} [STUB]`,
55
- inputSchema
276
+ title: "List Sandboxes",
277
+ description: "List Kubernetes-native sandboxes with optional filters and pagination.",
278
+ inputSchema: {
279
+ status: zod.z.string().optional().describe(
280
+ "Filter by status (PENDING, PROVISIONING, RUNNING, STOPPING, STOPPED, EXPIRED, FAILED)"
281
+ ),
282
+ template: zod.z.string().optional().describe(
283
+ "Filter by template (VIBECONTROLS, AI_BUILDER, WORKFLOW_MULTI_NODE, MISC_SHELL, CUSTOM)"
284
+ ),
285
+ limit: zod.z.number().optional().describe("Max results"),
286
+ offset: zod.z.number().optional().describe("Skip results")
287
+ }
56
288
  },
57
- async () => errorResult(
58
- `[stubbed] ${featureNote} Use ${altSuggestions.join(", ")} instead. The tool remains registered so callers receive a meaningful response instead of a schema-validation error.`
59
- )
289
+ async ({ status, template, limit, offset }) => {
290
+ try {
291
+ const filter = {};
292
+ if (status !== void 0) filter.status = status;
293
+ if (template !== void 0) filter.template = template;
294
+ const pagination = {};
295
+ if (limit !== void 0) pagination.limit = limit;
296
+ if (offset !== void 0) pagination.offset = offset;
297
+ const data = await wsRequest(LIST_SANDBOXES, {
298
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
299
+ pagination: Object.keys(pagination).length > 0 ? pagination : void 0
300
+ });
301
+ return jsonResult(data.listSandboxes);
302
+ } catch (error) {
303
+ ctx.logger.error("sandbox_list failed", { error });
304
+ return errorResult(
305
+ `Failed to list sandboxes: ${error instanceof Error ? error.message : String(error)}`
306
+ );
307
+ }
308
+ }
309
+ );
310
+ server.registerTool(
311
+ track(mcpToolName(ctx.productName, "sandbox_get")),
312
+ {
313
+ title: "Get Sandbox",
314
+ description: "Get a sandbox by its ID.",
315
+ inputSchema: { id: zod.z.string().describe("Sandbox ID") }
316
+ },
317
+ async ({ id }) => {
318
+ try {
319
+ const data = await wsRequest(GET_SANDBOX, { id });
320
+ return jsonResult(data.getSandbox);
321
+ } catch (error) {
322
+ ctx.logger.error("sandbox_get failed", { error });
323
+ return errorResult(
324
+ `Failed to get sandbox: ${error instanceof Error ? error.message : String(error)}`
325
+ );
326
+ }
327
+ }
328
+ );
329
+ server.registerTool(
330
+ track(mcpToolName(ctx.productName, "sandbox_create")),
331
+ {
332
+ title: "Create Sandbox",
333
+ description: "Create a new Kubernetes-native sandbox environment with Kata Containers isolation.",
334
+ inputSchema: {
335
+ name: zod.z.string().describe("Sandbox name"),
336
+ template: zod.z.enum(["VIBECONTROLS", "AI_BUILDER", "WORKFLOW_MULTI_NODE", "MISC_SHELL", "CUSTOM"]).describe("Sandbox template type"),
337
+ mode: zod.z.enum(["DEPLOYMENT", "JOB"]).optional().describe("Run mode: DEPLOYMENT (long-running) or JOB (run-to-completion)"),
338
+ containers: zod.z.array(
339
+ zod.z.object({
340
+ name: zod.z.string().describe("Container name"),
341
+ image: zod.z.string().describe("Container image"),
342
+ ports: zod.z.array(
343
+ zod.z.object({
344
+ containerPort: zod.z.number().describe("Container port"),
345
+ name: zod.z.string().optional().describe("Port name"),
346
+ protocol: zod.z.string().optional().describe("Protocol (TCP, UDP)")
347
+ })
348
+ ).optional().describe("Exposed ports"),
349
+ env: zod.z.array(
350
+ zod.z.object({
351
+ name: zod.z.string().describe("Env var name"),
352
+ value: zod.z.string().describe("Env var value")
353
+ })
354
+ ).optional().describe("Environment variables"),
355
+ command: zod.z.array(zod.z.string()).optional().describe("Container entrypoint command"),
356
+ args: zod.z.array(zod.z.string()).optional().describe("Container arguments")
357
+ })
358
+ ).optional().describe("Container specifications (uses template defaults if omitted)"),
359
+ ttlSeconds: zod.z.number().optional().describe("Time-to-live in seconds"),
360
+ resources: zod.z.object({
361
+ cpuRequest: zod.z.string().optional(),
362
+ cpuLimit: zod.z.string().optional(),
363
+ memoryRequest: zod.z.string().optional(),
364
+ memoryLimit: zod.z.string().optional()
365
+ }).optional().describe("Resource requests/limits"),
366
+ description: zod.z.string().optional().describe("Sandbox description"),
367
+ templateId: zod.z.string().optional().describe("Sandbox template config ID to use")
368
+ }
369
+ },
370
+ async ({
371
+ name,
372
+ template,
373
+ mode,
374
+ containers,
375
+ ttlSeconds,
376
+ resources,
377
+ description,
378
+ templateId
379
+ }) => {
380
+ try {
381
+ const input = { name, template };
382
+ if (mode !== void 0) input.mode = mode;
383
+ if (containers !== void 0) input.containers = containers;
384
+ if (ttlSeconds !== void 0) input.ttlSeconds = ttlSeconds;
385
+ if (resources !== void 0) input.resources = resources;
386
+ if (description !== void 0) input.description = description;
387
+ if (templateId !== void 0) input.templateId = templateId;
388
+ const data = await wsRequest(CREATE_SANDBOX, {
389
+ input
390
+ });
391
+ return jsonResult(data.createSandbox);
392
+ } catch (error) {
393
+ ctx.logger.error("sandbox_create failed", { error });
394
+ return errorResult(
395
+ `Failed to create sandbox: ${error instanceof Error ? error.message : String(error)}`
396
+ );
397
+ }
398
+ }
399
+ );
400
+ server.registerTool(
401
+ track(mcpToolName(ctx.productName, "sandbox_delete")),
402
+ {
403
+ title: "Delete Sandbox",
404
+ description: "Delete a sandbox and its Kubernetes resources.",
405
+ inputSchema: { id: zod.z.string().describe("Sandbox ID") }
406
+ },
407
+ async ({ id }) => {
408
+ try {
409
+ const data = await wsRequest(DELETE_SANDBOX, {
410
+ id
411
+ });
412
+ return jsonResult({ deleted: data.deleteSandbox, sandboxId: id });
413
+ } catch (error) {
414
+ ctx.logger.error("sandbox_delete failed", { error });
415
+ return errorResult(
416
+ `Failed to delete sandbox: ${error instanceof Error ? error.message : String(error)}`
417
+ );
418
+ }
419
+ }
420
+ );
421
+ server.registerTool(
422
+ track(mcpToolName(ctx.productName, "sandbox_stop")),
423
+ {
424
+ title: "Stop Sandbox",
425
+ description: "Stop a running sandbox.",
426
+ inputSchema: { id: zod.z.string().describe("Sandbox ID") }
427
+ },
428
+ async ({ id }) => {
429
+ try {
430
+ const data = await wsRequest(STOP_SANDBOX, {
431
+ id
432
+ });
433
+ return jsonResult(data.stopSandbox);
434
+ } catch (error) {
435
+ ctx.logger.error("sandbox_stop failed", { error });
436
+ return errorResult(
437
+ `Failed to stop sandbox: ${error instanceof Error ? error.message : String(error)}`
438
+ );
439
+ }
440
+ }
441
+ );
442
+ server.registerTool(
443
+ track(mcpToolName(ctx.productName, "sandbox_extend")),
444
+ {
445
+ title: "Extend Sandbox TTL",
446
+ description: "Extend the time-to-live of a sandbox.",
447
+ inputSchema: {
448
+ id: zod.z.string().describe("Sandbox ID"),
449
+ additionalSeconds: zod.z.number().describe("Number of seconds to add to the TTL")
450
+ }
451
+ },
452
+ async ({ id, additionalSeconds }) => {
453
+ try {
454
+ const data = await wsRequest(EXTEND_SANDBOX_TTL, {
455
+ id,
456
+ additionalSeconds
457
+ });
458
+ return jsonResult(data.extendSandboxTTL);
459
+ } catch (error) {
460
+ ctx.logger.error("sandbox_extend failed", { error });
461
+ return errorResult(
462
+ `Failed to extend sandbox TTL: ${error instanceof Error ? error.message : String(error)}`
463
+ );
464
+ }
465
+ }
466
+ );
467
+ server.registerTool(
468
+ track(mcpToolName(ctx.productName, "sandbox_templates_list")),
469
+ {
470
+ title: "List Sandbox Templates",
471
+ description: "List sandbox template configurations available in this workspace.",
472
+ inputSchema: {
473
+ template: zod.z.string().optional().describe("Filter by template kind"),
474
+ limit: zod.z.number().optional(),
475
+ offset: zod.z.number().optional()
476
+ }
477
+ },
478
+ async ({ template, limit, offset }) => {
479
+ try {
480
+ const pagination = {};
481
+ if (limit !== void 0) pagination.limit = limit;
482
+ if (offset !== void 0) pagination.offset = offset;
483
+ const data = await wsRequest(LIST_SANDBOX_TEMPLATES, {
484
+ template,
485
+ pagination: Object.keys(pagination).length > 0 ? pagination : void 0
486
+ });
487
+ return jsonResult(data.listSandboxTemplates);
488
+ } catch (error) {
489
+ ctx.logger.error("sandbox_templates_list failed", { error });
490
+ return errorResult(
491
+ `Failed to list templates: ${error instanceof Error ? error.message : String(error)}`
492
+ );
493
+ }
494
+ }
495
+ );
496
+ server.registerTool(
497
+ track(mcpToolName(ctx.productName, "sandbox_templates_get")),
498
+ {
499
+ title: "Get Sandbox Template",
500
+ description: "Get a sandbox template by ID.",
501
+ inputSchema: { id: zod.z.string().describe("Template ID") }
502
+ },
503
+ async ({ id }) => {
504
+ try {
505
+ const data = await wsRequest(GET_SANDBOX_TEMPLATE, { id });
506
+ return jsonResult(data.getSandboxTemplate);
507
+ } catch (error) {
508
+ ctx.logger.error("sandbox_templates_get failed", { error });
509
+ return errorResult(
510
+ `Failed to get template: ${error instanceof Error ? error.message : String(error)}`
511
+ );
512
+ }
513
+ }
514
+ );
515
+ server.registerTool(
516
+ track(mcpToolName(ctx.productName, "sandbox_templates_create")),
517
+ {
518
+ title: "Create Sandbox Template",
519
+ description: "Create a new sandbox template configuration.",
520
+ inputSchema: {
521
+ name: zod.z.string(),
522
+ template: zod.z.enum([
523
+ "VIBECONTROLS",
524
+ "AI_BUILDER",
525
+ "WORKFLOW_MULTI_NODE",
526
+ "MISC_SHELL",
527
+ "CUSTOM",
528
+ "DOCS_BUILDER"
529
+ ]),
530
+ description: zod.z.string().optional(),
531
+ isDefault: zod.z.boolean().optional(),
532
+ ttlSeconds: zod.z.number().optional()
533
+ }
534
+ },
535
+ async ({ name, template, description, isDefault, ttlSeconds }) => {
536
+ try {
537
+ const input = { name, template };
538
+ if (description !== void 0) input.description = description;
539
+ if (isDefault !== void 0) input.isDefault = isDefault;
540
+ if (ttlSeconds !== void 0) input.ttlSeconds = ttlSeconds;
541
+ const data = await wsRequest(CREATE_SANDBOX_TEMPLATE, {
542
+ input
543
+ });
544
+ return jsonResult(data.createSandboxTemplate);
545
+ } catch (error) {
546
+ ctx.logger.error("sandbox_templates_create failed", { error });
547
+ return errorResult(
548
+ `Failed to create template: ${error instanceof Error ? error.message : String(error)}`
549
+ );
550
+ }
551
+ }
552
+ );
553
+ server.registerTool(
554
+ track(mcpToolName(ctx.productName, "sandbox_templates_update")),
555
+ {
556
+ title: "Update Sandbox Template",
557
+ description: "Update a sandbox template configuration.",
558
+ inputSchema: {
559
+ id: zod.z.string(),
560
+ name: zod.z.string().optional(),
561
+ description: zod.z.string().optional(),
562
+ isDefault: zod.z.boolean().optional(),
563
+ ttlSeconds: zod.z.number().optional()
564
+ }
565
+ },
566
+ async ({ id, name, description, isDefault, ttlSeconds }) => {
567
+ try {
568
+ const input = { id };
569
+ if (name !== void 0) input.name = name;
570
+ if (description !== void 0) input.description = description;
571
+ if (isDefault !== void 0) input.isDefault = isDefault;
572
+ if (ttlSeconds !== void 0) input.ttlSeconds = ttlSeconds;
573
+ const data = await wsRequest(UPDATE_SANDBOX_TEMPLATE, {
574
+ input
575
+ });
576
+ return jsonResult(data.updateSandboxTemplate);
577
+ } catch (error) {
578
+ ctx.logger.error("sandbox_templates_update failed", { error });
579
+ return errorResult(
580
+ `Failed to update template: ${error instanceof Error ? error.message : String(error)}`
581
+ );
582
+ }
583
+ }
584
+ );
585
+ server.registerTool(
586
+ track(mcpToolName(ctx.productName, "sandbox_templates_delete")),
587
+ {
588
+ title: "Delete Sandbox Template",
589
+ description: "Delete a sandbox template configuration.",
590
+ inputSchema: { id: zod.z.string() }
591
+ },
592
+ async ({ id }) => {
593
+ try {
594
+ const data = await wsRequest(DELETE_SANDBOX_TEMPLATE, {
595
+ id
596
+ });
597
+ return jsonResult({ deleted: data.deleteSandboxTemplate, templateId: id });
598
+ } catch (error) {
599
+ ctx.logger.error("sandbox_templates_delete failed", { error });
600
+ return errorResult(
601
+ `Failed to delete template: ${error instanceof Error ? error.message : String(error)}`
602
+ );
603
+ }
604
+ }
605
+ );
606
+ server.registerTool(
607
+ track(mcpToolName(ctx.productName, "sandbox_tags_list")),
608
+ {
609
+ title: "List Available Sandbox Tags",
610
+ description: "List available sandbox tags in the workspace.",
611
+ inputSchema: {
612
+ query: zod.z.string().optional(),
613
+ limit: zod.z.number().optional()
614
+ }
615
+ },
616
+ async ({ query, limit }) => {
617
+ try {
618
+ const data = await wsRequest(AVAILABLE_SANDBOX_TAGS, {
619
+ query,
620
+ limit
621
+ });
622
+ return jsonResult(data.availableSandboxTags);
623
+ } catch (error) {
624
+ ctx.logger.error("sandbox_tags_list failed", { error });
625
+ return errorResult(
626
+ `Failed to list tags: ${error instanceof Error ? error.message : String(error)}`
627
+ );
628
+ }
629
+ }
630
+ );
631
+ server.registerTool(
632
+ track(mcpToolName(ctx.productName, "sandbox_tags_get")),
633
+ {
634
+ title: "Get Sandbox Tags",
635
+ description: "Get tag assignments for a sandbox.",
636
+ inputSchema: { sandboxId: zod.z.string() }
637
+ },
638
+ async ({ sandboxId }) => {
639
+ try {
640
+ const data = await wsRequest(GET_SANDBOX_TAGS, {
641
+ input: { sandboxId }
642
+ });
643
+ return jsonResult(data.getSandboxTags);
644
+ } catch (error) {
645
+ ctx.logger.error("sandbox_tags_get failed", { error });
646
+ return errorResult(
647
+ `Failed to get tags: ${error instanceof Error ? error.message : String(error)}`
648
+ );
649
+ }
650
+ }
651
+ );
652
+ server.registerTool(
653
+ track(mcpToolName(ctx.productName, "sandbox_tags_create")),
654
+ {
655
+ title: "Create Sandbox Tag",
656
+ description: "Create a new sandbox tag.",
657
+ inputSchema: {
658
+ label: zod.z.string(),
659
+ color: zod.z.string().optional()
660
+ }
661
+ },
662
+ async ({ label, color }) => {
663
+ try {
664
+ const input = { label };
665
+ if (color !== void 0) input.color = color;
666
+ const data = await wsRequest(CREATE_SANDBOX_TAG, { input });
667
+ return jsonResult(data.createSandboxTag);
668
+ } catch (error) {
669
+ ctx.logger.error("sandbox_tags_create failed", { error });
670
+ return errorResult(
671
+ `Failed to create tag: ${error instanceof Error ? error.message : String(error)}`
672
+ );
673
+ }
674
+ }
675
+ );
676
+ server.registerTool(
677
+ track(mcpToolName(ctx.productName, "sandbox_tags_attach")),
678
+ {
679
+ title: "Attach Tag to Sandbox",
680
+ description: "Attach a tag to a sandbox.",
681
+ inputSchema: {
682
+ sandboxId: zod.z.string(),
683
+ tagId: zod.z.string(),
684
+ source: zod.z.string().optional()
685
+ }
686
+ },
687
+ async ({ sandboxId, tagId, source }) => {
688
+ try {
689
+ const input = { sandboxId, tagId };
690
+ if (source !== void 0) input.source = source;
691
+ const data = await wsRequest(TAG_SANDBOX, {
692
+ input
693
+ });
694
+ return jsonResult(data.tagSandbox);
695
+ } catch (error) {
696
+ ctx.logger.error("sandbox_tags_attach failed", { error });
697
+ return errorResult(
698
+ `Failed to attach tag: ${error instanceof Error ? error.message : String(error)}`
699
+ );
700
+ }
701
+ }
702
+ );
703
+ server.registerTool(
704
+ track(mcpToolName(ctx.productName, "sandbox_tags_detach")),
705
+ {
706
+ title: "Detach Tag from Sandbox",
707
+ description: "Detach a tag from a sandbox.",
708
+ inputSchema: {
709
+ sandboxId: zod.z.string(),
710
+ tagId: zod.z.string()
711
+ }
712
+ },
713
+ async ({ sandboxId, tagId }) => {
714
+ try {
715
+ const data = await wsRequest(UNTAG_SANDBOX, {
716
+ input: { sandboxId, tagId }
717
+ });
718
+ return jsonResult({ detached: data.untagSandbox, sandboxId, tagId });
719
+ } catch (error) {
720
+ ctx.logger.error("sandbox_tags_detach failed", { error });
721
+ return errorResult(
722
+ `Failed to detach tag: ${error instanceof Error ? error.message : String(error)}`
723
+ );
724
+ }
725
+ }
726
+ );
727
+ server.registerTool(
728
+ track(mcpToolName(ctx.productName, "sandbox_tags_replace")),
729
+ {
730
+ title: "Replace Sandbox Tags",
731
+ description: "Replace the full set of tags on a sandbox.",
732
+ inputSchema: {
733
+ sandboxId: zod.z.string(),
734
+ tagIds: zod.z.array(zod.z.string())
735
+ }
736
+ },
737
+ async ({ sandboxId, tagIds }) => {
738
+ try {
739
+ const data = await wsRequest(REPLACE_SANDBOX_TAGS, {
740
+ input: { sandboxId, tagIds }
741
+ });
742
+ return jsonResult(data.replaceSandboxTags);
743
+ } catch (error) {
744
+ ctx.logger.error("sandbox_tags_replace failed", { error });
745
+ return errorResult(
746
+ `Failed to replace tags: ${error instanceof Error ? error.message : String(error)}`
747
+ );
748
+ }
749
+ }
750
+ );
751
+ server.registerTool(
752
+ track(mcpToolName(ctx.productName, "sandbox_admin_list_all")),
753
+ {
754
+ title: "List All Sandboxes (admin)",
755
+ description: "Admin-only list across the entire workspace including internal sandboxes.",
756
+ inputSchema: {
757
+ status: zod.z.string().optional(),
758
+ template: zod.z.string().optional(),
759
+ limit: zod.z.number().optional(),
760
+ offset: zod.z.number().optional()
761
+ }
762
+ },
763
+ async ({ status, template, limit, offset }) => {
764
+ try {
765
+ const filter = {};
766
+ if (status !== void 0) filter.status = status;
767
+ if (template !== void 0) filter.template = template;
768
+ const pagination = {};
769
+ if (limit !== void 0) pagination.limit = limit;
770
+ if (offset !== void 0) pagination.offset = offset;
771
+ const data = await wsRequest(LIST_ALL_SANDBOXES, {
772
+ filter: Object.keys(filter).length > 0 ? filter : void 0,
773
+ pagination: Object.keys(pagination).length > 0 ? pagination : void 0
774
+ });
775
+ return jsonResult(data.listAllSandboxes);
776
+ } catch (error) {
777
+ ctx.logger.error("sandbox_admin_list_all failed", { error });
778
+ return errorResult(
779
+ `Failed to list all sandboxes: ${error instanceof Error ? error.message : String(error)}`
780
+ );
781
+ }
782
+ }
783
+ );
784
+ server.registerTool(
785
+ track(mcpToolName(ctx.productName, "sandbox_admin_nodes_list")),
786
+ {
787
+ title: "List Sandbox Nodes",
788
+ description: "List Kubernetes nodes hosting sandbox workloads with capacity info.",
789
+ inputSchema: {}
790
+ },
791
+ async () => {
792
+ try {
793
+ const data = await wsRequest(LIST_SANDBOX_NODES, {});
794
+ return jsonResult(data.listSandboxNodes);
795
+ } catch (error) {
796
+ ctx.logger.error("sandbox_admin_nodes_list failed", { error });
797
+ return errorResult(
798
+ `Failed to list nodes: ${error instanceof Error ? error.message : String(error)}`
799
+ );
800
+ }
801
+ }
802
+ );
803
+ server.registerTool(
804
+ track(mcpToolName(ctx.productName, "sandbox_admin_active")),
805
+ {
806
+ title: "Get Active Sandboxes",
807
+ description: "Get currently active sandboxes in the workspace.",
808
+ annotations: { readOnlyHint: true, destructiveHint: false },
809
+ inputSchema: {}
810
+ },
811
+ async () => {
812
+ try {
813
+ const data = await wsRequest(GET_ACTIVE_SANDBOXES, {});
814
+ return jsonResult(data.getActiveSandboxes);
815
+ } catch (error) {
816
+ ctx.logger.error("sandbox_admin_active failed", { error });
817
+ return errorResult(
818
+ `Failed to get active sandboxes: ${error instanceof Error ? error.message : String(error)}`
819
+ );
820
+ }
821
+ }
822
+ );
823
+ server.registerTool(
824
+ track(mcpToolName(ctx.productName, "sandbox_admin_activity")),
825
+ {
826
+ title: "Recent Sandbox Activity",
827
+ description: "Get recent sandbox lifecycle activity (create/stop/delete/extend).",
828
+ annotations: { readOnlyHint: true, destructiveHint: false },
829
+ inputSchema: { limit: zod.z.number().optional() }
830
+ },
831
+ async ({ limit }) => {
832
+ try {
833
+ const data = await wsRequest(
834
+ GET_RECENT_SANDBOX_ACTIVITY,
835
+ { limit }
836
+ );
837
+ return jsonResult(data.getRecentSandboxActivity);
838
+ } catch (error) {
839
+ ctx.logger.error("sandbox_admin_activity failed", { error });
840
+ return errorResult(
841
+ `Failed to get activity: ${error instanceof Error ? error.message : String(error)}`
842
+ );
843
+ }
844
+ }
845
+ );
846
+ server.registerTool(
847
+ track(mcpToolName(ctx.productName, "sandbox_admin_stats")),
848
+ {
849
+ title: "Sandbox Stats",
850
+ description: "Get aggregate sandbox usage statistics for the workspace.",
851
+ inputSchema: {}
852
+ },
853
+ async () => {
854
+ try {
855
+ const data = await wsRequest(GET_SANDBOX_STATS, {});
856
+ return jsonResult(data.getSandboxStats);
857
+ } catch (error) {
858
+ ctx.logger.error("sandbox_admin_stats failed", { error });
859
+ return errorResult(
860
+ `Failed to get stats: ${error instanceof Error ? error.message : String(error)}`
861
+ );
862
+ }
863
+ }
864
+ );
865
+ server.registerTool(
866
+ track(mcpToolName(ctx.productName, "sandbox_admin_logs")),
867
+ {
868
+ title: "Get Sandbox Logs",
869
+ description: "Fetch logs for a sandbox container.",
870
+ annotations: { readOnlyHint: true, destructiveHint: false },
871
+ inputSchema: {
872
+ id: zod.z.string(),
873
+ containerName: zod.z.string(),
874
+ tailLines: zod.z.number().optional()
875
+ }
876
+ },
877
+ async ({ id, containerName, tailLines }) => {
878
+ try {
879
+ const data = await wsRequest(GET_SANDBOX_LOGS, {
880
+ id,
881
+ containerName,
882
+ tailLines
883
+ });
884
+ return jsonResult({ logs: data.getSandboxLogs });
885
+ } catch (error) {
886
+ ctx.logger.error("sandbox_admin_logs failed", { error });
887
+ return errorResult(
888
+ `Failed to get logs: ${error instanceof Error ? error.message : String(error)}`
889
+ );
890
+ }
891
+ }
892
+ );
893
+ server.registerTool(
894
+ track(mcpToolName(ctx.productName, "sandbox_admin_config_get")),
895
+ {
896
+ title: "Get Sandbox Config",
897
+ description: "Get the per-workspace sandbox configuration limits.",
898
+ inputSchema: {}
899
+ },
900
+ async () => {
901
+ try {
902
+ const data = await wsRequest(GET_SANDBOX_CONFIG, {});
903
+ return jsonResult(data.getSandboxConfig);
904
+ } catch (error) {
905
+ ctx.logger.error("sandbox_admin_config_get failed", { error });
906
+ return errorResult(
907
+ `Failed to get config: ${error instanceof Error ? error.message : String(error)}`
908
+ );
909
+ }
910
+ }
911
+ );
912
+ server.registerTool(
913
+ track(mcpToolName(ctx.productName, "sandbox_admin_config_set")),
914
+ {
915
+ title: "Update Sandbox Config",
916
+ description: "Update the per-workspace sandbox configuration limits.",
917
+ inputSchema: {
918
+ defaultTtlSeconds: zod.z.number().optional(),
919
+ maxTtlSeconds: zod.z.number().optional(),
920
+ maxConcurrentPerUser: zod.z.number().optional(),
921
+ maxConcurrentPerWorkspace: zod.z.number().optional()
922
+ }
923
+ },
924
+ async ({
925
+ defaultTtlSeconds,
926
+ maxTtlSeconds,
927
+ maxConcurrentPerUser,
928
+ maxConcurrentPerWorkspace
929
+ }) => {
930
+ try {
931
+ const input = {};
932
+ if (defaultTtlSeconds !== void 0) input.defaultTtlSeconds = defaultTtlSeconds;
933
+ if (maxTtlSeconds !== void 0) input.maxTtlSeconds = maxTtlSeconds;
934
+ if (maxConcurrentPerUser !== void 0) input.maxConcurrentPerUser = maxConcurrentPerUser;
935
+ if (maxConcurrentPerWorkspace !== void 0)
936
+ input.maxConcurrentPerWorkspace = maxConcurrentPerWorkspace;
937
+ const data = await wsRequest(UPDATE_SANDBOX_CONFIG, {
938
+ input
939
+ });
940
+ return jsonResult(data.updateSandboxConfig);
941
+ } catch (error) {
942
+ ctx.logger.error("sandbox_admin_config_set failed", { error });
943
+ return errorResult(
944
+ `Failed to update config: ${error instanceof Error ? error.message : String(error)}`
945
+ );
946
+ }
947
+ }
948
+ );
949
+ server.registerTool(
950
+ track(mcpToolName(ctx.productName, "sandbox_export_get_artifact_bytes")),
951
+ {
952
+ title: "Get Sandbox Artifact Bytes",
953
+ description: "Fetch raw artifact bytes for a sandbox session (base64-encoded, 50 MB cap).",
954
+ inputSchema: {
955
+ sandboxId: zod.z.string(),
956
+ sessionId: zod.z.string(),
957
+ path: zod.z.string(),
958
+ onBehalfOfUserId: zod.z.string().optional()
959
+ }
960
+ },
961
+ async ({ sandboxId, sessionId, path, onBehalfOfUserId }) => {
962
+ try {
963
+ const input = { sandboxId, sessionId, path };
964
+ if (onBehalfOfUserId !== void 0) input.onBehalfOfUserId = onBehalfOfUserId;
965
+ const data = await wsRequest(
966
+ GET_SANDBOX_ARTIFACT_BYTES,
967
+ { input }
968
+ );
969
+ return jsonResult(data.getSandboxArtifactBytes);
970
+ } catch (error) {
971
+ ctx.logger.error("sandbox_export_get_artifact_bytes failed", { error });
972
+ return errorResult(
973
+ `Failed to get artifact bytes: ${error instanceof Error ? error.message : String(error)}`
974
+ );
975
+ }
976
+ }
977
+ );
978
+ server.registerTool(
979
+ track(mcpToolName(ctx.productName, "sandbox_proxy_request")),
980
+ {
981
+ title: "Proxy HTTP Request to Sandbox",
982
+ description: "Proxy an HTTP request to a service running inside a sandbox container.",
983
+ inputSchema: {
984
+ sandboxId: zod.z.string(),
985
+ method: zod.z.string(),
986
+ path: zod.z.string(),
987
+ body: zod.z.unknown().optional(),
988
+ containerName: zod.z.string().optional()
989
+ }
990
+ },
991
+ async ({ sandboxId, method, path, body, containerName }) => {
992
+ try {
993
+ const input = { sandboxId, method, path };
994
+ if (body !== void 0) input.body = body;
995
+ if (containerName !== void 0) input.containerName = containerName;
996
+ const data = await wsRequest(PROXY_SANDBOX_REQUEST, {
997
+ input
998
+ });
999
+ return jsonResult(data.proxySandboxRequest);
1000
+ } catch (error) {
1001
+ ctx.logger.error("sandbox_proxy_request failed", { error });
1002
+ return errorResult(
1003
+ `Failed to proxy request: ${error instanceof Error ? error.message : String(error)}`
1004
+ );
1005
+ }
1006
+ }
1007
+ );
1008
+ server.registerTool(
1009
+ track(mcpToolName(ctx.productName, "sandbox_check")),
1010
+ {
1011
+ title: "Check Sandbox State",
1012
+ description: "Poll a sandbox by ID. MCP has no subscription protocol \u2014 call this in a loop to track lifecycle.",
1013
+ inputSchema: { id: zod.z.string() }
1014
+ },
1015
+ async ({ id }) => {
1016
+ try {
1017
+ const data = await wsRequest(GET_SANDBOX, { id });
1018
+ return jsonResult(data.getSandbox);
1019
+ } catch (error) {
1020
+ ctx.logger.error("sandbox_check failed", { error });
1021
+ return errorResult(
1022
+ `Failed to poll sandbox: ${error instanceof Error ? error.message : String(error)}`
1023
+ );
1024
+ }
1025
+ }
60
1026
  );
61
- }
62
- function registerSandboxTools(server, ctx, track) {
63
- const featureNote = "Live alpha requires `$context: ContextInput!` on every sandbox call (33 tools), and `Query.sandboxes` is gone from the gateway. The MCP never supplied the `$context` arg.";
64
- const alts = [
65
- "the next alpha release that derives the sandbox context from the workspace token",
66
- "the SDK sandbox API (which the MCP will mirror once it lands)"
67
- ];
68
- const tools = [
69
- ["sandbox_list", "List Sandboxes", "List sandboxes in the active workspace."],
70
- ["sandbox_get", "Get Sandbox", "Get a sandbox by ID."],
71
- ["sandbox_create", "Create Sandbox", "Create a new sandbox."],
72
- ["sandbox_delete", "Delete Sandbox", "Delete a sandbox."],
73
- ["sandbox_start", "Start Sandbox", "Start a sandbox."],
74
- ["sandbox_stop", "Stop Sandbox", "Stop a sandbox."],
75
- ["sandbox_extend", "Extend Sandbox TTL", "Extend a sandbox's TTL."],
76
- ["sandbox_check", "Check Sandbox Health", "Run a health check on a sandbox."],
77
- ["sandbox_export_create", "Create Sandbox Export", "Create a sandbox export job."],
78
- ["sandbox_export_check", "Check Export Job", "Check the status of a sandbox export."],
79
- ["sandbox_export_get", "Get Sandbox Export", "Get details of a sandbox export job."],
80
- ["sandbox_export_list", "List Sandbox Exports", "List sandbox export jobs."],
81
- [
82
- "sandbox_export_get_artifact_bytes",
83
- "Get Export Artifact Bytes",
84
- "Fetch bytes of a sandbox export artifact."
85
- ],
86
- ["sandbox_templates_list", "List Sandbox Templates", "List sandbox templates."],
87
- ["sandbox_templates_get", "Get Sandbox Template", "Get a sandbox template by ID."],
88
- ["sandbox_templates_create", "Create Sandbox Template", "Create a new sandbox template."],
89
- ["sandbox_templates_update", "Update Sandbox Template", "Update a sandbox template."],
90
- ["sandbox_templates_delete", "Delete Sandbox Template", "Delete a sandbox template."],
91
- ["sandbox_tags_list", "List Sandbox Tags", "List tags on a sandbox."],
92
- ["sandbox_tags_get", "Get Sandbox Tag", "Get a sandbox tag."],
93
- ["sandbox_tags_create", "Create Sandbox Tag", "Create a tag on a sandbox."],
94
- ["sandbox_tags_attach", "Attach Tag to Sandbox", "Attach an existing tag to a sandbox."],
95
- ["sandbox_tags_detach", "Detach Tag from Sandbox", "Detach a tag from a sandbox."],
96
- ["sandbox_tags_replace", "Replace Sandbox Tags", "Replace the tag set on a sandbox."],
97
- [
98
- "sandbox_admin_list_all",
99
- "List All Sandboxes (Admin)",
100
- "List all sandboxes across workspaces (admin)."
101
- ],
102
- ["sandbox_admin_nodes_list", "List Sandbox Nodes (Admin)", "List sandbox node fleet (admin)."],
103
- ["sandbox_admin_active", "List Active Sandboxes (Admin)", "List active sandboxes (admin)."],
104
- [
105
- "sandbox_admin_activity",
106
- "List Recent Sandbox Activity (Admin)",
107
- "Recent activity across sandboxes (admin)."
108
- ],
109
- ["sandbox_admin_stats", "Sandbox Fleet Stats (Admin)", "Aggregate sandbox fleet stats."],
110
- ["sandbox_admin_logs", "Sandbox Fleet Logs (Admin)", "Sandbox fleet logs (admin)."],
111
- ["sandbox_admin_config_get", "Get Sandbox Config (Admin)", "Read sandbox module config."],
112
- ["sandbox_admin_config_set", "Update Sandbox Config (Admin)", "Update sandbox module config."],
113
- [
114
- "sandbox_export_workspace_list",
115
- "List Sandbox Exports (Workspace)",
116
- "List sandbox exports in the active workspace."
117
- ],
118
- ["sandbox_proxy_request", "Proxy Sandbox Request", "Proxy a request into a running sandbox."]
119
- ];
120
- for (const [tool, title, desc] of tools) {
121
- stubbedTool(
122
- server,
123
- track(mcpToolName(ctx.productName, tool)),
124
- title,
125
- desc,
126
- featureNote,
127
- {},
128
- alts
129
- );
130
- }
131
1027
  }
132
1028
 
133
1029
  // src/modules/sandbox/index.ts