@burdenoff/mcp-libs 2026.523.1 → 2026.529.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.
@@ -93,6 +93,68 @@ var GET_EXPORT_TEMPLATE = `
93
93
  }
94
94
  }
95
95
  `;
96
+ var CANCEL_EXPORT_JOB = `
97
+ mutation CancelExportJob($context: ContextInput, $id: ID!) {
98
+ cancelExportJob(context: $context, id: $id) { id status progress }
99
+ }
100
+ `;
101
+ var DELETE_EXPORT_JOB = `
102
+ mutation DeleteExportJob($context: ContextInput, $id: ID!) {
103
+ deleteExportJob(context: $context, id: $id)
104
+ }
105
+ `;
106
+ var RETRY_EXPORT_JOB = `
107
+ mutation RetryExportJob($context: ContextInput, $id: ID!) {
108
+ retryExportJob(context: $context, id: $id) { id status progress }
109
+ }
110
+ `;
111
+ var CREATE_EXPORT_TEMPLATE = `
112
+ mutation CreateExportTemplate($context: ContextInput, $input: CreateExportTemplateInput!) {
113
+ createExportTemplate(context: $context, input: $input) {
114
+ id name entityTypes format includeMedia includeMetadata
115
+ }
116
+ }
117
+ `;
118
+ var UPDATE_EXPORT_TEMPLATE = `
119
+ mutation UpdateExportTemplate(
120
+ $context: ContextInput
121
+ $id: ID!
122
+ $input: UpdateExportTemplateInput!
123
+ ) {
124
+ updateExportTemplate(context: $context, id: $id, input: $input) {
125
+ id name entityTypes format includeMedia includeMetadata isDefault
126
+ }
127
+ }
128
+ `;
129
+ var DELETE_EXPORT_TEMPLATE = `
130
+ mutation DeleteExportTemplate($context: ContextInput, $id: ID!) {
131
+ deleteExportTemplate(context: $context, id: $id)
132
+ }
133
+ `;
134
+ var GET_AVAILABLE_EXPORT_ENTITIES = `
135
+ query GetAvailableExportEntities(
136
+ $context: ContextInput!
137
+ $pagination: ExportPaginationInput
138
+ ) {
139
+ getAvailableExportEntities(context: $context, pagination: $pagination) {
140
+ edges {
141
+ node {
142
+ entityType displayName description enabled
143
+ supportsDateRange supportsMediaExport estimatedSize
144
+ }
145
+ }
146
+ pageInfo { totalCount }
147
+ }
148
+ }
149
+ `;
150
+ var GET_EXPORT_PART = `
151
+ query GetExportPart($context: ContextInput, $id: ID!) {
152
+ getExportPart(context: $context, id: $id) {
153
+ id jobId partNumber fileName fileId sizeBytes checksum
154
+ downloadUrl downloadExpiresAt
155
+ }
156
+ }
157
+ `;
96
158
 
97
159
  // src/modules/export/tools.ts
98
160
  function readWorkspaceContext(ctx) {
@@ -307,6 +369,292 @@ function registerExportTools(server, ctx, track) {
307
369
  }
308
370
  }
309
371
  );
372
+ server.registerTool(
373
+ track(mcpToolName(ctx.productName, "export_jobs_cancel")),
374
+ {
375
+ title: "Cancel Export Job",
376
+ description: "Cancel a running export job.",
377
+ inputSchema: { id: zod.z.string().describe("Export job ID") }
378
+ },
379
+ async ({ id }) => {
380
+ try {
381
+ const context = readWorkspaceContext(ctx);
382
+ if (!context) {
383
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
384
+ }
385
+ const data = await ctx.gql.workspace.request(
386
+ CANCEL_EXPORT_JOB,
387
+ { context, id }
388
+ );
389
+ return jsonResult(data.cancelExportJob);
390
+ } catch (error) {
391
+ ctx.logger.error("export_jobs_cancel failed", { error: String(error) });
392
+ return errorResult(
393
+ `Failed to cancel export job: ${error instanceof Error ? error.message : String(error)}`
394
+ );
395
+ }
396
+ }
397
+ );
398
+ server.registerTool(
399
+ track(mcpToolName(ctx.productName, "export_jobs_delete")),
400
+ {
401
+ title: "Delete Export Job",
402
+ description: "Delete an export job.",
403
+ inputSchema: { id: zod.z.string().describe("Export job ID") }
404
+ },
405
+ async ({ id }) => {
406
+ try {
407
+ const context = readWorkspaceContext(ctx);
408
+ if (!context) {
409
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
410
+ }
411
+ const data = await ctx.gql.workspace.request(
412
+ DELETE_EXPORT_JOB,
413
+ { context, id }
414
+ );
415
+ return jsonResult({ deleted: data.deleteExportJob, id });
416
+ } catch (error) {
417
+ ctx.logger.error("export_jobs_delete failed", { error: String(error) });
418
+ return errorResult(
419
+ `Failed to delete export job: ${error instanceof Error ? error.message : String(error)}`
420
+ );
421
+ }
422
+ }
423
+ );
424
+ server.registerTool(
425
+ track(mcpToolName(ctx.productName, "export_jobs_retry")),
426
+ {
427
+ title: "Retry Export Job",
428
+ description: "Retry a failed export job.",
429
+ inputSchema: { id: zod.z.string().describe("Export job ID") }
430
+ },
431
+ async ({ id }) => {
432
+ try {
433
+ const context = readWorkspaceContext(ctx);
434
+ if (!context) {
435
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
436
+ }
437
+ const data = await ctx.gql.workspace.request(
438
+ RETRY_EXPORT_JOB,
439
+ { context, id }
440
+ );
441
+ return jsonResult(data.retryExportJob);
442
+ } catch (error) {
443
+ ctx.logger.error("export_jobs_retry failed", { error: String(error) });
444
+ return errorResult(
445
+ `Failed to retry export job: ${error instanceof Error ? error.message : String(error)}`
446
+ );
447
+ }
448
+ }
449
+ );
450
+ server.registerTool(
451
+ track(mcpToolName(ctx.productName, "export_job_check")),
452
+ {
453
+ title: "Check Export Job Progress",
454
+ description: "Polling tool that returns the current status/progress of an export job. Designed for AI agents to call repeatedly in lieu of the GraphQL `exportJobProgress` subscription (no MCP transport for live streams).",
455
+ inputSchema: { jobId: zod.z.string().describe("Export job ID") }
456
+ },
457
+ async ({ jobId }) => {
458
+ try {
459
+ const context = readWorkspaceContext(ctx);
460
+ if (!context) {
461
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
462
+ }
463
+ const data = await ctx.gql.workspace.request(
464
+ GET_EXPORT_JOB,
465
+ { context, id: jobId }
466
+ );
467
+ if (!data.getExportJob) return errorResult(`Export job ${jobId} not found`);
468
+ const terminal = ["COMPLETED", "FAILED", "CANCELLED", "EXPIRED", "DELETED"];
469
+ return jsonResult({
470
+ ...data.getExportJob,
471
+ isTerminal: terminal.includes(String(data.getExportJob.status ?? ""))
472
+ });
473
+ } catch (error) {
474
+ ctx.logger.error("export_job_check failed", { error: String(error) });
475
+ return errorResult(
476
+ `Failed to check export job: ${error instanceof Error ? error.message : String(error)}`
477
+ );
478
+ }
479
+ }
480
+ );
481
+ server.registerTool(
482
+ track(mcpToolName(ctx.productName, "export_templates_create")),
483
+ {
484
+ title: "Create Export Template",
485
+ description: "Create a reusable export template.",
486
+ inputSchema: {
487
+ name: zod.z.string().describe("Template name"),
488
+ entityTypes: zod.z.array(zod.z.string()).describe("Entity types to include"),
489
+ description: zod.z.string().optional(),
490
+ format: ExportFormatEnum.optional(),
491
+ includeMedia: zod.z.boolean().optional(),
492
+ includeMetadata: zod.z.boolean().optional()
493
+ }
494
+ },
495
+ async ({ name, entityTypes, description, format, includeMedia, includeMetadata }) => {
496
+ try {
497
+ const context = readWorkspaceContext(ctx);
498
+ if (!context) {
499
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
500
+ }
501
+ const input = {
502
+ name,
503
+ entityTypes,
504
+ format: format ?? "JSON",
505
+ includeMedia: includeMedia === true,
506
+ includeMetadata: includeMetadata !== false
507
+ };
508
+ if (description !== void 0) input.description = description;
509
+ const data = await ctx.gql.workspace.request(
510
+ CREATE_EXPORT_TEMPLATE,
511
+ { context, input }
512
+ );
513
+ return jsonResult(data.createExportTemplate);
514
+ } catch (error) {
515
+ ctx.logger.error("export_templates_create failed", { error: String(error) });
516
+ return errorResult(
517
+ `Failed to create export template: ${error instanceof Error ? error.message : String(error)}`
518
+ );
519
+ }
520
+ }
521
+ );
522
+ server.registerTool(
523
+ track(mcpToolName(ctx.productName, "export_templates_update")),
524
+ {
525
+ title: "Update Export Template",
526
+ description: "Update an existing export template. Only supplied fields are changed.",
527
+ inputSchema: {
528
+ id: zod.z.string().describe("Template ID"),
529
+ name: zod.z.string().optional(),
530
+ description: zod.z.string().optional(),
531
+ entityTypes: zod.z.array(zod.z.string()).optional(),
532
+ format: ExportFormatEnum.optional(),
533
+ includeMedia: zod.z.boolean().optional(),
534
+ includeMetadata: zod.z.boolean().optional(),
535
+ isDefault: zod.z.boolean().optional()
536
+ }
537
+ },
538
+ async ({
539
+ id,
540
+ name,
541
+ description,
542
+ entityTypes,
543
+ format,
544
+ includeMedia,
545
+ includeMetadata,
546
+ isDefault
547
+ }) => {
548
+ try {
549
+ const context = readWorkspaceContext(ctx);
550
+ if (!context) {
551
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
552
+ }
553
+ const input = {};
554
+ if (name !== void 0) input.name = name;
555
+ if (description !== void 0) input.description = description;
556
+ if (entityTypes !== void 0) input.entityTypes = entityTypes;
557
+ if (format !== void 0) input.format = format;
558
+ if (includeMedia !== void 0) input.includeMedia = includeMedia;
559
+ if (includeMetadata !== void 0) input.includeMetadata = includeMetadata;
560
+ if (isDefault !== void 0) input.isDefault = isDefault;
561
+ const data = await ctx.gql.workspace.request(
562
+ UPDATE_EXPORT_TEMPLATE,
563
+ { context, id, input }
564
+ );
565
+ return jsonResult(data.updateExportTemplate);
566
+ } catch (error) {
567
+ ctx.logger.error("export_templates_update failed", { error: String(error) });
568
+ return errorResult(
569
+ `Failed to update export template: ${error instanceof Error ? error.message : String(error)}`
570
+ );
571
+ }
572
+ }
573
+ );
574
+ server.registerTool(
575
+ track(mcpToolName(ctx.productName, "export_templates_delete")),
576
+ {
577
+ title: "Delete Export Template",
578
+ description: "Delete an export template.",
579
+ inputSchema: { id: zod.z.string().describe("Template ID") }
580
+ },
581
+ async ({ id }) => {
582
+ try {
583
+ const context = readWorkspaceContext(ctx);
584
+ if (!context) {
585
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
586
+ }
587
+ const data = await ctx.gql.workspace.request(
588
+ DELETE_EXPORT_TEMPLATE,
589
+ { context, id }
590
+ );
591
+ return jsonResult({ deleted: data.deleteExportTemplate, id });
592
+ } catch (error) {
593
+ ctx.logger.error("export_templates_delete failed", { error: String(error) });
594
+ return errorResult(
595
+ `Failed to delete export template: ${error instanceof Error ? error.message : String(error)}`
596
+ );
597
+ }
598
+ }
599
+ );
600
+ server.registerTool(
601
+ track(mcpToolName(ctx.productName, "export_entities_list")),
602
+ {
603
+ title: "List Available Export Entities",
604
+ description: "List the entity types available for export in the active workspace.",
605
+ inputSchema: {
606
+ limit: zod.z.number().optional().describe("Page size (default 50)")
607
+ }
608
+ },
609
+ async ({ limit }) => {
610
+ try {
611
+ const context = readWorkspaceContext(ctx);
612
+ if (!context) {
613
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
614
+ }
615
+ const data = await ctx.gql.workspace.request(GET_AVAILABLE_EXPORT_ENTITIES, {
616
+ context,
617
+ pagination: { first: limit ?? 50 }
618
+ });
619
+ return jsonResult({
620
+ items: data.getAvailableExportEntities.edges.map((e) => e.node),
621
+ pageInfo: data.getAvailableExportEntities.pageInfo
622
+ });
623
+ } catch (error) {
624
+ ctx.logger.error("export_entities_list failed", { error: String(error) });
625
+ return errorResult(
626
+ `Failed to list available export entities: ${error instanceof Error ? error.message : String(error)}`
627
+ );
628
+ }
629
+ }
630
+ );
631
+ server.registerTool(
632
+ track(mcpToolName(ctx.productName, "export_parts_get")),
633
+ {
634
+ title: "Get Export Part",
635
+ description: "Get an export part (a single chunk produced by a multi-part export job).",
636
+ inputSchema: { id: zod.z.string().describe("Export part ID") }
637
+ },
638
+ async ({ id }) => {
639
+ try {
640
+ const context = readWorkspaceContext(ctx);
641
+ if (!context) {
642
+ return errorResult("No workspace set. Run the auth workspace_set tool first.");
643
+ }
644
+ const data = await ctx.gql.workspace.request(
645
+ GET_EXPORT_PART,
646
+ { context, id }
647
+ );
648
+ if (!data.getExportPart) return errorResult(`Export part ${id} not found`);
649
+ return jsonResult(data.getExportPart);
650
+ } catch (error) {
651
+ ctx.logger.error("export_parts_get failed", { error: String(error) });
652
+ return errorResult(
653
+ `Failed to get export part: ${error instanceof Error ? error.message : String(error)}`
654
+ );
655
+ }
656
+ }
657
+ );
310
658
  }
311
659
 
312
660
  // src/modules/export/index.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/errors.ts","../../../src/core/result.ts","../../../src/core/tool-name.ts","../../../src/modules/export/operations.ts","../../../src/modules/export/tools.ts","../../../src/modules/export/index.ts"],"names":["z","writeFile"],"mappings":";;;;;;;;;;;;AA8BO,IAAM,gBAAA,GAAN,cAA+B,KAAA,CAAM;AAAA,EACjB,KAAA;AAAA,EAEzB,WAAA,CAAY,SAAiB,KAAA,EAAiB;AAC5C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;AACZ,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF,CAAA;;;ACCO,SAAS,UAAA,CAAW,MAAe,UAAA,EAAkD;AAC1F,EAAA,MAAM,MAAA,GAAqB;AAAA,IACzB,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,IAAA,EAAM,CAAC,CAAA,EAAG;AAAA,GACjE;AAIA,EAAA,OAAO,MAAA;AACT;AAaO,SAAS,WAAA,CAAY,SAAiB,IAAA,EAA2B;AACtE,EAAA,MAAM,IAAA,GAAO,IAAA,GAAO,CAAA,EAAG,OAAO;;AAAA,MAAA,EAAa,IAAI,CAAA,CAAA,GAAK,OAAA;AACpD,EAAA,OAAO,EAAE,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ,IAAA,EAAM,CAAA,EAAG,OAAA,EAAS,IAAA,EAAK;AAC5D;;;ACnDA,IAAM,oBAAA,GAAuB,EAAA;AAE7B,SAAS,cAAA,CAAe,MAAc,IAAA,EAA8C;AAClF,EAAA,IAAuB,IAAA,CAAK,MAAA,GAAS,oBAAA,EAAsB;AACzD,IAAA,MAAM,IAAI,gBAAA;AAAA,MACR,CAAA,WAAA,EAAc,IAAI,CAAA,UAAA,EAAa,oBAAoB,CAAA,8CAAA;AAAA,KACrD;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAMO,SAAS,WAAA,CAAY,gBAAwB,KAAA,EAAyB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CAAC,CAAA,KAAsB;AACnC,MAAA,KAAA,CAAM,KAAK,CAAC,CAAA;AACZ,MAAA,OAAO,CAAA;AAAA,IACT,CAAA;AAEA,IAAA,mBAAA,CAAoB,MAAA,EAAQ,KAAK,KAAK,CAAA;AAEtC,IAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,EAAC,EAAG,OAAA,EAAS,EAAC,EAAE;AAAA,EAC7C;AACF,CAAA;AAEA,IAAO,cAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * Error classes for MCP SDK.\n *\n * Modules MUST throw these instead of throwing raw Errors. The registerTool\n * wrapper in result.ts catches and maps them to MCP-protocol-compliant\n * `{ isError: true, content: [...] }` responses.\n *\n * Throwing past the wrapper to the protocol surfaces as JSON-RPC -32603 to\n * the client and is a protocol bug.\n */\n\nexport class McpUserError extends Error {\n public readonly hint: string | undefined;\n\n constructor(message: string, opts?: { hint?: string }) {\n super(message);\n this.name = 'McpUserError';\n this.hint = opts?.hint;\n }\n}\n\nexport class McpAuthError extends McpUserError {\n constructor(message: string, opts?: { hint?: string }) {\n super(message, {\n hint: opts?.hint ?? 'Run the auth_login tool to authenticate.',\n });\n this.name = 'McpAuthError';\n }\n}\n\nexport class McpInternalError extends Error {\n public override readonly cause: unknown;\n\n constructor(message: string, cause?: unknown) {\n super(message);\n this.name = 'McpInternalError';\n this.cause = cause;\n }\n}\n","/**\n * MCP tool result helpers + central handler.\n *\n * Modules NEVER call server.registerTool directly — they use registerTool()\n * from this module so the central try/catch wraps the handler and:\n * - maps thrown McpUserError / McpAuthError / McpInternalError to\n * MCP-protocol-compliant `{ isError: true, content: [...] }` shapes\n * - threads `_meta.progressToken` into ctx.progress for long ops\n * - emits a structured log line on every error\n * - never leaks `cause` from McpInternalError to the client\n *\n * This is the analog of cli-sdk's createProgram() central error handler.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { ZodRawShape } from 'zod';\nimport type { McpContext } from './context.js';\nimport { McpAuthError, McpInternalError, McpUserError } from './errors.js';\n\nexport interface ToolTextContent {\n type: 'text';\n text: string;\n [k: string]: unknown;\n}\n\nexport interface ToolResult {\n content: ToolTextContent[];\n isError?: boolean;\n structuredContent?: Record<string, unknown>;\n [k: string]: unknown;\n}\n\nexport interface ToolMeta {\n progressToken?: string | number;\n}\n\n/**\n * Build a successful tool result with JSON content (pretty-printed).\n */\nexport function jsonResult(data: unknown, structured?: Record<string, unknown>): ToolResult {\n const result: ToolResult = {\n content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],\n };\n if (structured !== undefined) {\n result.structuredContent = structured;\n }\n return result;\n}\n\n/**\n * Build a successful tool result with plain text content.\n */\nexport function textResult(text: string): ToolResult {\n return { content: [{ type: 'text', text }] };\n}\n\n/**\n * Build an error tool result. Honors MCP's `{ isError: true, content }` shape.\n * Optional hint is appended on a new line so the LLM can react.\n */\nexport function errorResult(message: string, hint?: string): ToolResult {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return { content: [{ type: 'text', text }], isError: true };\n}\n\nexport interface ToolMetadata {\n title: string;\n description: string;\n inputSchema?: ZodRawShape;\n}\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n ctx: McpContext,\n meta: ToolMeta,\n) => Promise<unknown>;\n\n/**\n * Register a tool with the central error wrapper.\n *\n * The handler returns a plain value or void. The wrapper:\n * - wraps non-undefined returns in jsonResult()\n * - if the value already looks like a ToolResult (has `content`), passes through\n * - catches McpAuthError / McpUserError / McpInternalError / generic Error\n * - logs every error via ctx.logger.error\n */\nexport function registerTool<TArgs extends Record<string, unknown>>(\n server: McpServer,\n ctx: McpContext,\n name: string,\n metadata: ToolMetadata,\n handler: ToolHandler<TArgs>,\n): void {\n const sdkConfig = {\n title: metadata.title,\n description: metadata.description,\n ...(metadata.inputSchema ? { inputSchema: metadata.inputSchema } : {}),\n };\n\n // The MCP SDK's registerTool signature is `(name, config, handler)`. The\n // handler arity depends on whether inputSchema is present (1-arg without,\n // 2-arg with). We accept a unified handler shape and dispatch at runtime.\n // The SDK's typing is strict and conditional on the inputSchema generic;\n // bypass with a cast since runtime acceptance is unconditional.\n const wrapped = async (...callbackArgs: unknown[]): Promise<ToolResult> => {\n const hasArgs = callbackArgs.length === 2;\n const args = (hasArgs ? callbackArgs[0] : {}) as TArgs;\n const extra = (hasArgs ? callbackArgs[1] : callbackArgs[0]) as\n | { _meta?: { progressToken?: string | number } }\n | undefined;\n\n const progressToken = extra?._meta?.progressToken;\n const meta: ToolMeta = progressToken !== undefined ? { progressToken } : {};\n\n try {\n const result = await handler(args, ctx, meta);\n if (isToolResult(result)) return result;\n if (result === undefined) return textResult('OK');\n return jsonResult(result);\n } catch (error) {\n return mapErrorToResult(error, ctx, name);\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (server as any).registerTool(name, sdkConfig, wrapped);\n}\n\nfunction isToolResult(value: unknown): value is ToolResult {\n return (\n !!value &&\n typeof value === 'object' &&\n 'content' in value &&\n Array.isArray((value as ToolResult).content)\n );\n}\n\nfunction mapErrorToResult(error: unknown, ctx: McpContext, toolName: string): ToolResult {\n if (error instanceof McpAuthError) {\n ctx.logger.warn(`${toolName}: auth required`, { message: error.message });\n return errorResult(error.message, error.hint);\n }\n if (error instanceof McpUserError) {\n ctx.logger.info(`${toolName}: user error`, { message: error.message });\n return errorResult(error.message, error.hint);\n }\n if (error instanceof McpInternalError) {\n ctx.logger.error(`${toolName}: internal error`, {\n message: error.message,\n cause: stringifyCause(error.cause),\n });\n return errorResult(`Internal error in ${toolName}.`);\n }\n const message = error instanceof Error ? error.message : String(error);\n ctx.logger.error(`${toolName}: unhandled error`, { message });\n return errorResult(`${toolName}: ${message}`);\n}\n\nfunction stringifyCause(cause: unknown): string | undefined {\n if (cause === undefined || cause === null) return undefined;\n if (cause instanceof Error) return cause.message;\n try {\n return JSON.stringify(cause);\n } catch {\n return String(cause);\n }\n}\n","/**\n * Tool / resource / prompt naming helpers.\n *\n * Mandatory product prefix avoids collisions when Claude Desktop runs\n * multiple MCP servers concurrently (typical setup is ~6).\n *\n * Tool names are capped at 63 characters — Claude Desktop pre-1.x\n * truncated at 64 in some versions.\n */\n\nimport { McpInternalError } from './errors.js';\n\nconst MAX_TOOL_NAME_LENGTH = 63;\n\nfunction assertSafeName(name: string, kind: 'tool' | 'resource' | 'prompt'): string {\n if (kind === 'tool' && name.length > MAX_TOOL_NAME_LENGTH) {\n throw new McpInternalError(\n `Tool name '${name}' exceeds ${MAX_TOOL_NAME_LENGTH} characters (some MCP clients truncate at 64).`,\n );\n }\n return name;\n}\n\n/**\n * Build a tool name. Format: `<productName>_<...parts>` (snake_case).\n * Example: mcpToolName('vibecontrols', 'vibes', 'list') -> 'vibecontrols_vibes_list'\n */\nexport function mcpToolName(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpToolName: productName is required');\n }\n const name = [productName, ...parts].filter(Boolean).join('_');\n return assertSafeName(name, 'tool');\n}\n\n/**\n * Build a resource URI. Format: `<productName>://<...parts>`.\n * Example: mcpResourceUri('vibecontrols', 'schema') -> 'vibecontrols://schema'\n */\nexport function mcpResourceUri(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpResourceUri: productName is required');\n }\n return `${productName}://${parts.filter(Boolean).join('/')}`;\n}\n\n/**\n * Build a prompt name. Format: `<productName>-<...parts>` (kebab-case).\n * Example: mcpPromptName('vibecontrols', 'setup') -> 'vibecontrols-setup'\n */\nexport function mcpPromptName(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpPromptName: productName is required');\n }\n return [productName, ...parts].filter(Boolean).join('-');\n}\n\nexport const TOOL_NAME_LIMIT = MAX_TOOL_NAME_LENGTH;\n","export const LIST_EXPORT_JOBS = `\n query ListExportJobs($context: ContextInput!, $filter: ExportJobFilterInput, $pagination: ExportPaginationInput) {\n listExportJobs(context: $context, filter: $filter, pagination: $pagination) {\n edges { node {\n id name status progress totalEntities processedEntities\n startedAt completedAt downloadUrl downloadExpiresAt\n } }\n pageInfo { totalCount hasNextPage }\n }\n }\n`;\n\nexport const GET_EXPORT_JOB = `\n query GetExportJob($context: ContextInput, $id: ID!) {\n getExportJob(context: $context, id: $id) {\n id name status progress\n downloadUrl downloadExpiresAt totalSizeBytes\n }\n }\n`;\n\nexport const CREATE_EXPORT_JOB = `\n mutation CreateExportJob($context: ContextInput!, $input: CreateExportJobInput!) {\n createExportJob(context: $context, input: $input) {\n id status progress entityTypes\n }\n }\n`;\n\nexport const LIST_EXPORT_TEMPLATES = `\n query ListExportTemplates($context: ContextInput!, $pagination: ExportPaginationInput) {\n listExportTemplates(context: $context, pagination: $pagination) {\n edges { node { id name entityTypes format includeMedia includeMetadata } }\n pageInfo { totalCount }\n }\n }\n`;\n\nexport const GET_EXPORT_TEMPLATE = `\n query GetExportTemplate($context: ContextInput, $id: ID!) {\n getExportTemplate(context: $context, id: $id) {\n id name entityTypes format\n }\n }\n`;\n","/**\n * Export MCP tools — export jobs lifecycle, templates, download.\n * Surface mirrors cli-sdk/src/modules/export/commands.ts.\n */\n\nimport { writeFile } from 'fs/promises';\nimport { z } from 'zod';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { jsonResult, errorResult, mcpToolName, type McpContext } from '../../core/index.js';\nimport * as ops from './operations.js';\n\ninterface JobNode {\n id: string;\n name?: string;\n status?: string;\n progress?: number;\n totalEntities?: number;\n processedEntities?: number;\n startedAt?: string;\n completedAt?: string;\n downloadUrl?: string;\n downloadExpiresAt?: string;\n}\n\ninterface TemplateNode {\n id: string;\n name?: string;\n entityTypes?: string[];\n format?: string;\n}\n\nfunction readWorkspaceContext(ctx: McpContext): { workspaceId: string } | null {\n const auth = ctx.auth.read();\n if (!auth?.workspaceId) return null;\n return { workspaceId: auth.workspaceId };\n}\n\nconst ExportFormatEnum = z.enum(['JSON', 'CSV', 'ZIP']);\n\nexport function registerExportTools(\n server: McpServer,\n ctx: McpContext,\n track: (n: string) => string,\n): void {\n // ── Jobs ────────────────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_list')),\n {\n title: 'List Export Jobs',\n description: 'List export jobs in the active workspace.',\n inputSchema: {\n status: z.string().optional().describe('Filter by status (will be uppercased)'),\n limit: z.number().optional().describe('Page size (default 50)'),\n },\n },\n async ({ status, limit }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const filter: Record<string, unknown> = {};\n if (status !== undefined) filter.status = status.toUpperCase();\n const data = await ctx.gql.workspace.request<{\n listExportJobs: {\n edges: Array<{ node: JobNode }>;\n pageInfo: { totalCount: number; hasNextPage: boolean };\n };\n }>(ops.LIST_EXPORT_JOBS, {\n context,\n filter: Object.keys(filter).length > 0 ? filter : undefined,\n pagination: { first: limit ?? 50 },\n });\n return jsonResult({\n items: data.listExportJobs.edges.map((e) => e.node),\n pageInfo: data.listExportJobs.pageInfo,\n });\n } catch (error) {\n ctx.logger.error('export_jobs_list failed', { error: String(error) });\n return errorResult(\n `Failed to list export jobs: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_get')),\n {\n title: 'Get Export Job',\n description: 'Get an export job by ID.',\n inputSchema: { id: z.string().describe('Export job ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportJob: JobNode | null }>(\n ops.GET_EXPORT_JOB,\n { context, id },\n );\n if (!data.getExportJob) return errorResult(`Export job ${id} not found`);\n return jsonResult(data.getExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_get failed', { error: String(error) });\n return errorResult(\n `Failed to get export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_create')),\n {\n title: 'Create Export Job',\n description: 'Create an export job for one or more entity types.',\n inputSchema: {\n name: z.string().describe('Job name'),\n entityTypes: z.array(z.string()).describe('Entity types to export'),\n format: ExportFormatEnum.optional().describe('Output format (default JSON)'),\n includeMedia: z.boolean().optional().describe('Include media files (default false)'),\n includeMetadata: z.boolean().optional().describe('Include metadata (default true)'),\n from: z.string().optional().describe('Date range start (ISO)'),\n to: z.string().optional().describe('Date range end (ISO)'),\n },\n },\n async ({ name, entityTypes, format, includeMedia, includeMetadata, from, to }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const input: Record<string, unknown> = {\n name,\n entityTypes,\n format: format ?? 'JSON',\n includeMedia: includeMedia === true,\n includeMetadata: includeMetadata !== false,\n };\n if (from !== undefined) input.dateRangeStart = from;\n if (to !== undefined) input.dateRangeEnd = to;\n const data = await ctx.gql.workspace.request<{ createExportJob: JobNode }>(\n ops.CREATE_EXPORT_JOB,\n { context, input },\n );\n return jsonResult(data.createExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_create failed', { error: String(error) });\n return errorResult(\n `Failed to create export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_download')),\n {\n title: 'Download Export Job',\n description: 'Download a completed export job to a local file path.',\n inputSchema: {\n jobId: z.string().describe('Export job ID'),\n to: z.string().describe('Local file path to write'),\n },\n },\n async ({ jobId, to }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportJob: JobNode | null }>(\n ops.GET_EXPORT_JOB,\n { context, id: jobId },\n );\n if (!data.getExportJob) return errorResult(`Export job ${jobId} not found`);\n const url = data.getExportJob.downloadUrl;\n if (!url) {\n return errorResult(\n `Job ${jobId} has no downloadUrl yet (status=${data.getExportJob.status ?? 'UNKNOWN'}).`,\n );\n }\n const res = await fetch(url);\n if (!res.ok) {\n return errorResult(`Download failed: ${res.status} ${res.statusText}`);\n }\n const buf = Buffer.from(await res.arrayBuffer());\n await writeFile(to, buf);\n return jsonResult({ status: 'success', path: to, bytes: buf.length });\n } catch (error) {\n ctx.logger.error('export_download failed', { error: String(error) });\n return errorResult(\n `Failed to download export: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Templates ───────────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_list')),\n {\n title: 'List Export Templates',\n description: 'List export templates in the active workspace.',\n inputSchema: {\n limit: z.number().optional().describe('Page size (default 50)'),\n },\n },\n async ({ limit }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{\n listExportTemplates: {\n edges: Array<{ node: TemplateNode }>;\n pageInfo: { totalCount: number };\n };\n }>(ops.LIST_EXPORT_TEMPLATES, {\n context,\n pagination: { first: limit ?? 50 },\n });\n return jsonResult({\n items: data.listExportTemplates.edges.map((e) => e.node),\n pageInfo: data.listExportTemplates.pageInfo,\n });\n } catch (error) {\n ctx.logger.error('export_templates_list failed', { error: String(error) });\n return errorResult(\n `Failed to list export templates: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_get')),\n {\n title: 'Get Export Template',\n description: 'Get an export template by ID.',\n inputSchema: { id: z.string().describe('Template ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportTemplate: TemplateNode | null }>(\n ops.GET_EXPORT_TEMPLATE,\n { context, id },\n );\n if (!data.getExportTemplate) return errorResult(`Template ${id} not found`);\n return jsonResult(data.getExportTemplate);\n } catch (error) {\n ctx.logger.error('export_templates_get failed', { error: String(error) });\n return errorResult(\n `Failed to get export template: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n}\n","/**\n * Export module — workspace data export jobs and templates.\n * Surface mirrors cli-sdk/src/modules/export/.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { McpContext, McpModule, ModuleRegistration } from '../../core/index.js';\nimport { registerExportTools } from './tools.js';\n\nconst exportModule: McpModule = {\n id: 'export',\n version: '0.0.1',\n displayName: 'Export',\n dependsOn: ['auth'],\n capabilities: { tools: {} },\n\n register(server: McpServer, ctx: McpContext): ModuleRegistration {\n const tools: string[] = [];\n const track = (n: string): string => {\n tools.push(n);\n return n;\n };\n\n registerExportTools(server, ctx, track);\n\n return { tools, resources: [], prompts: [] };\n },\n};\n\nexport default exportModule;\n"]}
1
+ {"version":3,"sources":["../../../src/core/errors.ts","../../../src/core/result.ts","../../../src/core/tool-name.ts","../../../src/modules/export/operations.ts","../../../src/modules/export/tools.ts","../../../src/modules/export/index.ts"],"names":["z","writeFile"],"mappings":";;;;;;;;;;;;AA8BO,IAAM,gBAAA,GAAN,cAA+B,KAAA,CAAM;AAAA,EACjB,KAAA;AAAA,EAEzB,WAAA,CAAY,SAAiB,KAAA,EAAiB;AAC5C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;AACZ,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF,CAAA;;;ACCO,SAAS,UAAA,CAAW,MAAe,UAAA,EAAkD;AAC1F,EAAA,MAAM,MAAA,GAAqB;AAAA,IACzB,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,IAAA,EAAM,CAAC,CAAA,EAAG;AAAA,GACjE;AAIA,EAAA,OAAO,MAAA;AACT;AAaO,SAAS,WAAA,CAAY,SAAiB,IAAA,EAA2B;AACtE,EAA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C/D,IAAA,MAAM,QAAkB,EAAC;AACzB,IAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,KAAsB;AACnC,MAAA,KAAA,CAAM,KAAK,CAAC,CAAA;AACZ,MAAA,OAAO,CAAA;AAAA,IACT,CAAA;AAEA,IAAA,mBAAA,CAAoB,MAAA,EAAQ,KAAK,KAAK,CAAA;AAEtC,IAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,EAAC,EAAG,OAAA,EAAS,EAAC,EAAE;AAAA,EAC7C;AACF,CAAA;AAEA,IAAO,cAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * Error classes for MCP SDK.\n *\n * Modules MUST throw these instead of throwing raw Errors. The registerTool\n * wrapper in result.ts catches and maps them to MCP-protocol-compliant\n * `{ isError: true, content: [...] }` responses.\n *\n * Throwing past the wrapper to the protocol surfaces as JSON-RPC -32603 to\n * the client and is a protocol bug.\n */\n\nexport class McpUserError extends Error {\n public readonly hint: string | undefined;\n\n constructor(message: string, opts?: { hint?: string }) {\n super(message);\n this.name = 'McpUserError';\n this.hint = opts?.hint;\n }\n}\n\nexport class McpAuthError extends McpUserError {\n constructor(message: string, opts?: { hint?: string }) {\n super(message, {\n hint: opts?.hint ?? 'Run the auth_login tool to authenticate.',\n });\n this.name = 'McpAuthError';\n }\n}\n\nexport class McpInternalError extends Error {\n public override readonly cause: unknown;\n\n constructor(message: string, cause?: unknown) {\n super(message);\n this.name = 'McpInternalError';\n this.cause = cause;\n }\n}\n","/**\n * MCP tool result helpers + central handler.\n *\n * Modules NEVER call server.registerTool directly — they use registerTool()\n * from this module so the central try/catch wraps the handler and:\n * - maps thrown McpUserError / McpAuthError / McpInternalError to\n * MCP-protocol-compliant `{ isError: true, content: [...] }` shapes\n * - threads `_meta.progressToken` into ctx.progress for long ops\n * - emits a structured log line on every error\n * - never leaks `cause` from McpInternalError to the client\n *\n * This is the analog of cli-sdk's createProgram() central error handler.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { ZodRawShape } from 'zod';\nimport type { McpContext } from './context.js';\nimport { McpAuthError, McpInternalError, McpUserError } from './errors.js';\n\nexport interface ToolTextContent {\n type: 'text';\n text: string;\n [k: string]: unknown;\n}\n\nexport interface ToolResult {\n content: ToolTextContent[];\n isError?: boolean;\n structuredContent?: Record<string, unknown>;\n [k: string]: unknown;\n}\n\nexport interface ToolMeta {\n progressToken?: string | number;\n}\n\n/**\n * Build a successful tool result with JSON content (pretty-printed).\n */\nexport function jsonResult(data: unknown, structured?: Record<string, unknown>): ToolResult {\n const result: ToolResult = {\n content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],\n };\n if (structured !== undefined) {\n result.structuredContent = structured;\n }\n return result;\n}\n\n/**\n * Build a successful tool result with plain text content.\n */\nexport function textResult(text: string): ToolResult {\n return { content: [{ type: 'text', text }] };\n}\n\n/**\n * Build an error tool result. Honors MCP's `{ isError: true, content }` shape.\n * Optional hint is appended on a new line so the LLM can react.\n */\nexport function errorResult(message: string, hint?: string): ToolResult {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return { content: [{ type: 'text', text }], isError: true };\n}\n\nexport interface ToolMetadata {\n title: string;\n description: string;\n inputSchema?: ZodRawShape;\n}\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n ctx: McpContext,\n meta: ToolMeta,\n) => Promise<unknown>;\n\n/**\n * Register a tool with the central error wrapper.\n *\n * The handler returns a plain value or void. The wrapper:\n * - wraps non-undefined returns in jsonResult()\n * - if the value already looks like a ToolResult (has `content`), passes through\n * - catches McpAuthError / McpUserError / McpInternalError / generic Error\n * - logs every error via ctx.logger.error\n */\nexport function registerTool<TArgs extends Record<string, unknown>>(\n server: McpServer,\n ctx: McpContext,\n name: string,\n metadata: ToolMetadata,\n handler: ToolHandler<TArgs>,\n): void {\n const sdkConfig = {\n title: metadata.title,\n description: metadata.description,\n ...(metadata.inputSchema ? { inputSchema: metadata.inputSchema } : {}),\n };\n\n // The MCP SDK's registerTool signature is `(name, config, handler)`. The\n // handler arity depends on whether inputSchema is present (1-arg without,\n // 2-arg with). We accept a unified handler shape and dispatch at runtime.\n // The SDK's typing is strict and conditional on the inputSchema generic;\n // bypass with a cast since runtime acceptance is unconditional.\n const wrapped = async (...callbackArgs: unknown[]): Promise<ToolResult> => {\n const hasArgs = callbackArgs.length === 2;\n const args = (hasArgs ? callbackArgs[0] : {}) as TArgs;\n const extra = (hasArgs ? callbackArgs[1] : callbackArgs[0]) as\n | { _meta?: { progressToken?: string | number } }\n | undefined;\n\n const progressToken = extra?._meta?.progressToken;\n const meta: ToolMeta = progressToken !== undefined ? { progressToken } : {};\n\n try {\n const result = await handler(args, ctx, meta);\n if (isToolResult(result)) return result;\n if (result === undefined) return textResult('OK');\n return jsonResult(result);\n } catch (error) {\n return mapErrorToResult(error, ctx, name);\n }\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (server as any).registerTool(name, sdkConfig, wrapped);\n}\n\nfunction isToolResult(value: unknown): value is ToolResult {\n return (\n !!value &&\n typeof value === 'object' &&\n 'content' in value &&\n Array.isArray((value as ToolResult).content)\n );\n}\n\nfunction mapErrorToResult(error: unknown, ctx: McpContext, toolName: string): ToolResult {\n if (error instanceof McpAuthError) {\n ctx.logger.warn(`${toolName}: auth required`, { message: error.message });\n return errorResult(error.message, error.hint);\n }\n if (error instanceof McpUserError) {\n ctx.logger.info(`${toolName}: user error`, { message: error.message });\n return errorResult(error.message, error.hint);\n }\n if (error instanceof McpInternalError) {\n ctx.logger.error(`${toolName}: internal error`, {\n message: error.message,\n cause: stringifyCause(error.cause),\n });\n return errorResult(`Internal error in ${toolName}.`);\n }\n const message = error instanceof Error ? error.message : String(error);\n ctx.logger.error(`${toolName}: unhandled error`, { message });\n return errorResult(`${toolName}: ${message}`);\n}\n\nfunction stringifyCause(cause: unknown): string | undefined {\n if (cause === undefined || cause === null) return undefined;\n if (cause instanceof Error) return cause.message;\n try {\n return JSON.stringify(cause);\n } catch {\n return String(cause);\n }\n}\n","/**\n * Tool / resource / prompt naming helpers.\n *\n * Mandatory product prefix avoids collisions when Claude Desktop runs\n * multiple MCP servers concurrently (typical setup is ~6).\n *\n * Tool names are capped at 63 characters — Claude Desktop pre-1.x\n * truncated at 64 in some versions.\n */\n\nimport { McpInternalError } from './errors.js';\n\nconst MAX_TOOL_NAME_LENGTH = 63;\n\nfunction assertSafeName(name: string, kind: 'tool' | 'resource' | 'prompt'): string {\n if (kind === 'tool' && name.length > MAX_TOOL_NAME_LENGTH) {\n throw new McpInternalError(\n `Tool name '${name}' exceeds ${MAX_TOOL_NAME_LENGTH} characters (some MCP clients truncate at 64).`,\n );\n }\n return name;\n}\n\n/**\n * Build a tool name. Format: `<productName>_<...parts>` (snake_case).\n * Example: mcpToolName('vibecontrols', 'vibes', 'list') -> 'vibecontrols_vibes_list'\n */\nexport function mcpToolName(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpToolName: productName is required');\n }\n const name = [productName, ...parts].filter(Boolean).join('_');\n return assertSafeName(name, 'tool');\n}\n\n/**\n * Build a resource URI. Format: `<productName>://<...parts>`.\n * Example: mcpResourceUri('vibecontrols', 'schema') -> 'vibecontrols://schema'\n */\nexport function mcpResourceUri(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpResourceUri: productName is required');\n }\n return `${productName}://${parts.filter(Boolean).join('/')}`;\n}\n\n/**\n * Build a prompt name. Format: `<productName>-<...parts>` (kebab-case).\n * Example: mcpPromptName('vibecontrols', 'setup') -> 'vibecontrols-setup'\n */\nexport function mcpPromptName(productName: string, ...parts: string[]): string {\n if (!productName) {\n throw new McpInternalError('mcpPromptName: productName is required');\n }\n return [productName, ...parts].filter(Boolean).join('-');\n}\n\nexport const TOOL_NAME_LIMIT = MAX_TOOL_NAME_LENGTH;\n","export const LIST_EXPORT_JOBS = `\n query ListExportJobs($context: ContextInput!, $filter: ExportJobFilterInput, $pagination: ExportPaginationInput) {\n listExportJobs(context: $context, filter: $filter, pagination: $pagination) {\n edges { node {\n id name status progress totalEntities processedEntities\n startedAt completedAt downloadUrl downloadExpiresAt\n } }\n pageInfo { totalCount hasNextPage }\n }\n }\n`;\n\nexport const GET_EXPORT_JOB = `\n query GetExportJob($context: ContextInput, $id: ID!) {\n getExportJob(context: $context, id: $id) {\n id name status progress\n downloadUrl downloadExpiresAt totalSizeBytes\n }\n }\n`;\n\nexport const CREATE_EXPORT_JOB = `\n mutation CreateExportJob($context: ContextInput!, $input: CreateExportJobInput!) {\n createExportJob(context: $context, input: $input) {\n id status progress entityTypes\n }\n }\n`;\n\nexport const LIST_EXPORT_TEMPLATES = `\n query ListExportTemplates($context: ContextInput!, $pagination: ExportPaginationInput) {\n listExportTemplates(context: $context, pagination: $pagination) {\n edges { node { id name entityTypes format includeMedia includeMetadata } }\n pageInfo { totalCount }\n }\n }\n`;\n\nexport const GET_EXPORT_TEMPLATE = `\n query GetExportTemplate($context: ContextInput, $id: ID!) {\n getExportTemplate(context: $context, id: $id) {\n id name entityTypes format\n }\n }\n`;\n\nexport const CANCEL_EXPORT_JOB = `\n mutation CancelExportJob($context: ContextInput, $id: ID!) {\n cancelExportJob(context: $context, id: $id) { id status progress }\n }\n`;\n\nexport const DELETE_EXPORT_JOB = `\n mutation DeleteExportJob($context: ContextInput, $id: ID!) {\n deleteExportJob(context: $context, id: $id)\n }\n`;\n\nexport const RETRY_EXPORT_JOB = `\n mutation RetryExportJob($context: ContextInput, $id: ID!) {\n retryExportJob(context: $context, id: $id) { id status progress }\n }\n`;\n\nexport const CREATE_EXPORT_TEMPLATE = `\n mutation CreateExportTemplate($context: ContextInput, $input: CreateExportTemplateInput!) {\n createExportTemplate(context: $context, input: $input) {\n id name entityTypes format includeMedia includeMetadata\n }\n }\n`;\n\nexport const UPDATE_EXPORT_TEMPLATE = `\n mutation UpdateExportTemplate(\n $context: ContextInput\n $id: ID!\n $input: UpdateExportTemplateInput!\n ) {\n updateExportTemplate(context: $context, id: $id, input: $input) {\n id name entityTypes format includeMedia includeMetadata isDefault\n }\n }\n`;\n\nexport const DELETE_EXPORT_TEMPLATE = `\n mutation DeleteExportTemplate($context: ContextInput, $id: ID!) {\n deleteExportTemplate(context: $context, id: $id)\n }\n`;\n\nexport const GET_AVAILABLE_EXPORT_ENTITIES = `\n query GetAvailableExportEntities(\n $context: ContextInput!\n $pagination: ExportPaginationInput\n ) {\n getAvailableExportEntities(context: $context, pagination: $pagination) {\n edges {\n node {\n entityType displayName description enabled\n supportsDateRange supportsMediaExport estimatedSize\n }\n }\n pageInfo { totalCount }\n }\n }\n`;\n\nexport const GET_EXPORT_PART = `\n query GetExportPart($context: ContextInput, $id: ID!) {\n getExportPart(context: $context, id: $id) {\n id jobId partNumber fileName fileId sizeBytes checksum\n downloadUrl downloadExpiresAt\n }\n }\n`;\n","/**\n * Export MCP tools — export jobs lifecycle, templates, download.\n * Surface mirrors cli-sdk/src/modules/export/commands.ts.\n */\n\nimport { writeFile } from 'fs/promises';\nimport { z } from 'zod';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { jsonResult, errorResult, mcpToolName, type McpContext } from '../../core/index.js';\nimport * as ops from './operations.js';\n\ninterface JobNode {\n id: string;\n name?: string;\n status?: string;\n progress?: number;\n totalEntities?: number;\n processedEntities?: number;\n startedAt?: string;\n completedAt?: string;\n downloadUrl?: string;\n downloadExpiresAt?: string;\n}\n\ninterface TemplateNode {\n id: string;\n name?: string;\n entityTypes?: string[];\n format?: string;\n includeMedia?: boolean;\n includeMetadata?: boolean;\n isDefault?: boolean;\n}\n\ninterface AvailableEntityNode {\n entityType: string;\n displayName: string;\n description?: string;\n enabled: boolean;\n supportsDateRange: boolean;\n supportsMediaExport: boolean;\n estimatedSize?: string;\n}\n\ninterface PartNode {\n id: string;\n jobId: string;\n partNumber: number;\n fileName: string;\n fileId?: string;\n sizeBytes: string;\n checksum?: string;\n downloadUrl?: string;\n downloadExpiresAt?: string;\n}\n\nfunction readWorkspaceContext(ctx: McpContext): { workspaceId: string } | null {\n const auth = ctx.auth.read();\n if (!auth?.workspaceId) return null;\n return { workspaceId: auth.workspaceId };\n}\n\nconst ExportFormatEnum = z.enum(['JSON', 'CSV', 'ZIP']);\n\nexport function registerExportTools(\n server: McpServer,\n ctx: McpContext,\n track: (n: string) => string,\n): void {\n // ── Jobs ────────────────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_list')),\n {\n title: 'List Export Jobs',\n description: 'List export jobs in the active workspace.',\n inputSchema: {\n status: z.string().optional().describe('Filter by status (will be uppercased)'),\n limit: z.number().optional().describe('Page size (default 50)'),\n },\n },\n async ({ status, limit }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const filter: Record<string, unknown> = {};\n if (status !== undefined) filter.status = status.toUpperCase();\n const data = await ctx.gql.workspace.request<{\n listExportJobs: {\n edges: Array<{ node: JobNode }>;\n pageInfo: { totalCount: number; hasNextPage: boolean };\n };\n }>(ops.LIST_EXPORT_JOBS, {\n context,\n filter: Object.keys(filter).length > 0 ? filter : undefined,\n pagination: { first: limit ?? 50 },\n });\n return jsonResult({\n items: data.listExportJobs.edges.map((e) => e.node),\n pageInfo: data.listExportJobs.pageInfo,\n });\n } catch (error) {\n ctx.logger.error('export_jobs_list failed', { error: String(error) });\n return errorResult(\n `Failed to list export jobs: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_get')),\n {\n title: 'Get Export Job',\n description: 'Get an export job by ID.',\n inputSchema: { id: z.string().describe('Export job ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportJob: JobNode | null }>(\n ops.GET_EXPORT_JOB,\n { context, id },\n );\n if (!data.getExportJob) return errorResult(`Export job ${id} not found`);\n return jsonResult(data.getExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_get failed', { error: String(error) });\n return errorResult(\n `Failed to get export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_create')),\n {\n title: 'Create Export Job',\n description: 'Create an export job for one or more entity types.',\n inputSchema: {\n name: z.string().describe('Job name'),\n entityTypes: z.array(z.string()).describe('Entity types to export'),\n format: ExportFormatEnum.optional().describe('Output format (default JSON)'),\n includeMedia: z.boolean().optional().describe('Include media files (default false)'),\n includeMetadata: z.boolean().optional().describe('Include metadata (default true)'),\n from: z.string().optional().describe('Date range start (ISO)'),\n to: z.string().optional().describe('Date range end (ISO)'),\n },\n },\n async ({ name, entityTypes, format, includeMedia, includeMetadata, from, to }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const input: Record<string, unknown> = {\n name,\n entityTypes,\n format: format ?? 'JSON',\n includeMedia: includeMedia === true,\n includeMetadata: includeMetadata !== false,\n };\n if (from !== undefined) input.dateRangeStart = from;\n if (to !== undefined) input.dateRangeEnd = to;\n const data = await ctx.gql.workspace.request<{ createExportJob: JobNode }>(\n ops.CREATE_EXPORT_JOB,\n { context, input },\n );\n return jsonResult(data.createExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_create failed', { error: String(error) });\n return errorResult(\n `Failed to create export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_download')),\n {\n title: 'Download Export Job',\n description: 'Download a completed export job to a local file path.',\n inputSchema: {\n jobId: z.string().describe('Export job ID'),\n to: z.string().describe('Local file path to write'),\n },\n },\n async ({ jobId, to }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportJob: JobNode | null }>(\n ops.GET_EXPORT_JOB,\n { context, id: jobId },\n );\n if (!data.getExportJob) return errorResult(`Export job ${jobId} not found`);\n const url = data.getExportJob.downloadUrl;\n if (!url) {\n return errorResult(\n `Job ${jobId} has no downloadUrl yet (status=${data.getExportJob.status ?? 'UNKNOWN'}).`,\n );\n }\n const res = await fetch(url);\n if (!res.ok) {\n return errorResult(`Download failed: ${res.status} ${res.statusText}`);\n }\n const buf = Buffer.from(await res.arrayBuffer());\n await writeFile(to, buf);\n return jsonResult({ status: 'success', path: to, bytes: buf.length });\n } catch (error) {\n ctx.logger.error('export_download failed', { error: String(error) });\n return errorResult(\n `Failed to download export: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Templates ───────────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_list')),\n {\n title: 'List Export Templates',\n description: 'List export templates in the active workspace.',\n inputSchema: {\n limit: z.number().optional().describe('Page size (default 50)'),\n },\n },\n async ({ limit }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{\n listExportTemplates: {\n edges: Array<{ node: TemplateNode }>;\n pageInfo: { totalCount: number };\n };\n }>(ops.LIST_EXPORT_TEMPLATES, {\n context,\n pagination: { first: limit ?? 50 },\n });\n return jsonResult({\n items: data.listExportTemplates.edges.map((e) => e.node),\n pageInfo: data.listExportTemplates.pageInfo,\n });\n } catch (error) {\n ctx.logger.error('export_templates_list failed', { error: String(error) });\n return errorResult(\n `Failed to list export templates: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_get')),\n {\n title: 'Get Export Template',\n description: 'Get an export template by ID.',\n inputSchema: { id: z.string().describe('Template ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportTemplate: TemplateNode | null }>(\n ops.GET_EXPORT_TEMPLATE,\n { context, id },\n );\n if (!data.getExportTemplate) return errorResult(`Template ${id} not found`);\n return jsonResult(data.getExportTemplate);\n } catch (error) {\n ctx.logger.error('export_templates_get failed', { error: String(error) });\n return errorResult(\n `Failed to get export template: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Jobs: cancel / delete / retry ───────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_cancel')),\n {\n title: 'Cancel Export Job',\n description: 'Cancel a running export job.',\n inputSchema: { id: z.string().describe('Export job ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ cancelExportJob: JobNode }>(\n ops.CANCEL_EXPORT_JOB,\n { context, id },\n );\n return jsonResult(data.cancelExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_cancel failed', { error: String(error) });\n return errorResult(\n `Failed to cancel export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_delete')),\n {\n title: 'Delete Export Job',\n description: 'Delete an export job.',\n inputSchema: { id: z.string().describe('Export job ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ deleteExportJob: boolean }>(\n ops.DELETE_EXPORT_JOB,\n { context, id },\n );\n return jsonResult({ deleted: data.deleteExportJob, id });\n } catch (error) {\n ctx.logger.error('export_jobs_delete failed', { error: String(error) });\n return errorResult(\n `Failed to delete export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_jobs_retry')),\n {\n title: 'Retry Export Job',\n description: 'Retry a failed export job.',\n inputSchema: { id: z.string().describe('Export job ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ retryExportJob: JobNode }>(\n ops.RETRY_EXPORT_JOB,\n { context, id },\n );\n return jsonResult(data.retryExportJob);\n } catch (error) {\n ctx.logger.error('export_jobs_retry failed', { error: String(error) });\n return errorResult(\n `Failed to retry export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Polling check (replacement for the GraphQL subscription) ───────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_job_check')),\n {\n title: 'Check Export Job Progress',\n description:\n 'Polling tool that returns the current status/progress of an export job. ' +\n 'Designed for AI agents to call repeatedly in lieu of the GraphQL ' +\n '`exportJobProgress` subscription (no MCP transport for live streams).',\n inputSchema: { jobId: z.string().describe('Export job ID') },\n },\n async ({ jobId }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportJob: JobNode | null }>(\n ops.GET_EXPORT_JOB,\n { context, id: jobId },\n );\n if (!data.getExportJob) return errorResult(`Export job ${jobId} not found`);\n const terminal = ['COMPLETED', 'FAILED', 'CANCELLED', 'EXPIRED', 'DELETED'];\n return jsonResult({\n ...data.getExportJob,\n isTerminal: terminal.includes(String(data.getExportJob.status ?? '')),\n });\n } catch (error) {\n ctx.logger.error('export_job_check failed', { error: String(error) });\n return errorResult(\n `Failed to check export job: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Templates: create / update / delete ─────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_create')),\n {\n title: 'Create Export Template',\n description: 'Create a reusable export template.',\n inputSchema: {\n name: z.string().describe('Template name'),\n entityTypes: z.array(z.string()).describe('Entity types to include'),\n description: z.string().optional(),\n format: ExportFormatEnum.optional(),\n includeMedia: z.boolean().optional(),\n includeMetadata: z.boolean().optional(),\n },\n },\n async ({ name, entityTypes, description, format, includeMedia, includeMetadata }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const input: Record<string, unknown> = {\n name,\n entityTypes,\n format: format ?? 'JSON',\n includeMedia: includeMedia === true,\n includeMetadata: includeMetadata !== false,\n };\n if (description !== undefined) input.description = description;\n const data = await ctx.gql.workspace.request<{ createExportTemplate: TemplateNode }>(\n ops.CREATE_EXPORT_TEMPLATE,\n { context, input },\n );\n return jsonResult(data.createExportTemplate);\n } catch (error) {\n ctx.logger.error('export_templates_create failed', { error: String(error) });\n return errorResult(\n `Failed to create export template: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_update')),\n {\n title: 'Update Export Template',\n description: 'Update an existing export template. Only supplied fields are changed.',\n inputSchema: {\n id: z.string().describe('Template ID'),\n name: z.string().optional(),\n description: z.string().optional(),\n entityTypes: z.array(z.string()).optional(),\n format: ExportFormatEnum.optional(),\n includeMedia: z.boolean().optional(),\n includeMetadata: z.boolean().optional(),\n isDefault: z.boolean().optional(),\n },\n },\n async ({\n id,\n name,\n description,\n entityTypes,\n format,\n includeMedia,\n includeMetadata,\n isDefault,\n }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const input: Record<string, unknown> = {};\n if (name !== undefined) input.name = name;\n if (description !== undefined) input.description = description;\n if (entityTypes !== undefined) input.entityTypes = entityTypes;\n if (format !== undefined) input.format = format;\n if (includeMedia !== undefined) input.includeMedia = includeMedia;\n if (includeMetadata !== undefined) input.includeMetadata = includeMetadata;\n if (isDefault !== undefined) input.isDefault = isDefault;\n const data = await ctx.gql.workspace.request<{ updateExportTemplate: TemplateNode }>(\n ops.UPDATE_EXPORT_TEMPLATE,\n { context, id, input },\n );\n return jsonResult(data.updateExportTemplate);\n } catch (error) {\n ctx.logger.error('export_templates_update failed', { error: String(error) });\n return errorResult(\n `Failed to update export template: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_templates_delete')),\n {\n title: 'Delete Export Template',\n description: 'Delete an export template.',\n inputSchema: { id: z.string().describe('Template ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ deleteExportTemplate: boolean }>(\n ops.DELETE_EXPORT_TEMPLATE,\n { context, id },\n );\n return jsonResult({ deleted: data.deleteExportTemplate, id });\n } catch (error) {\n ctx.logger.error('export_templates_delete failed', { error: String(error) });\n return errorResult(\n `Failed to delete export template: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n // ── Available entities + parts ──────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_entities_list')),\n {\n title: 'List Available Export Entities',\n description: 'List the entity types available for export in the active workspace.',\n inputSchema: {\n limit: z.number().optional().describe('Page size (default 50)'),\n },\n },\n async ({ limit }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{\n getAvailableExportEntities: {\n edges: Array<{ node: AvailableEntityNode }>;\n pageInfo: { totalCount: number };\n };\n }>(ops.GET_AVAILABLE_EXPORT_ENTITIES, {\n context,\n pagination: { first: limit ?? 50 },\n });\n return jsonResult({\n items: data.getAvailableExportEntities.edges.map((e) => e.node),\n pageInfo: data.getAvailableExportEntities.pageInfo,\n });\n } catch (error) {\n ctx.logger.error('export_entities_list failed', { error: String(error) });\n return errorResult(\n `Failed to list available export entities: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'export_parts_get')),\n {\n title: 'Get Export Part',\n description: 'Get an export part (a single chunk produced by a multi-part export job).',\n inputSchema: { id: z.string().describe('Export part ID') },\n },\n async ({ id }) => {\n try {\n const context = readWorkspaceContext(ctx);\n if (!context) {\n return errorResult('No workspace set. Run the auth workspace_set tool first.');\n }\n const data = await ctx.gql.workspace.request<{ getExportPart: PartNode | null }>(\n ops.GET_EXPORT_PART,\n { context, id },\n );\n if (!data.getExportPart) return errorResult(`Export part ${id} not found`);\n return jsonResult(data.getExportPart);\n } catch (error) {\n ctx.logger.error('export_parts_get failed', { error: String(error) });\n return errorResult(\n `Failed to get export part: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n );\n}\n","/**\n * Export module — workspace data export jobs and templates.\n * Surface mirrors cli-sdk/src/modules/export/.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { McpContext, McpModule, ModuleRegistration } from '../../core/index.js';\nimport { registerExportTools } from './tools.js';\n\nconst exportModule: McpModule = {\n id: 'export',\n version: '0.0.1',\n displayName: 'Export',\n dependsOn: ['auth'],\n capabilities: { tools: {} },\n\n register(server: McpServer, ctx: McpContext): ModuleRegistration {\n const tools: string[] = [];\n const track = (n: string): string => {\n tools.push(n);\n return n;\n };\n\n registerExportTools(server, ctx, track);\n\n return { tools, resources: [], prompts: [] };\n },\n};\n\nexport default exportModule;\n"]}