@tinycloud/mcp 0.8.3-beta.2 → 0.8.3-beta.20
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/README.md +52 -44
- package/dist/cli.cjs +4 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4 -4
- package/dist/cli.js.map +1 -1
- package/dist/http-cli.cjs +940 -26
- package/dist/http-cli.cjs.map +1 -1
- package/dist/http-cli.js +939 -22
- package/dist/http-cli.js.map +1 -1
- package/dist/http.cjs +927 -25
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +24 -0
- package/dist/http.d.ts +24 -0
- package/dist/http.js +926 -21
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +927 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +926 -21
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +4 -4
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/dist/tools.cjs +1 -1
- package/dist/tools.cjs.map +1 -1
- package/dist/tools.d.cts +3 -1
- package/dist/tools.d.ts +3 -1
- package/dist/tools.js +1 -1
- package/dist/tools.js.map +1 -1
- package/package.json +3 -3
- package/skills/tinycloud-delegated-secrets/SKILL.md +18 -4
package/dist/tools.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tools.ts","../src/results.ts","../src/logging.ts","../src/schemas.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\n\nimport { fromJsonSchema, type McpServer, type ToolAnnotations } from \"@modelcontextprotocol/server\";\nimport { AjvJsonSchemaValidator } from \"@modelcontextprotocol/server/validators/ajv\";\nimport { invokeOperation } from \"@tinycloud/operations\";\n\nimport { toMcpToolResult, type McpToolResult } from \"./results.js\";\nimport { logToolCall } from \"./logging.js\";\nimport { toMcpJsonSchema } from \"./schemas.js\";\n\nexport const TOOL_NAMES = [\n \"tinycloud_status\",\n \"tinycloud_auth_status\",\n \"tinycloud_auth_capabilities\",\n \"tinycloud_auth_request\",\n \"tinycloud_auth_import\",\n \"tinycloud_account_spaces_list\",\n \"tinycloud_account_applications_list\",\n \"tinycloud_kv_list\",\n \"tinycloud_kv_get\",\n \"tinycloud_kv_head\",\n \"tinycloud_kv_put\",\n \"tinycloud_kv_delete\",\n \"tinycloud_knowledge_list\",\n \"tinycloud_knowledge_read\",\n \"tinycloud_sql_schema_inspect\",\n \"tinycloud_sql_query\",\n \"tinycloud_sql_execute\",\n \"tinycloud_secrets_get\",\n \"tinycloud_secrets_status\",\n \"tinycloud_apps_context\",\n \"tinycloud_apps_read\",\n \"tinycloud_apps_write\",\n \"tinycloud_apps_query\",\n] as const;\n\nexport type ToolName = (typeof TOOL_NAMES)[number];\n\n/** Private stdio/hosted surfaces and the restricted public plugin. */\nexport type McpSurface = \"local\" | \"hosted\" | \"public\";\n\nexport interface McpStartupSelection {\n /** Which server registers the tools; bindings not on this surface are skipped. */\n readonly surface: McpSurface;\n readonly profile: string;\n readonly explicitProfile: boolean;\n readonly allowOwnerProfile: boolean;\n /** Absolute TinyCloud home used to isolate one hosted OAuth principal. */\n readonly stateRoot?: string;\n /** Check node authority only when an operation needs the account. */\n readonly beforeOperation?: () => Promise<void>;\n /** Hosted transports may attach a browser approval URL to canonical results. */\n readonly transformOperationResult?: (result: unknown, invocation: McpOperationInvocation) => Promise<unknown>;\n}\n\nexport interface McpOperationInvocation {\n readonly operationId: string;\n readonly operationVersion: number;\n readonly input: unknown;\n}\n\nexport interface McpInvocationTarget {\n readonly profile: string;\n readonly allowOwnerProfile?: true;\n readonly stateRoot?: string;\n}\n\n/** Project one startup selection into the only owner-sensitive target shape. */\nexport function invocationTargetForMcp(\n selection: Omit<McpStartupSelection, \"surface\">,\n): McpInvocationTarget {\n return {\n profile: selection.profile,\n ...(selection.explicitProfile && selection.allowOwnerProfile\n ? { allowOwnerProfile: true }\n : {}),\n ...(selection.stateRoot === undefined ? {} : { stateRoot: selection.stateRoot }),\n };\n}\n\ninterface CatalogOperation {\n readonly id: string;\n readonly version: number;\n readonly title: string;\n readonly description: string;\n readonly input: Record<string, unknown>;\n readonly result: Record<string, unknown>;\n}\n\ninterface OperationsCatalog {\n readonly stableErrors: readonly string[];\n readonly operations: readonly CatalogOperation[];\n}\n\n// The require anchor is this module, never the consumer entrypoint. In ESM\n// tsup preserves import.meta.url; in CJS it rewrites the same module-relative\n// anchor to the generated __filename, so both formats stay in MCP's package\n// dependency boundary.\nconst packageRequire = createRequire(\n typeof __dirname === \"string\" ? join(__dirname, \"tools.cjs\") : import.meta.url,\n);\nconst generatedCatalog = packageRequire(\n \"@tinycloud/operations/operations.json\",\n) as OperationsCatalog;\nconst stableErrorCodes: Readonly<Record<string, true>> = Object.fromEntries(\n generatedCatalog.stableErrors.map((code) => [code, true as const]),\n);\n\nexport interface ToolBinding {\n readonly name: ToolName;\n readonly operationId: string;\n readonly operationVersion: number;\n readonly readOnlyHint: boolean;\n readonly idempotentHint: boolean;\n readonly destructiveHint: boolean;\n readonly openWorldHint: boolean;\n /** Surfaces that register this tool; omitted means private local and hosted surfaces only. */\n readonly surfaces?: readonly McpSurface[];\n}\n\nconst PRIVATE_SURFACES: readonly McpSurface[] = [\"local\", \"hosted\"];\n\n/** The surfaces a binding is registered on. */\nexport function bindingSurfaces(binding: ToolBinding): readonly McpSurface[] {\n return binding.surfaces ?? PRIVATE_SURFACES;\n}\n\nexport const TOOL_BINDINGS: readonly ToolBinding[] = [\n {\n name: \"tinycloud_status\",\n operationId: \"tinycloud.status.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_status\",\n operationId: \"tinycloud.auth.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_capabilities\",\n operationId: \"tinycloud.auth.capabilities\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_request\",\n operationId: \"tinycloud.auth.request\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_import\",\n operationId: \"tinycloud.auth.import\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n // Hosted delegations must arrive through the owner/request-bound OpenKey callback,\n // not a caller-supplied import artifact.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_account_spaces_list\",\n operationId: \"tinycloud.account.spaces.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_account_applications_list\",\n operationId: \"tinycloud.account.applications.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_list\",\n operationId: \"tinycloud.kv.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_get\",\n operationId: \"tinycloud.kv.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_head\",\n operationId: \"tinycloud.kv.head\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_put\",\n operationId: \"tinycloud.kv.put\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_delete\",\n operationId: \"tinycloud.kv.delete\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_list\",\n operationId: \"tinycloud.knowledge.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_read\",\n operationId: \"tinycloud.knowledge.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_schema_inspect\",\n operationId: \"tinycloud.sql.schema.inspect\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_query\",\n operationId: \"tinycloud.sql.query\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_execute\",\n operationId: \"tinycloud.sql.execute\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_get\",\n operationId: \"tinycloud.secrets.get\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_status\",\n operationId: \"tinycloud.secrets.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n // Hosted has no persistent reauthorization path for a revoked session\n // yet (TC-896), so status is local/stdio only.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_apps_context\",\n operationId: \"tinycloud.apps.context\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_read\",\n operationId: \"tinycloud.apps.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_write\",\n operationId: \"tinycloud.apps.write\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_query\",\n operationId: \"tinycloud.apps.query\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n] as const;\n\n// Project once per process; never mutate the catalog shared with non-MCP consumers.\nconst definitions = new Map(generatedCatalog.operations.map((operation) => [\n `${operation.id}@${operation.version}`,\n {\n ...operation,\n input: toMcpJsonSchema(operation.input),\n result: toMcpJsonSchema(operation.result),\n },\n]));\n\nexport function createJsonSchemaValidator(): AjvJsonSchemaValidator {\n return new AjvJsonSchemaValidator();\n}\n\nexport function registerTinyCloudTools(\n server: McpServer,\n selection: McpStartupSelection,\n validator: AjvJsonSchemaValidator,\n): void {\n const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface));\n for (const binding of bindings) {\n const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);\n if (operation === undefined) {\n throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);\n }\n\n const inputSchema = fromJsonSchema(\n operation.input as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const outputSchema = fromJsonSchema(\n operation.result as unknown as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const annotations: ToolAnnotations = {\n readOnlyHint: binding.readOnlyHint,\n idempotentHint: binding.idempotentHint,\n destructiveHint: binding.destructiveHint,\n openWorldHint: binding.openWorldHint,\n };\n\n server.registerTool(\n binding.name,\n {\n title: operation.title,\n description: operation.description,\n inputSchema,\n outputSchema,\n annotations,\n },\n async (input: unknown): Promise<McpToolResult> => {\n const startedAt = performance.now();\n const metrics = { replayedGrants: 0 };\n let code = \"INTERNAL_ERROR\";\n try {\n await selection.beforeOperation?.();\n const result = await invokeOperation(\n binding.operationId,\n binding.operationVersion,\n invocationTargetForMcp(selection),\n input,\n metrics,\n );\n const projected = selection.transformOperationResult === undefined\n ? result\n : await selection.transformOperationResult(result, {\n operationId: binding.operationId,\n operationVersion: binding.operationVersion,\n input,\n });\n const response = toMcpToolResult(projected, bindings, {\n surface: selection.surface === \"local\" ? \"local\" : \"hosted\",\n readOnly: binding.readOnlyHint,\n operationId: binding.operationId,\n });\n code = outcomeCode(response.structuredContent);\n return response;\n } finally {\n if (selection.surface !== \"local\") {\n logToolCall(binding.name, code, startedAt, metrics.replayedGrants);\n }\n }\n },\n );\n }\n}\n\nfunction outcomeCode(result: McpToolResult[\"structuredContent\"]): string {\n if (result.status === \"error\") {\n const error = result.error as { code?: unknown } | undefined;\n return typeof error?.code === \"string\" && Object.hasOwn(stableErrorCodes, error.code) ? error.code : \"INTERNAL_ERROR\";\n }\n if (result.status !== \"ok\") return result.status;\n const output = result.output as { outcome?: unknown; ops?: readonly { outcome?: unknown }[] } | undefined;\n if (output?.outcome === \"COPY_PARTIAL\") return \"COPY_PARTIAL\";\n if (Array.isArray(output?.ops) && output.ops.some((op) => op.outcome !== \"ok\")) return \"PARTIAL\";\n return \"ok\";\n}\n\nexport function toolBindingsForTest(): readonly ToolBinding[] {\n return TOOL_BINDINGS;\n}\n","/** MCP preserves the canonical envelope; hosted clients also receive readable JSON. */\nexport interface CanonicalOperationResult {\n readonly status: \"ok\" | \"authority_required\" | \"setup_required\" | \"error\";\n readonly [key: string]: unknown;\n}\n\nexport interface McpToolResult extends CallToolResult {\n readonly content: [{ readonly type: \"text\"; readonly text: string }];\n readonly structuredContent: CanonicalOperationResult;\n}\n\n/** The binding fields needed to name the tool that runs an operation. */\nexport interface RecoveryToolBinding {\n readonly name: string;\n readonly operationId: string;\n}\n\nexport interface McpToolResultOptions {\n readonly surface?: \"hosted\" | \"local\";\n readonly readOnly?: boolean;\n /** Trusted operation identity from the tool binding, not operation output. */\n readonly operationId?: string;\n}\n\nexport function toMcpToolResult(\n result: unknown,\n bindings: readonly RecoveryToolBinding[] = [],\n options: McpToolResultOptions = {},\n): McpToolResult {\n let canonical: CanonicalOperationResult = isCanonicalOperationResult(result)\n ? withRecoveryTool(result, bindings)\n : {\n status: \"error\",\n operation: {},\n context: {},\n error: { code: \"INTERNAL_ERROR\" },\n };\n let serialized: string | undefined;\n if (options.surface === \"hosted\") {\n serialized = JSON.stringify(canonical);\n if (\n (options.readOnly === true ||\n options.operationId === \"tinycloud.apps.context\" ||\n options.operationId === \"tinycloud.apps.query\") &&\n serialized.length > 100_000\n ) {\n const sql = options.operationId?.startsWith(\"tinycloud.sql.\") ||\n options.operationId === \"tinycloud.apps.query\";\n canonical = {\n status: \"error\",\n operation: canonical.operation,\n context: canonical.context,\n error: {\n code: sql ? \"SQL_RESULT_LIMIT_EXCEEDED\" : \"KV_RESPONSE_TOO_LARGE\",\n message: sql\n ? \"The result exceeds 100,000 characters. Select fewer columns or rows, add a WHERE filter or a smaller LIMIT, or aggregate the data.\"\n : \"The result exceeds 100,000 characters. Request fewer keys, narrow the prefix, or use a smaller page size.\",\n retryable: false,\n },\n };\n serialized = JSON.stringify(canonical);\n }\n }\n\n return {\n content: [{\n type: \"text\",\n text: resultSummary(canonical.status) +\n (serialized !== undefined && !(options.operationId === \"tinycloud.secrets.get\" && canonical.status === \"ok\")\n ? `\\n${serialized}` : \"\"),\n }],\n structuredContent: canonical,\n };\n}\n\n/**\n * A redacted `complete_migration` recovery names an operation; MCP clients\n * call tools, so name the bound tool. `tool` comes from the code-owned binding\n * table only, never from operation data, and is added after redaction. An\n * operationId with no binding gets no `tool`.\n */\nfunction withRecoveryTool(\n result: CanonicalOperationResult,\n bindings: readonly RecoveryToolBinding[],\n): CanonicalOperationResult {\n if (result.status !== \"error\") return result;\n // The kernel's redaction already constrained `error.details.recovery` to a\n // safe recovery object; only its discriminant and operationId are read here.\n const error = result.error as\n | { readonly details?: { readonly recovery?: { readonly action?: unknown; readonly operationId?: unknown } } }\n | undefined;\n const recovery = error?.details?.recovery;\n if (recovery?.action !== \"complete_migration\") return result;\n const binding = bindings.find((candidate) => candidate.operationId === recovery.operationId);\n if (binding === undefined) return result;\n return {\n ...result,\n error: { ...error, details: { ...error?.details, recovery: { ...recovery, tool: binding.name } } },\n };\n}\n\n/** The canonical envelope immediately before MCP protocol serialization. */\nexport function canonicalMcpAdapterResult(result: unknown): CanonicalOperationResult {\n return toMcpToolResult(result).structuredContent;\n}\n\nfunction isCanonicalOperationResult(value: unknown): value is CanonicalOperationResult {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n const status = (value as { status?: unknown }).status;\n return status === \"ok\" ||\n status === \"authority_required\" ||\n status === \"setup_required\" ||\n status === \"error\";\n}\n\nfunction resultSummary(status: CanonicalOperationResult[\"status\"]): string {\n switch (status) {\n case \"ok\":\n return \"TinyCloud operation completed; use the structured result.\";\n case \"authority_required\":\n return \"TinyCloud authority is required; use the structured request and approval action.\";\n case \"setup_required\":\n return \"TinyCloud setup is required; use the structured setup action.\";\n case \"error\":\n return \"TinyCloud operation failed; use the structured error.\";\n }\n}\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n","/** Only code-owned tool names/codes and numeric counters reach this sink. */\nexport function logToolCall(\n tool: string,\n code: string,\n startedAt: number,\n replayedGrants: number,\n): void {\n process.stderr.write(`${JSON.stringify({\n tool,\n code,\n durationMs: Math.max(0, Math.round(performance.now() - startedAt)),\n replayedGrants,\n })}\\n`);\n}\n","type JsonSchema = boolean | Record<string, unknown>;\n\nconst DRAFT_7 = \"http://json-schema.org/draft-07/schema#\";\nconst DRAFT_2020_12 = \"https://json-schema.org/draft/2020-12/schema\";\nconst schemaMaps = new Set([\"properties\", \"patternProperties\", \"definitions\", \"$defs\"]);\nconst schemaArrays = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\nconst schemaValues = new Set([\n \"additionalProperties\", \"items\", \"contains\", \"propertyNames\", \"not\", \"if\", \"then\", \"else\",\n]);\n\n/** Project the catalog's shared Draft-07/2020-12 vocabulary without changing its validation rules. */\nexport function toMcpJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema {\n if (typeof schema === \"boolean\") return schema;\n // These forms need a semantic migration, not just a dialect declaration. The\n // generated catalog does not use them; fail closed if that contract changes.\n if (Array.isArray(schema.items) || \"additionalItems\" in schema || \"dependencies\" in schema ||\n (\"$ref\" in schema && Object.keys(schema).some((key) => key !== \"$ref\"))) {\n throw new Error(\"The operations schema needs a semantic migration to JSON Schema 2020-12.\");\n }\n\n const projected: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema)) {\n if (key === \"$schema\") {\n if (value !== DRAFT_7) throw new Error(`Unsupported operations schema dialect: ${String(value)}.`);\n projected[key] = DRAFT_2020_12;\n } else if (schemaMaps.has(key)) {\n projected[key] = Object.fromEntries(Object.entries(value as Record<string, JsonSchema>)\n .map(([name, child]) => [name, toMcpJsonSchema(child)]));\n } else if (schemaArrays.has(key)) {\n projected[key] = (value as JsonSchema[]).map(toMcpJsonSchema);\n } else if (schemaValues.has(key)) {\n projected[key] = toMcpJsonSchema(value as JsonSchema);\n } else {\n // Descriptions, defaults, examples and const/enum values are data, not schemas.\n projected[key] = value;\n }\n }\n return projected;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8B;AAC9B,uBAAqB;AAErB,oBAAqE;AACrE,iBAAuC;AACvC,wBAAgC;;;ACmBzB,SAAS,gBACd,QACA,WAA2C,CAAC,GAC5C,UAAgC,CAAC,GAClB;AACf,MAAI,YAAsC,2BAA2B,MAAM,IACvE,iBAAiB,QAAQ,QAAQ,IACjC;AAAA,IACA,QAAQ;AAAA,IACR,WAAW,CAAC;AAAA,IACZ,SAAS,CAAC;AAAA,IACV,OAAO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version":3,"sources":["../src/tools.ts","../src/results.ts","../src/logging.ts","../src/schemas.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\n\nimport { fromJsonSchema, type McpServer, type ToolAnnotations } from \"@modelcontextprotocol/server\";\nimport { AjvJsonSchemaValidator } from \"@modelcontextprotocol/server/validators/ajv\";\nimport { invokeOperation } from \"@tinycloud/operations\";\n\nimport { toMcpToolResult, type McpToolResult } from \"./results.js\";\nimport { logToolCall } from \"./logging.js\";\nimport { toMcpJsonSchema } from \"./schemas.js\";\n\nexport const TOOL_NAMES = [\n \"tinycloud_status\",\n \"tinycloud_auth_status\",\n \"tinycloud_auth_capabilities\",\n \"tinycloud_auth_request\",\n \"tinycloud_auth_import\",\n \"tinycloud_account_spaces_list\",\n \"tinycloud_account_applications_list\",\n \"tinycloud_kv_list\",\n \"tinycloud_kv_get\",\n \"tinycloud_kv_head\",\n \"tinycloud_kv_put\",\n \"tinycloud_kv_delete\",\n \"tinycloud_knowledge_list\",\n \"tinycloud_knowledge_read\",\n \"tinycloud_sql_schema_inspect\",\n \"tinycloud_sql_query\",\n \"tinycloud_sql_execute\",\n \"tinycloud_secrets_get\",\n \"tinycloud_secrets_status\",\n \"tinycloud_apps_context\",\n \"tinycloud_apps_read\",\n \"tinycloud_apps_write\",\n \"tinycloud_apps_query\",\n] as const;\n\nexport type ToolName = (typeof TOOL_NAMES)[number];\n\n/** Private stdio/hosted surfaces and the restricted public plugin. */\nexport type McpSurface = \"local\" | \"hosted\" | \"public\";\n\nexport interface McpStartupSelection {\n /** Which server registers the tools; bindings not on this surface are skipped. */\n readonly surface: McpSurface;\n readonly profile: string;\n readonly explicitProfile: boolean;\n readonly allowOwnerProfile: boolean;\n /** Absolute TinyCloud home used to isolate one hosted principal. */\n readonly stateRoot?: string;\n /** Optional allowlist for surfaces whose grant is narrower than hosted OAuth. */\n readonly allowedTools?: readonly ToolName[];\n /** Check node authority only when an operation needs the account. */\n readonly beforeOperation?: () => Promise<void>;\n /** Hosted transports may attach a browser approval URL to canonical results. */\n readonly transformOperationResult?: (result: unknown, invocation: McpOperationInvocation) => Promise<unknown>;\n}\n\nexport interface McpOperationInvocation {\n readonly operationId: string;\n readonly operationVersion: number;\n readonly input: unknown;\n}\n\nexport interface McpInvocationTarget {\n readonly profile: string;\n readonly allowOwnerProfile?: true;\n readonly stateRoot?: string;\n}\n\n/** Project one startup selection into the only owner-sensitive target shape. */\nexport function invocationTargetForMcp(\n selection: Omit<McpStartupSelection, \"surface\">,\n): McpInvocationTarget {\n return {\n profile: selection.profile,\n ...(selection.explicitProfile && selection.allowOwnerProfile\n ? { allowOwnerProfile: true }\n : {}),\n ...(selection.stateRoot === undefined ? {} : { stateRoot: selection.stateRoot }),\n };\n}\n\ninterface CatalogOperation {\n readonly id: string;\n readonly version: number;\n readonly title: string;\n readonly description: string;\n readonly input: Record<string, unknown>;\n readonly result: Record<string, unknown>;\n}\n\ninterface OperationsCatalog {\n readonly stableErrors: readonly string[];\n readonly operations: readonly CatalogOperation[];\n}\n\n// The require anchor is this module, never the consumer entrypoint. In ESM\n// tsup preserves import.meta.url; in CJS it rewrites the same module-relative\n// anchor to the generated __filename, so both formats stay in MCP's package\n// dependency boundary.\nconst packageRequire = createRequire(\n typeof __dirname === \"string\" ? join(__dirname, \"tools.cjs\") : import.meta.url,\n);\nconst generatedCatalog = packageRequire(\n \"@tinycloud/operations/operations.json\",\n) as OperationsCatalog;\nconst stableErrorCodes: Readonly<Record<string, true>> = Object.fromEntries(\n generatedCatalog.stableErrors.map((code) => [code, true as const]),\n);\n\nexport interface ToolBinding {\n readonly name: ToolName;\n readonly operationId: string;\n readonly operationVersion: number;\n readonly readOnlyHint: boolean;\n readonly idempotentHint: boolean;\n readonly destructiveHint: boolean;\n readonly openWorldHint: boolean;\n /** Surfaces that register this tool; omitted means private local and hosted surfaces only. */\n readonly surfaces?: readonly McpSurface[];\n}\n\nconst PRIVATE_SURFACES: readonly McpSurface[] = [\"local\", \"hosted\"];\n\n/** The surfaces a binding is registered on. */\nexport function bindingSurfaces(binding: ToolBinding): readonly McpSurface[] {\n return binding.surfaces ?? PRIVATE_SURFACES;\n}\n\nexport const TOOL_BINDINGS: readonly ToolBinding[] = [\n {\n name: \"tinycloud_status\",\n operationId: \"tinycloud.status.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_status\",\n operationId: \"tinycloud.auth.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_capabilities\",\n operationId: \"tinycloud.auth.capabilities\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_request\",\n operationId: \"tinycloud.auth.request\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_import\",\n operationId: \"tinycloud.auth.import\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n // Hosted delegations must arrive through the owner/request-bound OpenKey callback,\n // not a caller-supplied import artifact.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_account_spaces_list\",\n operationId: \"tinycloud.account.spaces.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_account_applications_list\",\n operationId: \"tinycloud.account.applications.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_list\",\n operationId: \"tinycloud.kv.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_get\",\n operationId: \"tinycloud.kv.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_head\",\n operationId: \"tinycloud.kv.head\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_put\",\n operationId: \"tinycloud.kv.put\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_delete\",\n operationId: \"tinycloud.kv.delete\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_list\",\n operationId: \"tinycloud.knowledge.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_read\",\n operationId: \"tinycloud.knowledge.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_schema_inspect\",\n operationId: \"tinycloud.sql.schema.inspect\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_query\",\n operationId: \"tinycloud.sql.query\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_execute\",\n operationId: \"tinycloud.sql.execute\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_get\",\n operationId: \"tinycloud.secrets.get\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_status\",\n operationId: \"tinycloud.secrets.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n // Hosted has no persistent reauthorization path for a revoked session\n // yet (TC-896), so status is local/stdio only.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_apps_context\",\n operationId: \"tinycloud.apps.context\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_read\",\n operationId: \"tinycloud.apps.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_write\",\n operationId: \"tinycloud.apps.write\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_query\",\n operationId: \"tinycloud.apps.query\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n] as const;\n\n// Project once per process; never mutate the catalog shared with non-MCP consumers.\nconst definitions = new Map(generatedCatalog.operations.map((operation) => [\n `${operation.id}@${operation.version}`,\n {\n ...operation,\n input: toMcpJsonSchema(operation.input),\n result: toMcpJsonSchema(operation.result),\n },\n]));\n\nexport function createJsonSchemaValidator(): AjvJsonSchemaValidator {\n return new AjvJsonSchemaValidator();\n}\n\nexport function registerTinyCloudTools(\n server: McpServer,\n selection: McpStartupSelection,\n validator: AjvJsonSchemaValidator,\n): void {\n const bindings = TOOL_BINDINGS.filter((binding) =>\n bindingSurfaces(binding).includes(selection.surface) &&\n (selection.allowedTools === undefined || selection.allowedTools.includes(binding.name)));\n for (const binding of bindings) {\n const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);\n if (operation === undefined) {\n throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);\n }\n\n const inputSchema = fromJsonSchema(\n operation.input as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const outputSchema = fromJsonSchema(\n operation.result as unknown as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const annotations: ToolAnnotations = {\n readOnlyHint: binding.readOnlyHint,\n idempotentHint: binding.idempotentHint,\n destructiveHint: binding.destructiveHint,\n openWorldHint: binding.openWorldHint,\n };\n\n server.registerTool(\n binding.name,\n {\n title: operation.title,\n description: operation.description,\n inputSchema,\n outputSchema,\n annotations,\n },\n async (input: unknown): Promise<McpToolResult> => {\n const startedAt = performance.now();\n const metrics = { replayedGrants: 0 };\n let code = \"INTERNAL_ERROR\";\n try {\n await selection.beforeOperation?.();\n const result = await invokeOperation(\n binding.operationId,\n binding.operationVersion,\n invocationTargetForMcp(selection),\n input,\n metrics,\n );\n const projected = selection.transformOperationResult === undefined\n ? result\n : await selection.transformOperationResult(result, {\n operationId: binding.operationId,\n operationVersion: binding.operationVersion,\n input,\n });\n const response = toMcpToolResult(projected, bindings, {\n surface: selection.surface === \"local\" ? \"local\" : \"hosted\",\n readOnly: binding.readOnlyHint,\n operationId: binding.operationId,\n });\n code = outcomeCode(response.structuredContent);\n return response;\n } finally {\n if (selection.surface !== \"local\") {\n logToolCall(binding.name, code, startedAt, metrics.replayedGrants);\n }\n }\n },\n );\n }\n}\n\nfunction outcomeCode(result: McpToolResult[\"structuredContent\"]): string {\n if (result.status === \"error\") {\n const error = result.error as { code?: unknown } | undefined;\n return typeof error?.code === \"string\" && Object.hasOwn(stableErrorCodes, error.code) ? error.code : \"INTERNAL_ERROR\";\n }\n if (result.status !== \"ok\") return result.status;\n const output = result.output as { outcome?: unknown; ops?: readonly { outcome?: unknown }[] } | undefined;\n if (output?.outcome === \"COPY_PARTIAL\") return \"COPY_PARTIAL\";\n if (Array.isArray(output?.ops) && output.ops.some((op) => op.outcome !== \"ok\")) return \"PARTIAL\";\n return \"ok\";\n}\n\nexport function toolBindingsForTest(): readonly ToolBinding[] {\n return TOOL_BINDINGS;\n}\n","/** MCP preserves the canonical envelope; hosted clients also receive readable JSON. */\nexport interface CanonicalOperationResult {\n readonly status: \"ok\" | \"authority_required\" | \"setup_required\" | \"error\";\n readonly [key: string]: unknown;\n}\n\nexport interface McpToolResult extends CallToolResult {\n readonly content: [{ readonly type: \"text\"; readonly text: string }];\n readonly structuredContent: CanonicalOperationResult;\n}\n\n/** The binding fields needed to name the tool that runs an operation. */\nexport interface RecoveryToolBinding {\n readonly name: string;\n readonly operationId: string;\n}\n\nexport interface McpToolResultOptions {\n readonly surface?: \"hosted\" | \"local\";\n readonly readOnly?: boolean;\n /** Trusted operation identity from the tool binding, not operation output. */\n readonly operationId?: string;\n}\n\nexport function toMcpToolResult(\n result: unknown,\n bindings: readonly RecoveryToolBinding[] = [],\n options: McpToolResultOptions = {},\n): McpToolResult {\n let canonical: CanonicalOperationResult = isCanonicalOperationResult(result)\n ? withRecoveryTool(result, bindings)\n : {\n status: \"error\",\n operation: {},\n context: {},\n error: { code: \"INTERNAL_ERROR\" },\n };\n let serialized: string | undefined;\n if (options.surface === \"hosted\") {\n serialized = JSON.stringify(canonical);\n if (\n (options.readOnly === true ||\n options.operationId === \"tinycloud.apps.context\" ||\n options.operationId === \"tinycloud.apps.query\") &&\n serialized.length > 100_000\n ) {\n const sql = options.operationId?.startsWith(\"tinycloud.sql.\") ||\n options.operationId === \"tinycloud.apps.query\";\n canonical = {\n status: \"error\",\n operation: canonical.operation,\n context: canonical.context,\n error: {\n code: sql ? \"SQL_RESULT_LIMIT_EXCEEDED\" : \"KV_RESPONSE_TOO_LARGE\",\n message: sql\n ? \"The result exceeds 100,000 characters. Select fewer columns or rows, add a WHERE filter or a smaller LIMIT, or aggregate the data.\"\n : \"The result exceeds 100,000 characters. Request fewer keys, narrow the prefix, or use a smaller page size.\",\n retryable: false,\n },\n };\n serialized = JSON.stringify(canonical);\n }\n }\n\n return {\n content: [{\n type: \"text\",\n text: resultSummary(canonical.status) +\n (serialized !== undefined && !(options.operationId === \"tinycloud.secrets.get\" && canonical.status === \"ok\")\n ? `\\n${serialized}` : \"\"),\n }],\n structuredContent: canonical,\n };\n}\n\n/**\n * A redacted `complete_migration` recovery names an operation; MCP clients\n * call tools, so name the bound tool. `tool` comes from the code-owned binding\n * table only, never from operation data, and is added after redaction. An\n * operationId with no binding gets no `tool`.\n */\nfunction withRecoveryTool(\n result: CanonicalOperationResult,\n bindings: readonly RecoveryToolBinding[],\n): CanonicalOperationResult {\n if (result.status !== \"error\") return result;\n // The kernel's redaction already constrained `error.details.recovery` to a\n // safe recovery object; only its discriminant and operationId are read here.\n const error = result.error as\n | { readonly details?: { readonly recovery?: { readonly action?: unknown; readonly operationId?: unknown } } }\n | undefined;\n const recovery = error?.details?.recovery;\n if (recovery?.action !== \"complete_migration\") return result;\n const binding = bindings.find((candidate) => candidate.operationId === recovery.operationId);\n if (binding === undefined) return result;\n return {\n ...result,\n error: { ...error, details: { ...error?.details, recovery: { ...recovery, tool: binding.name } } },\n };\n}\n\n/** The canonical envelope immediately before MCP protocol serialization. */\nexport function canonicalMcpAdapterResult(result: unknown): CanonicalOperationResult {\n return toMcpToolResult(result).structuredContent;\n}\n\nfunction isCanonicalOperationResult(value: unknown): value is CanonicalOperationResult {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n const status = (value as { status?: unknown }).status;\n return status === \"ok\" ||\n status === \"authority_required\" ||\n status === \"setup_required\" ||\n status === \"error\";\n}\n\nfunction resultSummary(status: CanonicalOperationResult[\"status\"]): string {\n switch (status) {\n case \"ok\":\n return \"TinyCloud operation completed; use the structured result.\";\n case \"authority_required\":\n return \"TinyCloud authority is required; use the structured request and approval action.\";\n case \"setup_required\":\n return \"TinyCloud setup is required; use the structured setup action.\";\n case \"error\":\n return \"TinyCloud operation failed; use the structured error.\";\n }\n}\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n","/** Only code-owned tool names/codes and numeric counters reach this sink. */\nexport function logToolCall(\n tool: string,\n code: string,\n startedAt: number,\n replayedGrants: number,\n): void {\n process.stderr.write(`${JSON.stringify({\n tool,\n code,\n durationMs: Math.max(0, Math.round(performance.now() - startedAt)),\n replayedGrants,\n })}\\n`);\n}\n","type JsonSchema = boolean | Record<string, unknown>;\n\nconst DRAFT_7 = \"http://json-schema.org/draft-07/schema#\";\nconst DRAFT_2020_12 = \"https://json-schema.org/draft/2020-12/schema\";\nconst schemaMaps = new Set([\"properties\", \"patternProperties\", \"definitions\", \"$defs\"]);\nconst schemaArrays = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\nconst schemaValues = new Set([\n \"additionalProperties\", \"items\", \"contains\", \"propertyNames\", \"not\", \"if\", \"then\", \"else\",\n]);\n\n/** Project the catalog's shared Draft-07/2020-12 vocabulary without changing its validation rules. */\nexport function toMcpJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema {\n if (typeof schema === \"boolean\") return schema;\n // These forms need a semantic migration, not just a dialect declaration. The\n // generated catalog does not use them; fail closed if that contract changes.\n if (Array.isArray(schema.items) || \"additionalItems\" in schema || \"dependencies\" in schema ||\n (\"$ref\" in schema && Object.keys(schema).some((key) => key !== \"$ref\"))) {\n throw new Error(\"The operations schema needs a semantic migration to JSON Schema 2020-12.\");\n }\n\n const projected: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema)) {\n if (key === \"$schema\") {\n if (value !== DRAFT_7) throw new Error(`Unsupported operations schema dialect: ${String(value)}.`);\n projected[key] = DRAFT_2020_12;\n } else if (schemaMaps.has(key)) {\n projected[key] = Object.fromEntries(Object.entries(value as Record<string, JsonSchema>)\n .map(([name, child]) => [name, toMcpJsonSchema(child)]));\n } else if (schemaArrays.has(key)) {\n projected[key] = (value as JsonSchema[]).map(toMcpJsonSchema);\n } else if (schemaValues.has(key)) {\n projected[key] = toMcpJsonSchema(value as JsonSchema);\n } else {\n // Descriptions, defaults, examples and const/enum values are data, not schemas.\n projected[key] = value;\n }\n }\n return projected;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8B;AAC9B,uBAAqB;AAErB,oBAAqE;AACrE,iBAAuC;AACvC,wBAAgC;;;ACmBzB,SAAS,gBACd,QACA,WAA2C,CAAC,GAC5C,UAAgC,CAAC,GAClB;AACf,MAAI,YAAsC,2BAA2B,MAAM,IACvE,iBAAiB,QAAQ,QAAQ,IACjC;AAAA,IACA,QAAQ;AAAA,IACR,WAAW,CAAC;AAAA,IACZ,SAAS,CAAC;AAAA,IACV,OAAO,EAAE,MAAM,iBAAiB;AAAA,EAClC;AACF,MAAI;AACJ,MAAI,QAAQ,YAAY,UAAU;AAChC,iBAAa,KAAK,UAAU,SAAS;AACrC,SACG,QAAQ,aAAa,QACpB,QAAQ,gBAAgB,4BACxB,QAAQ,gBAAgB,2BAC1B,WAAW,SAAS,KACpB;AACA,YAAM,MAAM,QAAQ,aAAa,WAAW,gBAAgB,KAC1D,QAAQ,gBAAgB;AAC1B,kBAAY;AAAA,QACV,QAAQ;AAAA,QACR,WAAW,UAAU;AAAA,QACrB,SAAS,UAAU;AAAA,QACnB,OAAO;AAAA,UACL,MAAM,MAAM,8BAA8B;AAAA,UAC1C,SAAS,MACL,uIACA;AAAA,UACJ,WAAW;AAAA,QACb;AAAA,MACF;AACA,mBAAa,KAAK,UAAU,SAAS;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,SAAS,CAAC;AAAA,MACR,MAAM;AAAA,MACN,MAAM,cAAc,UAAU,MAAM,KACjC,eAAe,UAAa,EAAE,QAAQ,gBAAgB,2BAA2B,UAAU,WAAW,QACnG;AAAA,EAAK,UAAU,KAAK;AAAA,IAC5B,CAAC;AAAA,IACD,mBAAmB;AAAA,EACr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,QAAQ,cAAc;AAAA,UACnE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,YAAY,QAAoD;AACvE,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,WAAO,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO,kBAAkB,MAAM,IAAI,IAAI,MAAM,OAAO;AAAA,EACvG;AACA,MAAI,OAAO,WAAW,KAAM,QAAO,OAAO;AAC1C,QAAM,SAAS,OAAO;AACtB,MAAI,QAAQ,YAAY,eAAgB,QAAO;AAC/C,MAAI,MAAM,QAAQ,QAAQ,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,EAAG,QAAO;AACvF,SAAO;AACT;AAEO,SAAS,sBAA8C;AAC5D,SAAO;AACT;","names":[]}
|
package/dist/tools.d.cts
CHANGED
|
@@ -11,8 +11,10 @@ interface McpStartupSelection {
|
|
|
11
11
|
readonly profile: string;
|
|
12
12
|
readonly explicitProfile: boolean;
|
|
13
13
|
readonly allowOwnerProfile: boolean;
|
|
14
|
-
/** Absolute TinyCloud home used to isolate one hosted
|
|
14
|
+
/** Absolute TinyCloud home used to isolate one hosted principal. */
|
|
15
15
|
readonly stateRoot?: string;
|
|
16
|
+
/** Optional allowlist for surfaces whose grant is narrower than hosted OAuth. */
|
|
17
|
+
readonly allowedTools?: readonly ToolName[];
|
|
16
18
|
/** Check node authority only when an operation needs the account. */
|
|
17
19
|
readonly beforeOperation?: () => Promise<void>;
|
|
18
20
|
/** Hosted transports may attach a browser approval URL to canonical results. */
|
package/dist/tools.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ interface McpStartupSelection {
|
|
|
11
11
|
readonly profile: string;
|
|
12
12
|
readonly explicitProfile: boolean;
|
|
13
13
|
readonly allowOwnerProfile: boolean;
|
|
14
|
-
/** Absolute TinyCloud home used to isolate one hosted
|
|
14
|
+
/** Absolute TinyCloud home used to isolate one hosted principal. */
|
|
15
15
|
readonly stateRoot?: string;
|
|
16
|
+
/** Optional allowlist for surfaces whose grant is narrower than hosted OAuth. */
|
|
17
|
+
readonly allowedTools?: readonly ToolName[];
|
|
16
18
|
/** Check node authority only when an operation needs the account. */
|
|
17
19
|
readonly beforeOperation?: () => Promise<void>;
|
|
18
20
|
/** Hosted transports may attach a browser approval URL to canonical results. */
|
package/dist/tools.js
CHANGED
|
@@ -396,7 +396,7 @@ function createJsonSchemaValidator() {
|
|
|
396
396
|
return new AjvJsonSchemaValidator();
|
|
397
397
|
}
|
|
398
398
|
function registerTinyCloudTools(server, selection, validator) {
|
|
399
|
-
const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface));
|
|
399
|
+
const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
|
|
400
400
|
for (const binding of bindings) {
|
|
401
401
|
const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
|
|
402
402
|
if (operation === void 0) {
|
package/dist/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tools.ts","../src/results.ts","../src/logging.ts","../src/schemas.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\n\nimport { fromJsonSchema, type McpServer, type ToolAnnotations } from \"@modelcontextprotocol/server\";\nimport { AjvJsonSchemaValidator } from \"@modelcontextprotocol/server/validators/ajv\";\nimport { invokeOperation } from \"@tinycloud/operations\";\n\nimport { toMcpToolResult, type McpToolResult } from \"./results.js\";\nimport { logToolCall } from \"./logging.js\";\nimport { toMcpJsonSchema } from \"./schemas.js\";\n\nexport const TOOL_NAMES = [\n \"tinycloud_status\",\n \"tinycloud_auth_status\",\n \"tinycloud_auth_capabilities\",\n \"tinycloud_auth_request\",\n \"tinycloud_auth_import\",\n \"tinycloud_account_spaces_list\",\n \"tinycloud_account_applications_list\",\n \"tinycloud_kv_list\",\n \"tinycloud_kv_get\",\n \"tinycloud_kv_head\",\n \"tinycloud_kv_put\",\n \"tinycloud_kv_delete\",\n \"tinycloud_knowledge_list\",\n \"tinycloud_knowledge_read\",\n \"tinycloud_sql_schema_inspect\",\n \"tinycloud_sql_query\",\n \"tinycloud_sql_execute\",\n \"tinycloud_secrets_get\",\n \"tinycloud_secrets_status\",\n \"tinycloud_apps_context\",\n \"tinycloud_apps_read\",\n \"tinycloud_apps_write\",\n \"tinycloud_apps_query\",\n] as const;\n\nexport type ToolName = (typeof TOOL_NAMES)[number];\n\n/** Private stdio/hosted surfaces and the restricted public plugin. */\nexport type McpSurface = \"local\" | \"hosted\" | \"public\";\n\nexport interface McpStartupSelection {\n /** Which server registers the tools; bindings not on this surface are skipped. */\n readonly surface: McpSurface;\n readonly profile: string;\n readonly explicitProfile: boolean;\n readonly allowOwnerProfile: boolean;\n /** Absolute TinyCloud home used to isolate one hosted OAuth principal. */\n readonly stateRoot?: string;\n /** Check node authority only when an operation needs the account. */\n readonly beforeOperation?: () => Promise<void>;\n /** Hosted transports may attach a browser approval URL to canonical results. */\n readonly transformOperationResult?: (result: unknown, invocation: McpOperationInvocation) => Promise<unknown>;\n}\n\nexport interface McpOperationInvocation {\n readonly operationId: string;\n readonly operationVersion: number;\n readonly input: unknown;\n}\n\nexport interface McpInvocationTarget {\n readonly profile: string;\n readonly allowOwnerProfile?: true;\n readonly stateRoot?: string;\n}\n\n/** Project one startup selection into the only owner-sensitive target shape. */\nexport function invocationTargetForMcp(\n selection: Omit<McpStartupSelection, \"surface\">,\n): McpInvocationTarget {\n return {\n profile: selection.profile,\n ...(selection.explicitProfile && selection.allowOwnerProfile\n ? { allowOwnerProfile: true }\n : {}),\n ...(selection.stateRoot === undefined ? {} : { stateRoot: selection.stateRoot }),\n };\n}\n\ninterface CatalogOperation {\n readonly id: string;\n readonly version: number;\n readonly title: string;\n readonly description: string;\n readonly input: Record<string, unknown>;\n readonly result: Record<string, unknown>;\n}\n\ninterface OperationsCatalog {\n readonly stableErrors: readonly string[];\n readonly operations: readonly CatalogOperation[];\n}\n\n// The require anchor is this module, never the consumer entrypoint. In ESM\n// tsup preserves import.meta.url; in CJS it rewrites the same module-relative\n// anchor to the generated __filename, so both formats stay in MCP's package\n// dependency boundary.\nconst packageRequire = createRequire(\n typeof __dirname === \"string\" ? join(__dirname, \"tools.cjs\") : import.meta.url,\n);\nconst generatedCatalog = packageRequire(\n \"@tinycloud/operations/operations.json\",\n) as OperationsCatalog;\nconst stableErrorCodes: Readonly<Record<string, true>> = Object.fromEntries(\n generatedCatalog.stableErrors.map((code) => [code, true as const]),\n);\n\nexport interface ToolBinding {\n readonly name: ToolName;\n readonly operationId: string;\n readonly operationVersion: number;\n readonly readOnlyHint: boolean;\n readonly idempotentHint: boolean;\n readonly destructiveHint: boolean;\n readonly openWorldHint: boolean;\n /** Surfaces that register this tool; omitted means private local and hosted surfaces only. */\n readonly surfaces?: readonly McpSurface[];\n}\n\nconst PRIVATE_SURFACES: readonly McpSurface[] = [\"local\", \"hosted\"];\n\n/** The surfaces a binding is registered on. */\nexport function bindingSurfaces(binding: ToolBinding): readonly McpSurface[] {\n return binding.surfaces ?? PRIVATE_SURFACES;\n}\n\nexport const TOOL_BINDINGS: readonly ToolBinding[] = [\n {\n name: \"tinycloud_status\",\n operationId: \"tinycloud.status.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_status\",\n operationId: \"tinycloud.auth.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_capabilities\",\n operationId: \"tinycloud.auth.capabilities\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_request\",\n operationId: \"tinycloud.auth.request\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_import\",\n operationId: \"tinycloud.auth.import\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n // Hosted delegations must arrive through the owner/request-bound OpenKey callback,\n // not a caller-supplied import artifact.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_account_spaces_list\",\n operationId: \"tinycloud.account.spaces.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_account_applications_list\",\n operationId: \"tinycloud.account.applications.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_list\",\n operationId: \"tinycloud.kv.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_get\",\n operationId: \"tinycloud.kv.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_head\",\n operationId: \"tinycloud.kv.head\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_put\",\n operationId: \"tinycloud.kv.put\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_delete\",\n operationId: \"tinycloud.kv.delete\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_list\",\n operationId: \"tinycloud.knowledge.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_read\",\n operationId: \"tinycloud.knowledge.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_schema_inspect\",\n operationId: \"tinycloud.sql.schema.inspect\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_query\",\n operationId: \"tinycloud.sql.query\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_execute\",\n operationId: \"tinycloud.sql.execute\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_get\",\n operationId: \"tinycloud.secrets.get\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_status\",\n operationId: \"tinycloud.secrets.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n // Hosted has no persistent reauthorization path for a revoked session\n // yet (TC-896), so status is local/stdio only.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_apps_context\",\n operationId: \"tinycloud.apps.context\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_read\",\n operationId: \"tinycloud.apps.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_write\",\n operationId: \"tinycloud.apps.write\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_query\",\n operationId: \"tinycloud.apps.query\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n] as const;\n\n// Project once per process; never mutate the catalog shared with non-MCP consumers.\nconst definitions = new Map(generatedCatalog.operations.map((operation) => [\n `${operation.id}@${operation.version}`,\n {\n ...operation,\n input: toMcpJsonSchema(operation.input),\n result: toMcpJsonSchema(operation.result),\n },\n]));\n\nexport function createJsonSchemaValidator(): AjvJsonSchemaValidator {\n return new AjvJsonSchemaValidator();\n}\n\nexport function registerTinyCloudTools(\n server: McpServer,\n selection: McpStartupSelection,\n validator: AjvJsonSchemaValidator,\n): void {\n const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface));\n for (const binding of bindings) {\n const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);\n if (operation === undefined) {\n throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);\n }\n\n const inputSchema = fromJsonSchema(\n operation.input as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const outputSchema = fromJsonSchema(\n operation.result as unknown as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const annotations: ToolAnnotations = {\n readOnlyHint: binding.readOnlyHint,\n idempotentHint: binding.idempotentHint,\n destructiveHint: binding.destructiveHint,\n openWorldHint: binding.openWorldHint,\n };\n\n server.registerTool(\n binding.name,\n {\n title: operation.title,\n description: operation.description,\n inputSchema,\n outputSchema,\n annotations,\n },\n async (input: unknown): Promise<McpToolResult> => {\n const startedAt = performance.now();\n const metrics = { replayedGrants: 0 };\n let code = \"INTERNAL_ERROR\";\n try {\n await selection.beforeOperation?.();\n const result = await invokeOperation(\n binding.operationId,\n binding.operationVersion,\n invocationTargetForMcp(selection),\n input,\n metrics,\n );\n const projected = selection.transformOperationResult === undefined\n ? result\n : await selection.transformOperationResult(result, {\n operationId: binding.operationId,\n operationVersion: binding.operationVersion,\n input,\n });\n const response = toMcpToolResult(projected, bindings, {\n surface: selection.surface === \"local\" ? \"local\" : \"hosted\",\n readOnly: binding.readOnlyHint,\n operationId: binding.operationId,\n });\n code = outcomeCode(response.structuredContent);\n return response;\n } finally {\n if (selection.surface !== \"local\") {\n logToolCall(binding.name, code, startedAt, metrics.replayedGrants);\n }\n }\n },\n );\n }\n}\n\nfunction outcomeCode(result: McpToolResult[\"structuredContent\"]): string {\n if (result.status === \"error\") {\n const error = result.error as { code?: unknown } | undefined;\n return typeof error?.code === \"string\" && Object.hasOwn(stableErrorCodes, error.code) ? error.code : \"INTERNAL_ERROR\";\n }\n if (result.status !== \"ok\") return result.status;\n const output = result.output as { outcome?: unknown; ops?: readonly { outcome?: unknown }[] } | undefined;\n if (output?.outcome === \"COPY_PARTIAL\") return \"COPY_PARTIAL\";\n if (Array.isArray(output?.ops) && output.ops.some((op) => op.outcome !== \"ok\")) return \"PARTIAL\";\n return \"ok\";\n}\n\nexport function toolBindingsForTest(): readonly ToolBinding[] {\n return TOOL_BINDINGS;\n}\n","/** MCP preserves the canonical envelope; hosted clients also receive readable JSON. */\nexport interface CanonicalOperationResult {\n readonly status: \"ok\" | \"authority_required\" | \"setup_required\" | \"error\";\n readonly [key: string]: unknown;\n}\n\nexport interface McpToolResult extends CallToolResult {\n readonly content: [{ readonly type: \"text\"; readonly text: string }];\n readonly structuredContent: CanonicalOperationResult;\n}\n\n/** The binding fields needed to name the tool that runs an operation. */\nexport interface RecoveryToolBinding {\n readonly name: string;\n readonly operationId: string;\n}\n\nexport interface McpToolResultOptions {\n readonly surface?: \"hosted\" | \"local\";\n readonly readOnly?: boolean;\n /** Trusted operation identity from the tool binding, not operation output. */\n readonly operationId?: string;\n}\n\nexport function toMcpToolResult(\n result: unknown,\n bindings: readonly RecoveryToolBinding[] = [],\n options: McpToolResultOptions = {},\n): McpToolResult {\n let canonical: CanonicalOperationResult = isCanonicalOperationResult(result)\n ? withRecoveryTool(result, bindings)\n : {\n status: \"error\",\n operation: {},\n context: {},\n error: { code: \"INTERNAL_ERROR\" },\n };\n let serialized: string | undefined;\n if (options.surface === \"hosted\") {\n serialized = JSON.stringify(canonical);\n if (\n (options.readOnly === true ||\n options.operationId === \"tinycloud.apps.context\" ||\n options.operationId === \"tinycloud.apps.query\") &&\n serialized.length > 100_000\n ) {\n const sql = options.operationId?.startsWith(\"tinycloud.sql.\") ||\n options.operationId === \"tinycloud.apps.query\";\n canonical = {\n status: \"error\",\n operation: canonical.operation,\n context: canonical.context,\n error: {\n code: sql ? \"SQL_RESULT_LIMIT_EXCEEDED\" : \"KV_RESPONSE_TOO_LARGE\",\n message: sql\n ? \"The result exceeds 100,000 characters. Select fewer columns or rows, add a WHERE filter or a smaller LIMIT, or aggregate the data.\"\n : \"The result exceeds 100,000 characters. Request fewer keys, narrow the prefix, or use a smaller page size.\",\n retryable: false,\n },\n };\n serialized = JSON.stringify(canonical);\n }\n }\n\n return {\n content: [{\n type: \"text\",\n text: resultSummary(canonical.status) +\n (serialized !== undefined && !(options.operationId === \"tinycloud.secrets.get\" && canonical.status === \"ok\")\n ? `\\n${serialized}` : \"\"),\n }],\n structuredContent: canonical,\n };\n}\n\n/**\n * A redacted `complete_migration` recovery names an operation; MCP clients\n * call tools, so name the bound tool. `tool` comes from the code-owned binding\n * table only, never from operation data, and is added after redaction. An\n * operationId with no binding gets no `tool`.\n */\nfunction withRecoveryTool(\n result: CanonicalOperationResult,\n bindings: readonly RecoveryToolBinding[],\n): CanonicalOperationResult {\n if (result.status !== \"error\") return result;\n // The kernel's redaction already constrained `error.details.recovery` to a\n // safe recovery object; only its discriminant and operationId are read here.\n const error = result.error as\n | { readonly details?: { readonly recovery?: { readonly action?: unknown; readonly operationId?: unknown } } }\n | undefined;\n const recovery = error?.details?.recovery;\n if (recovery?.action !== \"complete_migration\") return result;\n const binding = bindings.find((candidate) => candidate.operationId === recovery.operationId);\n if (binding === undefined) return result;\n return {\n ...result,\n error: { ...error, details: { ...error?.details, recovery: { ...recovery, tool: binding.name } } },\n };\n}\n\n/** The canonical envelope immediately before MCP protocol serialization. */\nexport function canonicalMcpAdapterResult(result: unknown): CanonicalOperationResult {\n return toMcpToolResult(result).structuredContent;\n}\n\nfunction isCanonicalOperationResult(value: unknown): value is CanonicalOperationResult {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n const status = (value as { status?: unknown }).status;\n return status === \"ok\" ||\n status === \"authority_required\" ||\n status === \"setup_required\" ||\n status === \"error\";\n}\n\nfunction resultSummary(status: CanonicalOperationResult[\"status\"]): string {\n switch (status) {\n case \"ok\":\n return \"TinyCloud operation completed; use the structured result.\";\n case \"authority_required\":\n return \"TinyCloud authority is required; use the structured request and approval action.\";\n case \"setup_required\":\n return \"TinyCloud setup is required; use the structured setup action.\";\n case \"error\":\n return \"TinyCloud operation failed; use the structured error.\";\n }\n}\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n","/** Only code-owned tool names/codes and numeric counters reach this sink. */\nexport function logToolCall(\n tool: string,\n code: string,\n startedAt: number,\n replayedGrants: number,\n): void {\n process.stderr.write(`${JSON.stringify({\n tool,\n code,\n durationMs: Math.max(0, Math.round(performance.now() - startedAt)),\n replayedGrants,\n })}\\n`);\n}\n","type JsonSchema = boolean | Record<string, unknown>;\n\nconst DRAFT_7 = \"http://json-schema.org/draft-07/schema#\";\nconst DRAFT_2020_12 = \"https://json-schema.org/draft/2020-12/schema\";\nconst schemaMaps = new Set([\"properties\", \"patternProperties\", \"definitions\", \"$defs\"]);\nconst schemaArrays = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\nconst schemaValues = new Set([\n \"additionalProperties\", \"items\", \"contains\", \"propertyNames\", \"not\", \"if\", \"then\", \"else\",\n]);\n\n/** Project the catalog's shared Draft-07/2020-12 vocabulary without changing its validation rules. */\nexport function toMcpJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema {\n if (typeof schema === \"boolean\") return schema;\n // These forms need a semantic migration, not just a dialect declaration. The\n // generated catalog does not use them; fail closed if that contract changes.\n if (Array.isArray(schema.items) || \"additionalItems\" in schema || \"dependencies\" in schema ||\n (\"$ref\" in schema && Object.keys(schema).some((key) => key !== \"$ref\"))) {\n throw new Error(\"The operations schema needs a semantic migration to JSON Schema 2020-12.\");\n }\n\n const projected: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema)) {\n if (key === \"$schema\") {\n if (value !== DRAFT_7) throw new Error(`Unsupported operations schema dialect: ${String(value)}.`);\n projected[key] = DRAFT_2020_12;\n } else if (schemaMaps.has(key)) {\n projected[key] = Object.fromEntries(Object.entries(value as Record<string, JsonSchema>)\n .map(([name, child]) => [name, toMcpJsonSchema(child)]));\n } else if (schemaArrays.has(key)) {\n projected[key] = (value as JsonSchema[]).map(toMcpJsonSchema);\n } else if (schemaValues.has(key)) {\n projected[key] = toMcpJsonSchema(value as JsonSchema);\n } else {\n // Descriptions, defaults, examples and const/enum values are data, not schemas.\n projected[key] = value;\n }\n }\n return projected;\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AAErB,SAAS,sBAA4D;AACrE,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;;;ACmBzB,SAAS,gBACd,QACA,WAA2C,CAAC,GAC5C,UAAgC,CAAC,GAClB;AACf,MAAI,YAAsC,2BAA2B,MAAM,IACvE,iBAAiB,QAAQ,QAAQ,IACjC;AAAA,IACA,QAAQ;AAAA,IACR,WAAW,CAAC;AAAA,IACZ,SAAS,CAAC;AAAA,IACV,OAAO,EAAE,MAAM,iBAAiB;AAAA,EAClC;AACF,MAAI;AACJ,MAAI,QAAQ,YAAY,UAAU;AAChC,iBAAa,KAAK,UAAU,SAAS;AACrC,SACG,QAAQ,aAAa,QACpB,QAAQ,gBAAgB,4BACxB,QAAQ,gBAAgB,2BAC1B,WAAW,SAAS,KACpB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AuB,SAAS;AAAA,YAChC;AAAA,YACA;AAAA,UACF;AACA,gBAAM,YAAY,UAAU,6BAA6B,SACrD,SACA,MAAM,UAAU,yBAAyB,QAAQ;AAAA,YACjD,aAAa,QAAQ;AAAA,YACrB,kBAAkB,QAAQ;AAAA,YAC1B;AAAA,UACF,CAAC;AACH,gBAAM,WAAW,gBAAgB,WAAW,UAAU;AAAA,YACpD,SAAS,UAAU,YAAY,UAAU,UAAU;AAAA,YACnD,UAAU,QAAQ;AAAA,YAClB,aAAa,QAAQ;AAAA,UACvB,CAAC;AACD,iBAAO,YAAY,SAAS,iBAAiB;AAC7C,iBAAO;AAAA,QACT,UAAE;AACA,cAAI,UAAU,YAAY,SAAS;AACjC,wBAAY,QAAQ,MAAM,MAAM,WAAW,QAAQ,cAAc;AAAA,UACnE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,YAAY,QAAoD;AACvE,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,WAAO,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO,kBAAkB,MAAM,IAAI,IAAI,MAAM,OAAO;AAAA,EACvG;AACA,MAAI,OAAO,WAAW,KAAM,QAAO,OAAO;AAC1C,QAAM,SAAS,OAAO;AACtB,MAAI,QAAQ,YAAY,eAAgB,QAAO;AAC/C,MAAI,MAAM,QAAQ,QAAQ,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,EAAG,QAAO;AACvF,SAAO;AACT;AAEO,SAAS,sBAA8C;AAC5D,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/tools.ts","../src/results.ts","../src/logging.ts","../src/schemas.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { join } from \"node:path\";\n\nimport { fromJsonSchema, type McpServer, type ToolAnnotations } from \"@modelcontextprotocol/server\";\nimport { AjvJsonSchemaValidator } from \"@modelcontextprotocol/server/validators/ajv\";\nimport { invokeOperation } from \"@tinycloud/operations\";\n\nimport { toMcpToolResult, type McpToolResult } from \"./results.js\";\nimport { logToolCall } from \"./logging.js\";\nimport { toMcpJsonSchema } from \"./schemas.js\";\n\nexport const TOOL_NAMES = [\n \"tinycloud_status\",\n \"tinycloud_auth_status\",\n \"tinycloud_auth_capabilities\",\n \"tinycloud_auth_request\",\n \"tinycloud_auth_import\",\n \"tinycloud_account_spaces_list\",\n \"tinycloud_account_applications_list\",\n \"tinycloud_kv_list\",\n \"tinycloud_kv_get\",\n \"tinycloud_kv_head\",\n \"tinycloud_kv_put\",\n \"tinycloud_kv_delete\",\n \"tinycloud_knowledge_list\",\n \"tinycloud_knowledge_read\",\n \"tinycloud_sql_schema_inspect\",\n \"tinycloud_sql_query\",\n \"tinycloud_sql_execute\",\n \"tinycloud_secrets_get\",\n \"tinycloud_secrets_status\",\n \"tinycloud_apps_context\",\n \"tinycloud_apps_read\",\n \"tinycloud_apps_write\",\n \"tinycloud_apps_query\",\n] as const;\n\nexport type ToolName = (typeof TOOL_NAMES)[number];\n\n/** Private stdio/hosted surfaces and the restricted public plugin. */\nexport type McpSurface = \"local\" | \"hosted\" | \"public\";\n\nexport interface McpStartupSelection {\n /** Which server registers the tools; bindings not on this surface are skipped. */\n readonly surface: McpSurface;\n readonly profile: string;\n readonly explicitProfile: boolean;\n readonly allowOwnerProfile: boolean;\n /** Absolute TinyCloud home used to isolate one hosted principal. */\n readonly stateRoot?: string;\n /** Optional allowlist for surfaces whose grant is narrower than hosted OAuth. */\n readonly allowedTools?: readonly ToolName[];\n /** Check node authority only when an operation needs the account. */\n readonly beforeOperation?: () => Promise<void>;\n /** Hosted transports may attach a browser approval URL to canonical results. */\n readonly transformOperationResult?: (result: unknown, invocation: McpOperationInvocation) => Promise<unknown>;\n}\n\nexport interface McpOperationInvocation {\n readonly operationId: string;\n readonly operationVersion: number;\n readonly input: unknown;\n}\n\nexport interface McpInvocationTarget {\n readonly profile: string;\n readonly allowOwnerProfile?: true;\n readonly stateRoot?: string;\n}\n\n/** Project one startup selection into the only owner-sensitive target shape. */\nexport function invocationTargetForMcp(\n selection: Omit<McpStartupSelection, \"surface\">,\n): McpInvocationTarget {\n return {\n profile: selection.profile,\n ...(selection.explicitProfile && selection.allowOwnerProfile\n ? { allowOwnerProfile: true }\n : {}),\n ...(selection.stateRoot === undefined ? {} : { stateRoot: selection.stateRoot }),\n };\n}\n\ninterface CatalogOperation {\n readonly id: string;\n readonly version: number;\n readonly title: string;\n readonly description: string;\n readonly input: Record<string, unknown>;\n readonly result: Record<string, unknown>;\n}\n\ninterface OperationsCatalog {\n readonly stableErrors: readonly string[];\n readonly operations: readonly CatalogOperation[];\n}\n\n// The require anchor is this module, never the consumer entrypoint. In ESM\n// tsup preserves import.meta.url; in CJS it rewrites the same module-relative\n// anchor to the generated __filename, so both formats stay in MCP's package\n// dependency boundary.\nconst packageRequire = createRequire(\n typeof __dirname === \"string\" ? join(__dirname, \"tools.cjs\") : import.meta.url,\n);\nconst generatedCatalog = packageRequire(\n \"@tinycloud/operations/operations.json\",\n) as OperationsCatalog;\nconst stableErrorCodes: Readonly<Record<string, true>> = Object.fromEntries(\n generatedCatalog.stableErrors.map((code) => [code, true as const]),\n);\n\nexport interface ToolBinding {\n readonly name: ToolName;\n readonly operationId: string;\n readonly operationVersion: number;\n readonly readOnlyHint: boolean;\n readonly idempotentHint: boolean;\n readonly destructiveHint: boolean;\n readonly openWorldHint: boolean;\n /** Surfaces that register this tool; omitted means private local and hosted surfaces only. */\n readonly surfaces?: readonly McpSurface[];\n}\n\nconst PRIVATE_SURFACES: readonly McpSurface[] = [\"local\", \"hosted\"];\n\n/** The surfaces a binding is registered on. */\nexport function bindingSurfaces(binding: ToolBinding): readonly McpSurface[] {\n return binding.surfaces ?? PRIVATE_SURFACES;\n}\n\nexport const TOOL_BINDINGS: readonly ToolBinding[] = [\n {\n name: \"tinycloud_status\",\n operationId: \"tinycloud.status.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_status\",\n operationId: \"tinycloud.auth.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_capabilities\",\n operationId: \"tinycloud.auth.capabilities\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_request\",\n operationId: \"tinycloud.auth.request\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n },\n {\n name: \"tinycloud_auth_import\",\n operationId: \"tinycloud.auth.import\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n // Hosted delegations must arrive through the owner/request-bound OpenKey callback,\n // not a caller-supplied import artifact.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_account_spaces_list\",\n operationId: \"tinycloud.account.spaces.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_account_applications_list\",\n operationId: \"tinycloud.account.applications.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_list\",\n operationId: \"tinycloud.kv.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_get\",\n operationId: \"tinycloud.kv.get\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_head\",\n operationId: \"tinycloud.kv.head\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_put\",\n operationId: \"tinycloud.kv.put\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_kv_delete\",\n operationId: \"tinycloud.kv.delete\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_list\",\n operationId: \"tinycloud.knowledge.list\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_knowledge_read\",\n operationId: \"tinycloud.knowledge.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_schema_inspect\",\n operationId: \"tinycloud.sql.schema.inspect\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_query\",\n operationId: \"tinycloud.sql.query\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_sql_execute\",\n operationId: \"tinycloud.sql.execute\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_get\",\n operationId: \"tinycloud.secrets.get\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n },\n {\n name: \"tinycloud_secrets_status\",\n operationId: \"tinycloud.secrets.status\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: true,\n // Hosted has no persistent reauthorization path for a revoked session\n // yet (TC-896), so status is local/stdio only.\n surfaces: [\"local\"],\n },\n {\n name: \"tinycloud_apps_context\",\n operationId: \"tinycloud.apps.context\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_read\",\n operationId: \"tinycloud.apps.read\",\n operationVersion: 1,\n readOnlyHint: true,\n idempotentHint: true,\n destructiveHint: false,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_write\",\n operationId: \"tinycloud.apps.write\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n {\n name: \"tinycloud_apps_query\",\n operationId: \"tinycloud.apps.query\",\n operationVersion: 1,\n readOnlyHint: false,\n idempotentHint: true,\n destructiveHint: true,\n openWorldHint: false,\n surfaces: [\"hosted\", \"public\"],\n },\n] as const;\n\n// Project once per process; never mutate the catalog shared with non-MCP consumers.\nconst definitions = new Map(generatedCatalog.operations.map((operation) => [\n `${operation.id}@${operation.version}`,\n {\n ...operation,\n input: toMcpJsonSchema(operation.input),\n result: toMcpJsonSchema(operation.result),\n },\n]));\n\nexport function createJsonSchemaValidator(): AjvJsonSchemaValidator {\n return new AjvJsonSchemaValidator();\n}\n\nexport function registerTinyCloudTools(\n server: McpServer,\n selection: McpStartupSelection,\n validator: AjvJsonSchemaValidator,\n): void {\n const bindings = TOOL_BINDINGS.filter((binding) =>\n bindingSurfaces(binding).includes(selection.surface) &&\n (selection.allowedTools === undefined || selection.allowedTools.includes(binding.name)));\n for (const binding of bindings) {\n const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);\n if (operation === undefined) {\n throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);\n }\n\n const inputSchema = fromJsonSchema(\n operation.input as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const outputSchema = fromJsonSchema(\n operation.result as unknown as Parameters<typeof fromJsonSchema>[0],\n validator,\n );\n const annotations: ToolAnnotations = {\n readOnlyHint: binding.readOnlyHint,\n idempotentHint: binding.idempotentHint,\n destructiveHint: binding.destructiveHint,\n openWorldHint: binding.openWorldHint,\n };\n\n server.registerTool(\n binding.name,\n {\n title: operation.title,\n description: operation.description,\n inputSchema,\n outputSchema,\n annotations,\n },\n async (input: unknown): Promise<McpToolResult> => {\n const startedAt = performance.now();\n const metrics = { replayedGrants: 0 };\n let code = \"INTERNAL_ERROR\";\n try {\n await selection.beforeOperation?.();\n const result = await invokeOperation(\n binding.operationId,\n binding.operationVersion,\n invocationTargetForMcp(selection),\n input,\n metrics,\n );\n const projected = selection.transformOperationResult === undefined\n ? result\n : await selection.transformOperationResult(result, {\n operationId: binding.operationId,\n operationVersion: binding.operationVersion,\n input,\n });\n const response = toMcpToolResult(projected, bindings, {\n surface: selection.surface === \"local\" ? \"local\" : \"hosted\",\n readOnly: binding.readOnlyHint,\n operationId: binding.operationId,\n });\n code = outcomeCode(response.structuredContent);\n return response;\n } finally {\n if (selection.surface !== \"local\") {\n logToolCall(binding.name, code, startedAt, metrics.replayedGrants);\n }\n }\n },\n );\n }\n}\n\nfunction outcomeCode(result: McpToolResult[\"structuredContent\"]): string {\n if (result.status === \"error\") {\n const error = result.error as { code?: unknown } | undefined;\n return typeof error?.code === \"string\" && Object.hasOwn(stableErrorCodes, error.code) ? error.code : \"INTERNAL_ERROR\";\n }\n if (result.status !== \"ok\") return result.status;\n const output = result.output as { outcome?: unknown; ops?: readonly { outcome?: unknown }[] } | undefined;\n if (output?.outcome === \"COPY_PARTIAL\") return \"COPY_PARTIAL\";\n if (Array.isArray(output?.ops) && output.ops.some((op) => op.outcome !== \"ok\")) return \"PARTIAL\";\n return \"ok\";\n}\n\nexport function toolBindingsForTest(): readonly ToolBinding[] {\n return TOOL_BINDINGS;\n}\n","/** MCP preserves the canonical envelope; hosted clients also receive readable JSON. */\nexport interface CanonicalOperationResult {\n readonly status: \"ok\" | \"authority_required\" | \"setup_required\" | \"error\";\n readonly [key: string]: unknown;\n}\n\nexport interface McpToolResult extends CallToolResult {\n readonly content: [{ readonly type: \"text\"; readonly text: string }];\n readonly structuredContent: CanonicalOperationResult;\n}\n\n/** The binding fields needed to name the tool that runs an operation. */\nexport interface RecoveryToolBinding {\n readonly name: string;\n readonly operationId: string;\n}\n\nexport interface McpToolResultOptions {\n readonly surface?: \"hosted\" | \"local\";\n readonly readOnly?: boolean;\n /** Trusted operation identity from the tool binding, not operation output. */\n readonly operationId?: string;\n}\n\nexport function toMcpToolResult(\n result: unknown,\n bindings: readonly RecoveryToolBinding[] = [],\n options: McpToolResultOptions = {},\n): McpToolResult {\n let canonical: CanonicalOperationResult = isCanonicalOperationResult(result)\n ? withRecoveryTool(result, bindings)\n : {\n status: \"error\",\n operation: {},\n context: {},\n error: { code: \"INTERNAL_ERROR\" },\n };\n let serialized: string | undefined;\n if (options.surface === \"hosted\") {\n serialized = JSON.stringify(canonical);\n if (\n (options.readOnly === true ||\n options.operationId === \"tinycloud.apps.context\" ||\n options.operationId === \"tinycloud.apps.query\") &&\n serialized.length > 100_000\n ) {\n const sql = options.operationId?.startsWith(\"tinycloud.sql.\") ||\n options.operationId === \"tinycloud.apps.query\";\n canonical = {\n status: \"error\",\n operation: canonical.operation,\n context: canonical.context,\n error: {\n code: sql ? \"SQL_RESULT_LIMIT_EXCEEDED\" : \"KV_RESPONSE_TOO_LARGE\",\n message: sql\n ? \"The result exceeds 100,000 characters. Select fewer columns or rows, add a WHERE filter or a smaller LIMIT, or aggregate the data.\"\n : \"The result exceeds 100,000 characters. Request fewer keys, narrow the prefix, or use a smaller page size.\",\n retryable: false,\n },\n };\n serialized = JSON.stringify(canonical);\n }\n }\n\n return {\n content: [{\n type: \"text\",\n text: resultSummary(canonical.status) +\n (serialized !== undefined && !(options.operationId === \"tinycloud.secrets.get\" && canonical.status === \"ok\")\n ? `\\n${serialized}` : \"\"),\n }],\n structuredContent: canonical,\n };\n}\n\n/**\n * A redacted `complete_migration` recovery names an operation; MCP clients\n * call tools, so name the bound tool. `tool` comes from the code-owned binding\n * table only, never from operation data, and is added after redaction. An\n * operationId with no binding gets no `tool`.\n */\nfunction withRecoveryTool(\n result: CanonicalOperationResult,\n bindings: readonly RecoveryToolBinding[],\n): CanonicalOperationResult {\n if (result.status !== \"error\") return result;\n // The kernel's redaction already constrained `error.details.recovery` to a\n // safe recovery object; only its discriminant and operationId are read here.\n const error = result.error as\n | { readonly details?: { readonly recovery?: { readonly action?: unknown; readonly operationId?: unknown } } }\n | undefined;\n const recovery = error?.details?.recovery;\n if (recovery?.action !== \"complete_migration\") return result;\n const binding = bindings.find((candidate) => candidate.operationId === recovery.operationId);\n if (binding === undefined) return result;\n return {\n ...result,\n error: { ...error, details: { ...error?.details, recovery: { ...recovery, tool: binding.name } } },\n };\n}\n\n/** The canonical envelope immediately before MCP protocol serialization. */\nexport function canonicalMcpAdapterResult(result: unknown): CanonicalOperationResult {\n return toMcpToolResult(result).structuredContent;\n}\n\nfunction isCanonicalOperationResult(value: unknown): value is CanonicalOperationResult {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n const status = (value as { status?: unknown }).status;\n return status === \"ok\" ||\n status === \"authority_required\" ||\n status === \"setup_required\" ||\n status === \"error\";\n}\n\nfunction resultSummary(status: CanonicalOperationResult[\"status\"]): string {\n switch (status) {\n case \"ok\":\n return \"TinyCloud operation completed; use the structured result.\";\n case \"authority_required\":\n return \"TinyCloud authority is required; use the structured request and approval action.\";\n case \"setup_required\":\n return \"TinyCloud setup is required; use the structured setup action.\";\n case \"error\":\n return \"TinyCloud operation failed; use the structured error.\";\n }\n}\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n","/** Only code-owned tool names/codes and numeric counters reach this sink. */\nexport function logToolCall(\n tool: string,\n code: string,\n startedAt: number,\n replayedGrants: number,\n): void {\n process.stderr.write(`${JSON.stringify({\n tool,\n code,\n durationMs: Math.max(0, Math.round(performance.now() - startedAt)),\n replayedGrants,\n })}\\n`);\n}\n","type JsonSchema = boolean | Record<string, unknown>;\n\nconst DRAFT_7 = \"http://json-schema.org/draft-07/schema#\";\nconst DRAFT_2020_12 = \"https://json-schema.org/draft/2020-12/schema\";\nconst schemaMaps = new Set([\"properties\", \"patternProperties\", \"definitions\", \"$defs\"]);\nconst schemaArrays = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\nconst schemaValues = new Set([\n \"additionalProperties\", \"items\", \"contains\", \"propertyNames\", \"not\", \"if\", \"then\", \"else\",\n]);\n\n/** Project the catalog's shared Draft-07/2020-12 vocabulary without changing its validation rules. */\nexport function toMcpJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema;\nexport function toMcpJsonSchema(schema: JsonSchema): JsonSchema {\n if (typeof schema === \"boolean\") return schema;\n // These forms need a semantic migration, not just a dialect declaration. The\n // generated catalog does not use them; fail closed if that contract changes.\n if (Array.isArray(schema.items) || \"additionalItems\" in schema || \"dependencies\" in schema ||\n (\"$ref\" in schema && Object.keys(schema).some((key) => key !== \"$ref\"))) {\n throw new Error(\"The operations schema needs a semantic migration to JSON Schema 2020-12.\");\n }\n\n const projected: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema)) {\n if (key === \"$schema\") {\n if (value !== DRAFT_7) throw new Error(`Unsupported operations schema dialect: ${String(value)}.`);\n projected[key] = DRAFT_2020_12;\n } else if (schemaMaps.has(key)) {\n projected[key] = Object.fromEntries(Object.entries(value as Record<string, JsonSchema>)\n .map(([name, child]) => [name, toMcpJsonSchema(child)]));\n } else if (schemaArrays.has(key)) {\n projected[key] = (value as JsonSchema[]).map(toMcpJsonSchema);\n } else if (schemaValues.has(key)) {\n projected[key] = toMcpJsonSchema(value as JsonSchema);\n } else {\n // Descriptions, defaults, examples and const/enum values are data, not schemas.\n projected[key] = value;\n }\n }\n return projected;\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AAErB,SAAS,sBAA4D;AACrE,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;;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M,QAAO,OAAO;AAC1C,QAAM,SAAS,OAAO;AACtB,MAAI,QAAQ,YAAY,eAAgB,QAAO;AAC/C,MAAI,MAAM,QAAQ,QAAQ,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,EAAG,QAAO;AACvF,SAAO;AACT;AAEO,SAAS,sBAA8C;AAC5D,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloud/mcp",
|
|
3
|
-
"version": "0.8.3-beta.
|
|
3
|
+
"version": "0.8.3-beta.20",
|
|
4
4
|
"description": "TinyCloud delegated operations MCP server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tinycloud",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
73
73
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
74
|
-
"@tinycloud/node-sdk": "3.8.0-beta.
|
|
74
|
+
"@tinycloud/node-sdk": "3.8.0-beta.18",
|
|
75
75
|
"@tinycloud/node-sdk-wasm": "1.7.8",
|
|
76
|
-
"@tinycloud/operations": "0.7.7-beta.
|
|
76
|
+
"@tinycloud/operations": "0.7.7-beta.17",
|
|
77
77
|
"jose": "6.2.4"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
@@ -37,7 +37,7 @@ Coverage is generated from the Commander registration ledger; legacy commands ar
|
|
|
37
37
|
|
|
38
38
|
- 4 migrated registration(s).
|
|
39
39
|
- 1 partially migrated registration(s).
|
|
40
|
-
-
|
|
40
|
+
- 148 legacy registration(s) remain Commander-owned.
|
|
41
41
|
- `auth import [source]` → `tinycloud.auth.import@1` (partially-migrated; remaining legacy inputs: v1 delegation artifact, v1 permission artifact without command, bare portable delegation, stored delegation wrapper, cross-user delegation persisted with activated=false).
|
|
42
42
|
- `secrets get <name>` → `tinycloud.secrets.get@1` (migrated).
|
|
43
43
|
- `secrets probe <name>` → `tinycloud.secrets.status@1` (migrated).
|
|
@@ -47,6 +47,10 @@ Coverage is generated from the Commander registration ledger; legacy commands ar
|
|
|
47
47
|
|
|
48
48
|
## Account and KV exploration
|
|
49
49
|
|
|
50
|
+
With hosted Streamable HTTP, call `tinycloud_connect`, give the owner the returned `approvalUrl` to approve in OpenKey, then call `tinycloud_connect` again. When a tool returns `authority_required` with `approval.url`, give the owner that link, wait for their approval, then retry the same call unchanged. If the result has no `approval.url`, stop and report it; don't try another route. The `tc auth request` / `tc auth import` and `tinycloud_auth_import` instructions below are for local stdio only. See the [hosted MCP guide](https://docs.tinycloud.xyz/cli/mcp).
|
|
51
|
+
|
|
52
|
+
The `tc auth grant --stdin --yes` artifact, import, restart, and retry steps below apply to local stdio only; hosted operations use a returned `approval.url` as described above.
|
|
53
|
+
|
|
50
54
|
1. A fresh `delegate-session` profile must first bootstrap its session through
|
|
51
55
|
the CLI: emit one exact `tc auth request --cap ...` artifact, have the owner
|
|
52
56
|
grant that artifact, and import the result with `tc auth import`. Start MCP
|
|
@@ -107,9 +111,19 @@ transcripts, caches, or evaluation records. TinyCloud controls only its own
|
|
|
107
111
|
logs and local profile state, not host-side transcript retention. Hosts should
|
|
108
112
|
apply their own sensitive-result retention and access controls.
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
The canonical remote service is hosted MCP at
|
|
115
|
+
`https://mcp.tinycloud.xyz/mcp` using Streamable HTTP and OpenKey OAuth.
|
|
116
|
+
Connect Claude through its remote MCP connector and complete OpenKey OAuth.
|
|
117
|
+
ChatGPT users can add `https://mcp.tinycloud.xyz/mcp` on the web under Plugins → + → Add custom MCP server; Developer Mode isn't required first.
|
|
118
|
+
Availability depends on the ChatGPT plan and workspace settings. Follow
|
|
119
|
+
[OpenAI's custom MCP connection guide](https://help.openai.com/en/articles/12584461-connecting-custom-mcp-servers-in-chatgpt).
|
|
120
|
+
|
|
121
|
+
Local stdio is the alternative: install `@tinycloud/cli` and `@tinycloud/mcp`,
|
|
122
|
+
then configure `tinycloud-mcp` in the client's stdio MCP settings.
|
|
123
|
+
Connection documentation: https://docs.tinycloud.xyz/cli/mcp
|
|
124
|
+
|
|
125
|
+
The MCP server has no resources, prompts, elicitation, generic permission grant,
|
|
126
|
+
or secret mutation tool.
|
|
113
127
|
|
|
114
128
|
This is a beta surface. Delegated posture is the default; owner-profile data
|
|
115
129
|
access requires explicit opt-in. The user must enter secrets only in Secret
|