@burdenoff/mcp-libs 2026.1031.2 → 2026.1031.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/auth/index.cjs +1 -1
- package/dist/modules/auth/index.cjs.map +1 -1
- package/dist/modules/auth/index.js +1 -1
- package/dist/modules/auth/index.js.map +1 -1
- package/dist/modules/auth/operations.d.ts +2 -2
- package/dist/modules/billing/index.cjs +45 -19
- package/dist/modules/billing/index.cjs.map +1 -1
- package/dist/modules/billing/index.js +45 -19
- package/dist/modules/billing/index.js.map +1 -1
- package/dist/modules/billing/operations.d.ts +4 -4
- package/dist/modules/channels/index.cjs +0 -35
- package/dist/modules/channels/index.cjs.map +1 -1
- package/dist/modules/channels/index.js +0 -35
- package/dist/modules/channels/index.js.map +1 -1
- package/dist/modules/channels/operations.d.ts +0 -1
- package/dist/modules/conversations/index.cjs +6 -6
- package/dist/modules/conversations/index.cjs.map +1 -1
- package/dist/modules/conversations/index.js +6 -6
- package/dist/modules/conversations/index.js.map +1 -1
- package/dist/modules/conversations/operations.d.ts +1 -1
- package/dist/modules/files/index.cjs +421 -101
- package/dist/modules/files/index.cjs.map +1 -1
- package/dist/modules/files/index.js +412 -97
- package/dist/modules/files/index.js.map +1 -1
- package/dist/modules/files/operations.d.ts +9 -8
- package/dist/modules/files/tools.d.ts +2 -0
- package/dist/modules/products/index.cjs +1 -1
- package/dist/modules/products/index.cjs.map +1 -1
- package/dist/modules/products/index.js +1 -1
- package/dist/modules/products/index.js.map +1 -1
- package/dist/modules/products/operations.d.ts +1 -1
- package/dist/modules/rbac/index.cjs +0 -64
- package/dist/modules/rbac/index.cjs.map +1 -1
- package/dist/modules/rbac/index.js +0 -64
- package/dist/modules/rbac/index.js.map +1 -1
- package/dist/modules/rbac/operations.d.ts +0 -2
- package/dist/modules/scheduler/index.cjs +4 -4
- package/dist/modules/scheduler/index.cjs.map +1 -1
- package/dist/modules/scheduler/index.js +4 -4
- package/dist/modules/scheduler/index.js.map +1 -1
- package/dist/modules/scheduler/operations.d.ts +3 -3
- package/dist/modules/tags/index.cjs +454 -48
- package/dist/modules/tags/index.cjs.map +1 -1
- package/dist/modules/tags/index.js +443 -42
- package/dist/modules/tags/index.js.map +1 -1
- package/dist/modules/tags/operations.d.ts +10 -6
- package/dist/modules/tags/tools.d.ts +1 -1
- package/dist/modules/vibecontrols/index.cjs +8 -8
- package/dist/modules/vibecontrols/index.cjs.map +1 -1
- package/dist/modules/vibecontrols/index.js +8 -8
- package/dist/modules/vibecontrols/index.js.map +1 -1
- package/dist/modules/workspaces/index.cjs +235 -5
- package/dist/modules/workspaces/index.cjs.map +1 -1
- package/dist/modules/workspaces/index.js +224 -6
- package/dist/modules/workspaces/index.js.map +1 -1
- package/dist/modules/workspaces/operations.d.ts +2 -2
- package/dist/modules/workspaces/prompts.d.ts +3 -0
- package/dist/modules/workspaces/resources.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/errors.ts","../../../src/core/tool-name.ts","../../../src/core/result.ts","../../../src/modules/files/tools.ts","../../../src/modules/files/index.ts"],"names":["z"],"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;;;AC1BA,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,oBAA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UST 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 * 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\n/**\n * Name-based hint heuristics for MCP `annotations` (readOnlyHint /\n * destructiveHint). Used by tool-governance.ts to auto-fill annotations for\n * the fleet of product modules that call `server.registerTool` directly\n * (bypassing the `registerTool()` core helper) and so never set them\n * explicitly today (BOFF-3903). Deliberately conservative — matched against\n * whole `_`-delimited segments so e.g. `timeentries_delete` and\n * `pomodoro_delete_goal` match, but a hypothetical `undeletable_check`\n * would not.\n *\n * The destructive verb set covers more than `delete`: stopping, killing or\n * terminating a running process, revoking or rotating a credential/share,\n * resetting settings and removing/purging/uninstalling are all actions an\n * MCP client must not auto-run without the user's intent (VC/FG parity G57 —\n * e.g. `vibecontrols_sessions_kill`, `vibecontrols_tunnels_rotate_credentials`\n * were previously reported as non-destructive).\n *\n * A module can always override the inference by passing an explicit\n * `annotations` object to `registerTool()` / `server.registerTool()` — do\n * that for the rare verb match that is harmless (e.g. a typing indicator's\n * `typing_stop`).\n */\nexport const DESTRUCTIVE_NAME_VERBS = [\n 'delete',\n 'destroy',\n 'erase',\n 'kill',\n 'purge',\n 'remove',\n 'reset',\n 'revoke',\n 'rotate',\n 'stop',\n 'terminate',\n 'uninstall',\n 'wipe',\n] as const;\nconst DESTRUCTIVE_NAME_SEGMENT = new RegExp(\n `(?:^|_)(?:${DESTRUCTIVE_NAME_VERBS.join('|')})(?:_|$)`,\n 'i',\n);\nconst READ_ONLY_NAME_SEGMENT = /(?:^|_)(?:list|get|search|check|read|count|stats|by_date)(?:_|$)/i;\n\n/** True when a tool name looks destructive (irreversibly deletes data) by naming convention. */\nexport function inferDestructiveHint(toolName: string): boolean {\n return DESTRUCTIVE_NAME_SEGMENT.test(toolName);\n}\n\n/**\n * True when a tool name looks read-only by naming convention. Never true for\n * a name that also looks destructive (a tool can't be both).\n */\nexport function inferReadOnlyHint(toolName: string): boolean {\n return !inferDestructiveHint(toolName) && READ_ONLY_NAME_SEGMENT.test(toolName);\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';\nimport type { ToolAnnotations } from './tool-governance.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 * Explicit MCP annotations (readOnlyHint / destructiveHint / ...). Optional\n * — when omitted, `wrapServerWithToolGovernance` (applied centrally in\n * `createMcpServer`) infers them from the tool name. Set this to override\n * the inference for a tool whose name doesn't match the naming convention.\n */\n annotations?: ToolAnnotations;\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 ...(metadata.annotations ? { annotations: metadata.annotations } : {}),\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 } } | 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","import { z } from 'zod';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { errorResult, mcpToolName, type McpContext } from '../../core/index.js';\n\ntype StubInputSchema = Record<string, z.ZodTypeAny>;\nfunction stubbedTool(\n server: McpServer,\n toolName: string,\n title: string,\n description: string,\n featureNote: string,\n inputSchema: StubInputSchema,\n altSuggestions: string[],\n): void {\n server.registerTool(\n toolName,\n {\n title,\n description: `${description} [STUB]`,\n inputSchema,\n },\n async () =>\n errorResult(\n `[stubbed] ${featureNote} Use ${altSuggestions.join(', ')} instead. The tool remains registered so callers receive a meaningful response instead of a schema-validation error.`,\n ),\n );\n}\n\nexport function registerFilesTools(\n server: McpServer,\n ctx: McpContext,\n track: (n: string) => string,\n): void {\n // BOFF-8192: `Query.files` is gone on the live alpha gateway;\n // none of the 11 files tools are reachable. Stubs so callers get a\n // clean error rather than a schema-validation failure, and the\n // per-call wiring stays in place for the day alpha re-exposes the\n // files surface.\n const featureNote =\n 'Live alpha removed the `files` query family (workspace files are moving to a per-workspace service).';\n const alts = [\n 'the next alpha release that re-exposes the files surface',\n 'the SDK files API (which the MCP will mirror once it lands)',\n ];\n\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_browse')),\n 'Browse Folder',\n 'Browse a workspace folder. Returns subfolders and paginated files.',\n featureNote,\n { folderId: z.string().optional().describe('Folder ID (omit to browse root)') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_list')),\n 'List Files',\n 'List files in a workspace, optionally scoped to a folder.',\n featureNote,\n { folderId: z.string().optional().describe('Folder ID (omit to list workspace root)') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_get')),\n 'Get File',\n 'Get a single file by ID. Returns the file record or an error if not found.',\n featureNote,\n { id: z.string().describe('File ID') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_download')),\n 'Get File Download URL',\n 'Resolve a server-signed presigned download URL for a file.',\n featureNote,\n { id: z.string().describe('File ID') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_upload')),\n 'Upload File',\n 'Single-shot file upload mirroring the SDK files.upload contract (s3Bucket/s3Key/size pre-resolved). For raw-byte uploads from MCP callers, prefer files_upload_initiate + files_upload_complete which use presigned URLs.',\n featureNote,\n { name: z.string().describe('Display filename including extension') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_upload_initiate')),\n 'Initiate File Upload',\n 'Initiate a multipart upload session. Returns presigned URL(s) the caller must PUT bytes to, plus a sessionId to use with files_upload_complete.',\n featureNote,\n { fileName: z.string().describe('File name including extension') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_upload_complete')),\n 'Complete File Upload',\n 'Complete an in-flight upload session previously initiated by files_upload_initiate.',\n featureNote,\n { sessionId: z.string().describe('Session ID from files_upload_initiate') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_share')),\n 'Share File',\n 'Create a share for a file (mirrors SDK files.share).',\n featureNote,\n { fileId: z.string().describe('File ID to share') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_share_create')),\n 'Create File Share',\n 'Create a shareable link for a file with optional access controls.',\n featureNote,\n { fileId: z.string().describe('File ID to share') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_share_revoke')),\n 'Revoke File Share',\n 'Revoke a previously created file share by ID.',\n featureNote,\n { id: z.string().describe('Share ID to revoke') },\n alts,\n );\n stubbedTool(\n server,\n track(mcpToolName(ctx.productName, 'files_revoke')),\n 'Revoke File Share',\n 'Revoke an existing file share by ID (mirrors SDK files.shareApi.revoke).',\n featureNote,\n { id: z.string().describe('Share ID') },\n alts,\n );\n}\n","/**\n * Files module — workspace file browse, upload (initiate/complete), and share\n * (<product>_files_{browse,upload_initiate,upload_complete,share_create,share_revoke}).\n *\n * Backend: ~/products/wspace/files/wspace-files-svc/.\n * Ported from cli-sdk/src/modules/files/.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { McpContext, McpModule, ModuleRegistration } from '../../core/index.js';\nimport { registerFilesTools } from './tools.js';\n\nconst filesModule: McpModule = {\n id: 'files',\n version: '0.0.1',\n displayName: 'Files',\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 registerFilesTools(server, ctx, track);\n\n return { tools, resources: [], prompts: [] };\n },\n};\n\nexport default filesModule;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/errors.ts","../../../src/core/tool-name.ts","../../../src/core/result.ts","../../../src/modules/files/operations.ts","../../../src/modules/files/tools.ts","../../../src/modules/files/index.ts"],"names":["message","z"],"mappings":";;;;;;;;;;;;AA8BO,IAAM,gBAAA,GAAN,cAA+B,KAAA,CAAM;AAAA,EACjB,KAAA;AAAA,EAEzB,WAAA,CAAYA,UAAiB,KAAA,EAAiB;AAC5C,IAAA,KAAA,CAAMA,QAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;AACZ,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF,CAAA;;;AC1BA,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;AAC3E,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,MAAM,IAAI,iBAAiB,sCAAsC,CAAA;AAAA,EACnE;AACA,EAAA,MAAM,IAAA,GAAO,CAAC,WAAA,EAAa,GAAG,KAAK,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAC7D,EAAA,OAAO,cAAA,CAAe,IAAY,CAAA;AACpC;;;ACOO,SAAS,UAAA,CAAW,MAAe,UAAA,EAAkD;AAC1F,EAAA,MAAM,MAAA,GAAqB;AAAA,IACzB,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,MAAA,E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AAAA,IACT,CAAA;AAEA,IAAA,kBAAA,CAAmB,MAAA,EAAQ,KAAK,KAAK,CAAA;AAErC,IAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,EAAC,EAAG,OAAA,EAAS,EAAC,EAAE;AAAA,EAC7C;AACF,CAAA;AAEA,IAAO,aAAA,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 * 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\n/**\n * Name-based hint heuristics for MCP `annotations` (readOnlyHint /\n * destructiveHint). Used by tool-governance.ts to auto-fill annotations for\n * the fleet of product modules that call `server.registerTool` directly\n * (bypassing the `registerTool()` core helper) and so never set them\n * explicitly today (BOFF-3903). Deliberately conservative — matched against\n * whole `_`-delimited segments so e.g. `timeentries_delete` and\n * `pomodoro_delete_goal` match, but a hypothetical `undeletable_check`\n * would not.\n *\n * The destructive verb set covers more than `delete`: stopping, killing or\n * terminating a running process, revoking or rotating a credential/share,\n * resetting settings and removing/purging/uninstalling are all actions an\n * MCP client must not auto-run without the user's intent (VC/FG parity G57 —\n * e.g. `vibecontrols_sessions_kill`, `vibecontrols_tunnels_rotate_credentials`\n * were previously reported as non-destructive).\n *\n * A module can always override the inference by passing an explicit\n * `annotations` object to `registerTool()` / `server.registerTool()` — do\n * that for the rare verb match that is harmless (e.g. a typing indicator's\n * `typing_stop`).\n */\nexport const DESTRUCTIVE_NAME_VERBS = [\n 'delete',\n 'destroy',\n 'erase',\n 'kill',\n 'purge',\n 'remove',\n 'reset',\n 'revoke',\n 'rotate',\n 'stop',\n 'terminate',\n 'uninstall',\n 'wipe',\n] as const;\nconst DESTRUCTIVE_NAME_SEGMENT = new RegExp(\n `(?:^|_)(?:${DESTRUCTIVE_NAME_VERBS.join('|')})(?:_|$)`,\n 'i',\n);\nconst READ_ONLY_NAME_SEGMENT = /(?:^|_)(?:list|get|search|check|read|count|stats|by_date)(?:_|$)/i;\n\n/** True when a tool name looks destructive (irreversibly deletes data) by naming convention. */\nexport function inferDestructiveHint(toolName: string): boolean {\n return DESTRUCTIVE_NAME_SEGMENT.test(toolName);\n}\n\n/**\n * True when a tool name looks read-only by naming convention. Never true for\n * a name that also looks destructive (a tool can't be both).\n */\nexport function inferReadOnlyHint(toolName: string): boolean {\n return !inferDestructiveHint(toolName) && READ_ONLY_NAME_SEGMENT.test(toolName);\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';\nimport type { ToolAnnotations } from './tool-governance.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 * Explicit MCP annotations (readOnlyHint / destructiveHint / ...). Optional\n * — when omitted, `wrapServerWithToolGovernance` (applied centrally in\n * `createMcpServer`) infers them from the tool name. Set this to override\n * the inference for a tool whose name doesn't match the naming convention.\n */\n annotations?: ToolAnnotations;\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 ...(metadata.annotations ? { annotations: metadata.annotations } : {}),\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 } } | 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 * Files module GraphQL operations against wspace-files-svc on the workspace\n * gateway. Every document is validated against the composed supergraph by\n * tests/unit/platform-supergraph-contract.test.ts (BOFF-4413).\n */\n\nconst FILE_FIELDS = `\n id name description workspaceId folderId\n mimeType extension size\n status visibility starred downloadCount viewCount sha256Hash\n uploadedById createdAt updatedAt tags\n`;\n\nexport const LIST_FILES = `\n query GetFiles($folderId: ID, $filter: FileFilterInput, $pagination: PaginationInput) {\n getFiles(folderId: $folderId, filter: $filter, pagination: $pagination) {\n files { ${FILE_FIELDS} }\n total page limit hasMore\n }\n }\n`;\n\nexport const GET_FILE = `\n query GetFile($id: ID!) {\n getFile(id: $id) { ${FILE_FIELDS} }\n }\n`;\n\nexport const GET_FOLDER = `\n query GetFolder($id: ID!) {\n getFolder(id: $id) {\n id name description path level parentFolderId visibility starred\n filesCount subfoldersCount createdAt updatedAt\n }\n }\n`;\n\nexport const LIST_FOLDERS = `\n query GetFolders($filter: FolderFilterInput, $pagination: PaginationInput) {\n getFolders(filter: $filter, pagination: $pagination) {\n folders { id name path level parentFolderId filesCount subfoldersCount updatedAt }\n total page limit hasMore\n }\n }\n`;\n\nexport const GET_FILE_DOWNLOAD_URL = `\n query GetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }\n`;\n\nexport const UPLOAD_FILE = `\n mutation UploadFile($input: UploadFileInput!) {\n uploadFile(input: $input) {\n file { ${FILE_FIELDS} }\n uploadProgress\n message\n }\n }\n`;\n\nexport const INITIATE_UPLOAD = `\n mutation InitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) {\n session { id fileName fileSize status expiresAt uploadType partSize totalParts }\n uploadUrl\n presignedUrls { partNumber url expiresAt }\n multipartUploadId\n }\n }\n`;\n\nexport const COMPLETE_UPLOAD = `\n mutation CompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) {\n fileId\n message\n file { ${FILE_FIELDS} }\n }\n }\n`;\n\nexport const CREATE_SHARE = `\n mutation CreateShare($input: FileCreateShareInput!) {\n createShare(input: $input) {\n id fileId token shareType accessLevel expiresAt requiresPassword\n invitedEmail invitedUserIds downloadCount maxDownloads createdAt\n }\n }\n`;\n\nexport const REVOKE_SHARE = `\n mutation RevokeShare($id: ID!) {\n revokeShare(id: $id) {\n id fileId revokedAt revokedBy\n }\n }\n`;\n","/**\n * Files MCP tools — browse, read, download, upload and share workspace files\n * through wspace-files-svc on the workspace gateway.\n *\n * The workspace comes from the gateway headers bound by\n * <product>_auth_select_workspace.\n *\n * History: BOFF-8192 stubbed this module on the belief that the files\n * surface had been removed. It had not — `getFiles`, `getFile`,\n * `getFolder(s)`, `getFileDownloadUrl`, `initiateUpload`, `completeUpload`,\n * `createShare` and `revokeShare` are all live — so BOFF-4413 restored the\n * real tools and pinned every document to the supergraph\n * (tests/unit/platform-supergraph-contract.test.ts).\n *\n * The MCP server cannot read or stream local bytes. Uploads therefore use\n * the presigned flow: files_upload_initiate returns URL(s) the caller PUTs the\n * bytes to, then files_upload_complete registers the file.\n */\n\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\n/** S3 caps presigned GET URLs at 7 days; larger values fail server-side. */\nexport const MAX_DOWNLOAD_URL_TTL_SECONDS = 604_800;\n\nconst VisibilityEnum = z.enum(['PRIVATE', 'TEAM', 'WORKSPACE', 'PUBLIC']);\nconst ShareAccessEnum = z.enum(['VIEW', 'COMMENT', 'DOWNLOAD', 'EDIT']);\nconst ShareTypeEnum = z.enum(['PUBLIC_LINK', 'EMAIL_INVITE', 'GROUP_SHARE']);\n\ninterface FileListRow {\n files: Array<Record<string, unknown>>;\n total: number;\n page: number;\n limit: number;\n hasMore: boolean;\n}\n\ninterface FolderListRow {\n folders: Array<Record<string, unknown>>;\n total: number;\n hasMore: boolean;\n}\n\nfunction message(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction pagination(\n limit: number | undefined,\n offset: number | undefined,\n): { limit: number; offset: number } {\n return { limit: limit ?? 50, offset: offset ?? 0 };\n}\n\n/** `report.pdf` → `pdf`; names without a dot yield an empty extension. */\nexport function extensionOf(fileName: string): string {\n const dot = fileName.lastIndexOf('.');\n return dot > 0 && dot < fileName.length - 1 ? fileName.slice(dot + 1).toLowerCase() : '';\n}\n\nconst fileSizeSchema = z.number().int().positive().describe('File size in bytes');\n\nexport function registerFilesTools(\n server: McpServer,\n ctx: McpContext,\n track: (n: string) => string,\n): void {\n // ── Browse / read ───────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_browse')),\n {\n title: 'Browse Folder',\n description:\n 'Browse a folder of the current workspace: a page of its subfolders and a page of its files. Omit folderId to browse the workspace root. Returns { folder, folders, foldersTotal, foldersHasMore, files, total, hasMore }.',\n inputSchema: {\n folderId: z.string().optional().describe('Folder ID (omit for the root)'),\n limit: z.number().int().min(1).max(200).optional().describe('Files page size (default 50)'),\n offset: z.number().int().min(0).optional().describe('Files offset (default 0)'),\n folderLimit: z\n .number()\n .int()\n .min(1)\n .max(200)\n .optional()\n .describe('Subfolders page size (default 50)'),\n folderOffset: z.number().int().min(0).optional().describe('Subfolders offset (default 0)'),\n },\n },\n async ({ folderId, limit, offset, folderLimit, folderOffset }) => {\n try {\n const [folder, folders, files] = await Promise.all([\n folderId\n ? ctx.gql.workspace.request<{ getFolder: Record<string, unknown> | null }>(\n ops.GET_FOLDER,\n { id: folderId },\n )\n : Promise.resolve({ getFolder: null }),\n ctx.gql.workspace.request<{ getFolders: FolderListRow }>(ops.LIST_FOLDERS, {\n filter: { parentFolderId: folderId ?? null },\n pagination: pagination(folderLimit, folderOffset),\n }),\n ctx.gql.workspace.request<{ getFiles: FileListRow }>(ops.LIST_FILES, {\n folderId: folderId ?? null,\n pagination: pagination(limit, offset),\n }),\n ]);\n if (folderId && !folder.getFolder) return errorResult(`Folder ${folderId} not found`);\n return jsonResult({\n folder: folder.getFolder,\n folders: folders.getFolders.folders,\n foldersTotal: folders.getFolders.total,\n foldersHasMore: folders.getFolders.hasMore,\n files: files.getFiles.files,\n total: files.getFiles.total,\n hasMore: files.getFiles.hasMore,\n });\n } catch (error) {\n ctx.logger.error('files_browse failed', { error: String(error) });\n return errorResult(`Failed to browse folder: ${message(error)}`);\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_list')),\n {\n title: 'List Files',\n description:\n 'List files in the current workspace, optionally in one folder and filtered by MIME type, extension or starred. Returns { files, total, page, limit, hasMore }.',\n inputSchema: {\n folderId: z.string().optional().describe('Folder ID (omit for the root)'),\n mimeTypes: z.array(z.string()).optional().describe('Only these MIME types'),\n extensions: z.array(z.string()).optional().describe('Only these extensions (no dot)'),\n starred: z.boolean().optional().describe('Only starred files'),\n limit: z.number().int().min(1).max(200).optional().describe('Page size (default 50)'),\n offset: z.number().int().min(0).optional().describe('Offset (default 0)'),\n },\n },\n async ({ folderId, mimeTypes, extensions, starred, limit, offset }) => {\n try {\n const filter: Record<string, unknown> = {};\n if (mimeTypes !== undefined) filter.mimeTypes = mimeTypes;\n if (extensions !== undefined) filter.extensions = extensions;\n if (starred !== undefined) filter.starred = starred;\n const data = await ctx.gql.workspace.request<{ getFiles: FileListRow }>(ops.LIST_FILES, {\n folderId: folderId ?? null,\n filter: Object.keys(filter).length ? filter : undefined,\n pagination: pagination(limit, offset),\n });\n return jsonResult(data.getFiles);\n } catch (error) {\n ctx.logger.error('files_list failed', { error: String(error) });\n return errorResult(`Failed to list files: ${message(error)}`);\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_get')),\n {\n title: 'Get File',\n description: 'Get one file record (metadata, visibility, counters) by ID.',\n inputSchema: { id: z.string().describe('File ID') },\n },\n async ({ id }) => {\n try {\n const data = await ctx.gql.workspace.request<{ getFile: Record<string, unknown> | null }>(\n ops.GET_FILE,\n { id },\n );\n if (!data.getFile) return errorResult(`File ${id} not found`);\n return jsonResult(data.getFile);\n } catch (error) {\n ctx.logger.error('files_get failed', { error: String(error) });\n return errorResult(`Failed to get file: ${message(error)}`);\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_download')),\n {\n title: 'Get File Download URL',\n description:\n 'Return a short-lived presigned download URL for a file. The MCP server does not stream bytes; fetch the URL out of band. Returns { url, expiresIn }.',\n inputSchema: {\n id: z.string().describe('File ID'),\n expiresIn: z\n .number()\n .int()\n .min(60)\n .max(MAX_DOWNLOAD_URL_TTL_SECONDS)\n .optional()\n .describe('URL lifetime in seconds (60 to 604800; server default when omitted)'),\n },\n },\n async ({ id, expiresIn }) => {\n try {\n const data = await ctx.gql.workspace.request<{ getFileDownloadUrl: string }>(\n ops.GET_FILE_DOWNLOAD_URL,\n { id, expiresIn },\n );\n return jsonResult({ url: data.getFileDownloadUrl, expiresIn: expiresIn ?? null });\n } catch (error) {\n ctx.logger.error('files_download failed', { error: String(error) });\n return errorResult(`Failed to resolve download URL: ${message(error)}`);\n }\n },\n );\n\n // ── Upload ──────────────────────────────────────────────────────────────\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_upload_initiate')),\n {\n title: 'Initiate File Upload',\n description:\n 'Start an upload session. Returns the session (id, uploadType, partSize, totalParts) and either one presigned uploadUrl or, for multipart uploads, presignedUrls: PUT byte range [(partNumber-1)*partSize, partNumber*partSize) to each part URL. Then call files_upload_complete with the session id.',\n inputSchema: {\n fileName: z.string().min(1).describe('File name including extension'),\n fileSize: fileSizeSchema,\n mimeType: z.string().optional().describe('MIME type (default application/octet-stream)'),\n extension: z\n .string()\n .optional()\n .describe('Extension without the dot (derived from fileName when omitted)'),\n sha256Hash: z.string().optional().describe('Hex SHA-256 of the contents'),\n folderId: z.string().optional().describe('Target folder ID'),\n visibility: VisibilityEnum.optional().describe('Visibility (default WORKSPACE)'),\n },\n },\n async ({ fileName, fileSize, mimeType, extension, sha256Hash, folderId, visibility }) => {\n try {\n const input: Record<string, unknown> = {\n fileName,\n fileSize: String(fileSize),\n mimeType: mimeType ?? 'application/octet-stream',\n extension: extension ?? extensionOf(fileName),\n visibility: visibility ?? 'WORKSPACE',\n };\n if (sha256Hash !== undefined) input.sha256Hash = sha256Hash;\n if (folderId !== undefined) input.folderId = folderId;\n const data = await ctx.gql.workspace.request<{ initiateUpload: unknown }>(\n ops.INITIATE_UPLOAD,\n { input },\n );\n return jsonResult(data.initiateUpload);\n } catch (error) {\n ctx.logger.error('files_upload_initiate failed', { error: String(error) });\n return errorResult(`Failed to initiate upload: ${message(error)}`);\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_upload_complete')),\n {\n title: 'Complete File Upload',\n description:\n 'Finish an upload session after the bytes were PUT to the presigned URL. fileSize must match the size passed to files_upload_initiate.',\n inputSchema: {\n sessionId: z.string().describe('Session ID from files_upload_initiate'),\n fileSize: fileSizeSchema,\n sha256Hash: z.string().optional().describe('Hex SHA-256 of the contents'),\n folderId: z.string().optional().describe('Target folder ID (overrides initiate)'),\n description: z.string().optional().describe('File description'),\n },\n },\n async ({ sessionId, fileSize, sha256Hash, folderId, description }) => {\n try {\n const input: Record<string, unknown> = { sessionId, fileSize: String(fileSize) };\n if (sha256Hash !== undefined) input.sha256Hash = sha256Hash;\n if (folderId !== undefined) input.folderId = folderId;\n if (description !== undefined) input.description = description;\n const data = await ctx.gql.workspace.request<{ completeUpload: unknown }>(\n ops.COMPLETE_UPLOAD,\n { input },\n );\n return jsonResult(data.completeUpload);\n } catch (error) {\n ctx.logger.error('files_upload_complete failed', { error: String(error) });\n return errorResult(`Failed to complete upload: ${message(error)}`);\n }\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_upload')),\n {\n title: 'Register Uploaded File',\n description:\n 'Register an object that already exists in the workspace bucket as a file (mirrors the SDK files.upload contract). For new bytes use files_upload_initiate + files_upload_complete.',\n inputSchema: {\n name: z.string().min(1).describe('Display file name including extension'),\n mimeType: z.string().describe('MIME type'),\n extension: z.string().describe('Extension without the dot'),\n size: fileSizeSchema,\n s3Bucket: z.string().describe('Bucket holding the object'),\n s3Key: z.string().describe('Object key'),\n description: z.string().optional().describe('File description'),\n folderId: z.string().optional().describe('Target folder ID'),\n visibility: VisibilityEnum.optional().describe('Visibility (default WORKSPACE)'),\n },\n },\n async ({\n name,\n mimeType,\n extension,\n size,\n s3Bucket,\n s3Key,\n description,\n folderId,\n visibility,\n }) => {\n try {\n const input: Record<string, unknown> = {\n name,\n mimeType,\n extension,\n size: String(size),\n s3Bucket,\n s3Key,\n };\n if (description !== undefined) input.description = description;\n if (folderId !== undefined) input.folderId = folderId;\n if (visibility !== undefined) input.visibility = visibility;\n const data = await ctx.gql.workspace.request<{ uploadFile: unknown }>(ops.UPLOAD_FILE, {\n input,\n });\n return jsonResult(data.uploadFile);\n } catch (error) {\n ctx.logger.error('files_upload failed', { error: String(error) });\n return errorResult(`Failed to register file: ${message(error)}`);\n }\n },\n );\n\n // ── Share ───────────────────────────────────────────────────────────────\n const createShare = async (input: Record<string, unknown>, tool: string) => {\n try {\n const data = await ctx.gql.workspace.request<{ createShare: unknown }>(ops.CREATE_SHARE, {\n input,\n });\n return jsonResult(data.createShare);\n } catch (error) {\n ctx.logger.error(`${tool} failed`, { error: String(error) });\n return errorResult(`Failed to share file: ${message(error)}`);\n }\n };\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_share')),\n {\n title: 'Share File',\n description:\n 'Share a file: PUBLIC_LINK (anyone with the link), EMAIL_INVITE (one email) or GROUP_SHARE (listed user IDs).',\n inputSchema: {\n fileId: z.string().describe('File ID'),\n shareType: ShareTypeEnum.describe('How the file is shared'),\n accessLevel: ShareAccessEnum.describe('What the share allows'),\n expiresAt: z.string().optional().describe('Expiry (ISO-8601)'),\n password: z.string().optional().describe('Password that gates the share'),\n maxDownloads: z.number().int().positive().optional().describe('Download limit'),\n invitedEmail: z.string().optional().describe('Email for EMAIL_INVITE'),\n invitedUserIds: z.array(z.string()).optional().describe('User IDs for GROUP_SHARE'),\n },\n },\n async (args) => {\n const input: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) if (value !== undefined) input[key] = value;\n if (args.shareType === 'EMAIL_INVITE' && !args.invitedEmail) {\n return errorResult('EMAIL_INVITE shares need invitedEmail.');\n }\n if (args.shareType === 'GROUP_SHARE' && !args.invitedUserIds?.length) {\n return errorResult('GROUP_SHARE shares need at least one invitedUserIds entry.');\n }\n return createShare(input, 'files_share');\n },\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_share_create')),\n {\n title: 'Create File Share Link',\n description: 'Create a public share link for a file (DOWNLOAD access unless stated).',\n inputSchema: {\n fileId: z.string().describe('File ID'),\n access: ShareAccessEnum.optional().describe('Access level (default DOWNLOAD)'),\n expiresAt: z.string().optional().describe('Expiry (ISO-8601)'),\n password: z.string().optional().describe('Password that gates the link'),\n maxDownloads: z.number().int().positive().optional().describe('Download limit'),\n },\n },\n async ({ fileId, access, expiresAt, password, maxDownloads }) => {\n const input: Record<string, unknown> = {\n fileId,\n shareType: 'PUBLIC_LINK',\n accessLevel: access ?? 'DOWNLOAD',\n };\n if (expiresAt !== undefined) input.expiresAt = expiresAt;\n if (password !== undefined) input.password = password;\n if (maxDownloads !== undefined) input.maxDownloads = maxDownloads;\n return createShare(input, 'files_share_create');\n },\n );\n\n const revokeShare = async (id: string, tool: string) => {\n try {\n const data = await ctx.gql.workspace.request<{ revokeShare: unknown }>(ops.REVOKE_SHARE, {\n id,\n });\n return jsonResult(data.revokeShare);\n } catch (error) {\n ctx.logger.error(`${tool} failed`, { error: String(error) });\n return errorResult(`Failed to revoke share: ${message(error)}`);\n }\n };\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_share_revoke')),\n {\n title: 'Revoke File Share',\n description: 'Revoke a file share by its share ID.',\n inputSchema: { id: z.string().describe('Share ID') },\n },\n async ({ id }) => revokeShare(id, 'files_share_revoke'),\n );\n\n server.registerTool(\n track(mcpToolName(ctx.productName, 'files_revoke')),\n {\n title: 'Revoke File Share (SDK alias)',\n description: 'Alias of files_share_revoke that mirrors the SDK files.revoke name.',\n inputSchema: { id: z.string().describe('Share ID') },\n },\n async ({ id }) => revokeShare(id, 'files_revoke'),\n );\n}\n","/**\n * Files module — browse, read, download, upload and share workspace files:\n * <product>_files_{browse,list,get,download,upload_initiate,upload_complete,\n * upload,share,share_create,share_revoke,revoke}.\n *\n * Backend: ~/products/wspace/files/wspace-files-svc/.\n * Ported from cli-sdk/src/modules/files/.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { McpContext, McpModule, ModuleRegistration } from '../../core/index.js';\nimport { registerFilesTools } from './tools.js';\n\nconst filesModule: McpModule = {\n id: 'files',\n version: '0.0.1',\n displayName: 'Files',\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 registerFilesTools(server, ctx, track);\n\n return { tools, resources: [], prompts: [] };\n },\n};\n\nexport default filesModule;\n"]}
|