@databrainhq/mcp-server 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -326,7 +326,7 @@ var DatabrainClient = class {
326
326
  }
327
327
  const text = await response.text();
328
328
  let data = text ? JSON.parse(text) : {};
329
- if (data && typeof data === "object" && !Array.isArray(data) && "data" in data) {
329
+ if (!options.skipDataUnwrap && data && typeof data === "object" && !Array.isArray(data) && "data" in data) {
330
330
  const inner = data.data;
331
331
  if (inner !== null && inner !== void 0) {
332
332
  data = inner;
@@ -735,9 +735,10 @@ var TenantsApi = class {
735
735
  }
736
736
  return this.client.request({
737
737
  method: "POST",
738
- path: "/hasuraActions/getClientData",
738
+ path: "/api/mcp/getClientData",
739
739
  auth: "service",
740
740
  body: { input: { input } },
741
+ skipDataUnwrap: true,
741
742
  cacheKey: `list_tenants:${JSON.stringify(input)}`,
742
743
  cacheTtlMs: 5 * 60 * 1e3
743
744
  });
@@ -6044,26 +6045,97 @@ function registerCreateOrUpdateMetricFromQuery(server, client) {
6044
6045
  );
6045
6046
  }
6046
6047
 
6047
- // src/tools/widgets/validate-metric-spec.ts
6048
+ // src/tools/widgets/create-workspace-metric.ts
6048
6049
  import { z as z31 } from "zod";
6050
+ var modeSchema2 = z31.enum(["dry_run", "apply"]).default("dry_run");
6051
+ function registerCreateWorkspaceMetric(server, client) {
6052
+ server.tool(
6053
+ "create_workspace_metric",
6054
+ "Create a workspace-level metric from validated SQL using the org service token. Scoped to the workspace, unpublished, and NOT attached to any dashboard. Defaults to dry-run; apply requires explicit confirmation.",
6055
+ {
6056
+ mode: modeSchema2.describe(
6057
+ "dry_run validates the SQL only (no write); apply creates the metric after confirmation"
6058
+ ),
6059
+ confirm: z31.string().optional().describe(`Required for apply: ${APPLY_TO_PRODUCTION_CONFIRMATION}`),
6060
+ workspaceName: z31.string().describe("Target workspace name"),
6061
+ name: z31.string().describe("Metric display name"),
6062
+ query: z31.string().describe("SQL query to validate and store"),
6063
+ metricId: z31.string().optional().describe("Stable metric slug; generated from the name if omitted"),
6064
+ description: z31.string().optional().describe("Metric description"),
6065
+ datasourceId: z31.string().optional().describe("Datasource UUID override; defaults to the workspace datasource"),
6066
+ isPublished: z31.boolean().optional().describe("Publish after apply. Defaults to false for safety")
6067
+ },
6068
+ WRITE_CREATE,
6069
+ async (params) => {
6070
+ try {
6071
+ const mode = params.mode || "dry_run";
6072
+ if (!params.name.trim()) return toolError("`name` cannot be empty.");
6073
+ if (!params.query.trim()) return toolError("`query` cannot be empty.");
6074
+ const isApply = mode === "apply";
6075
+ if (isApply) {
6076
+ const guardError = validateProductionApply({
6077
+ workspaceName: params.workspaceName,
6078
+ confirm: params.confirm
6079
+ });
6080
+ if (guardError) return toolError(guardError);
6081
+ }
6082
+ const body = {
6083
+ workspaceName: params.workspaceName,
6084
+ name: params.name,
6085
+ query: params.query,
6086
+ metricId: params.metricId,
6087
+ description: params.description,
6088
+ datasourceId: params.datasourceId,
6089
+ isPublished: params.isPublished ?? false,
6090
+ validateOnly: !isApply
6091
+ };
6092
+ const result = await client.request({
6093
+ method: "POST",
6094
+ // MCP-only control-plane route (not the public /api/v2 surface).
6095
+ path: "/api/mcp/metrics/create",
6096
+ auth: "service",
6097
+ body
6098
+ });
6099
+ return toolSuccess(
6100
+ JSON.stringify(
6101
+ {
6102
+ mode,
6103
+ safety: productionSafetyNote(params.workspaceName),
6104
+ result,
6105
+ nextStep: isApply ? "Metric created unpublished and unattached. Publish/attach it to a dashboard as a separate step when ready." : 'Dry-run only \u2014 no metric written. Re-run with mode "apply" and confirm to create it.'
6106
+ },
6107
+ null,
6108
+ 2
6109
+ )
6110
+ );
6111
+ } catch (err) {
6112
+ if (err instanceof DatabrainApiError) return err.toToolResponse();
6113
+ return toolError(`Unexpected error: ${err.message}`);
6114
+ }
6115
+ }
6116
+ );
6117
+ }
6118
+
6119
+ // src/tools/widgets/validate-metric-spec.ts
6120
+ import { z as z32 } from "zod";
6049
6121
  function registerValidateMetricSpec(server, client) {
6050
6122
  const services = createServiceBundle(client);
6051
6123
  server.tool(
6052
6124
  "validate_metric_spec",
6053
6125
  "Validate a production metric spec from SQL without saving it. Resolves dashboard, data app, datasource, conflicts, and required fields.",
6054
6126
  {
6055
- clientId: z31.string().describe("Client/tenant identifier used to validate dashboard widget scope"),
6056
- workspaceName: z31.string().describe("Target production-backed workspace name"),
6057
- dashboardName: z31.string().optional().describe("Dashboard name to attach to"),
6058
- embedId: z31.string().optional().describe("Technical embed id alternative to dashboardName"),
6059
- dataAppName: z31.string().optional().describe("Optional data app override"),
6060
- name: z31.string().describe("Metric/widget display name"),
6061
- metricId: z31.string().describe("Stable metric slug to create or update"),
6062
- query: z31.string().describe("SQL query already validated against the warehouse"),
6063
- description: z31.string().optional().describe("Metric description"),
6064
- chartOptions: z31.record(z31.unknown()).optional().describe("Chart configuration JSON"),
6065
- companyIntegrationId: z31.string().optional().describe("Datasource UUID override"),
6066
- integrationName: z31.string().optional().describe("Datasource display name override")
6127
+ clientId: z32.string().describe("Client/tenant identifier used to validate dashboard widget scope"),
6128
+ workspaceName: z32.string().describe("Target production-backed workspace name"),
6129
+ dashboardName: z32.string().optional().describe("Dashboard name to attach to"),
6130
+ embedId: z32.string().optional().describe("Technical embed id alternative to dashboardName"),
6131
+ dataAppName: z32.string().optional().describe("Optional data app override"),
6132
+ name: z32.string().describe("Metric/widget display name"),
6133
+ metricId: z32.string().describe("Stable metric slug to create or update"),
6134
+ query: z32.string().describe("SQL query already validated against the warehouse"),
6135
+ description: z32.string().optional().describe("Metric description"),
6136
+ chartOptions: z32.record(z32.unknown()).optional().describe("Chart configuration JSON"),
6137
+ companyIntegrationId: z32.string().optional().describe("Datasource UUID override"),
6138
+ integrationName: z32.string().optional().describe("Datasource display name override")
6067
6139
  },
6068
6140
  READ_ONLY,
6069
6141
  async (params) => {
@@ -6154,20 +6226,20 @@ function registerValidateMetricSpec(server, client) {
6154
6226
  }
6155
6227
 
6156
6228
  // src/tools/reports/list-scheduled-reports.ts
6157
- import { z as z32 } from "zod";
6229
+ import { z as z33 } from "zod";
6158
6230
  function registerListScheduledReports(server, client) {
6159
6231
  const services = createServiceBundle(client);
6160
6232
  server.tool(
6161
6233
  "list_scheduled_reports",
6162
6234
  "List configured scheduled reports for a specific client/dashboard embed. Shows schedule metadata, not delivery success history.",
6163
6235
  {
6164
- clientId: z32.string().describe("Client/tenant identifier. Required by the current backend API for non-empty results"),
6165
- dashboardName: z32.string().optional().describe("Dashboard name to inspect"),
6166
- workspaceName: z32.string().optional().describe("Workspace name if dashboardName is ambiguous"),
6167
- embedId: z32.string().optional().describe("Technical embed id alternative to dashboardName"),
6168
- userIdentifier: z32.string().optional().describe("Optional creator/user filter"),
6169
- pageNumber: z32.number().int().positive().optional().describe("Page number when pagination is enabled"),
6170
- isPagination: z32.boolean().optional().describe("Enable backend pagination")
6236
+ clientId: z33.string().describe("Client/tenant identifier. Required by the current backend API for non-empty results"),
6237
+ dashboardName: z33.string().optional().describe("Dashboard name to inspect"),
6238
+ workspaceName: z33.string().optional().describe("Workspace name if dashboardName is ambiguous"),
6239
+ embedId: z33.string().optional().describe("Technical embed id alternative to dashboardName"),
6240
+ userIdentifier: z33.string().optional().describe("Optional creator/user filter"),
6241
+ pageNumber: z33.number().int().positive().optional().describe("Page number when pagination is enabled"),
6242
+ isPagination: z33.boolean().optional().describe("Enable backend pagination")
6171
6243
  },
6172
6244
  READ_ONLY,
6173
6245
  async (params) => {
@@ -6300,6 +6372,7 @@ function registerAllTools(server, client) {
6300
6372
  registerListWidgets(server, client);
6301
6373
  registerValidateMetricSpec(server, client);
6302
6374
  registerCreateOrUpdateMetricFromQuery(server, client);
6375
+ registerCreateWorkspaceMetric(server, client);
6303
6376
  registerAddWidget(server, client);
6304
6377
  registerUpdateWidget(server, client);
6305
6378
  registerRemoveWidget(server, client);