@malloy-publisher/server 0.0.232 → 0.0.234

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.
Files changed (83) hide show
  1. package/README.docker.md +1 -0
  2. package/dist/app/api-doc.yaml +269 -10
  3. package/dist/app/assets/{EnvironmentPage-DXEaZIPx.js → EnvironmentPage-DTZQ4Gxc.js} +1 -1
  4. package/dist/app/assets/{HomePage-kofsqpZt.js → HomePage-C5mlDPXK.js} +1 -1
  5. package/dist/app/assets/{LightMode-CNhIlIlJ.js → LightMode-DGNmhG0u.js} +1 -1
  6. package/dist/app/assets/{MainPage-Bgqo8jCy.js → MainPage-CVL_wmP4.js} +1 -1
  7. package/dist/app/assets/{MaterializationsPage-CgBlgGz2.js → MaterializationsPage-DmzMBCpy.js} +1 -1
  8. package/dist/app/assets/{ModelPage-B0TjoDtf.js → ModelPage-Dbvf4QbB.js} +1 -1
  9. package/dist/app/assets/{PackagePage-BL8vnFj1.js → PackagePage-DxdHc2Qs.js} +1 -1
  10. package/dist/app/assets/{RouteError-BzPby0X2.js → RouteError-OJdT4tCd.js} +1 -1
  11. package/dist/app/assets/{ThemeEditorPage-CTEP_9r3.js → ThemeEditorPage-Bk7s0KXY.js} +1 -1
  12. package/dist/app/assets/{WorkbookPage-BwM3BmKw.js → WorkbookPage-j_vCWdN3.js} +1 -1
  13. package/dist/app/assets/{core-CK68iv6w.es-CpRxXBt7.js → core-Rj_4rRnA.es-DoIfLxDJ.js} +1 -1
  14. package/dist/app/assets/{index-B33zGctF.js → index-B_jKMR35.js} +4 -4
  15. package/dist/app/assets/{index-CmkW1MiE.js → index-D-rDyK11.js} +1 -1
  16. package/dist/app/assets/{index-tXJXwdyj.js → index-DWIe_hK0.js} +1 -1
  17. package/dist/app/assets/{index-BkiWKaAF.js → index-hw-xn0X7.js} +1 -1
  18. package/dist/app/index.html +1 -1
  19. package/dist/package_load_worker.mjs +53 -3
  20. package/dist/server.mjs +20277 -925
  21. package/package.json +1 -1
  22. package/src/config.ts +35 -1
  23. package/src/controller/connection.controller.spec.ts +46 -0
  24. package/src/controller/connection.controller.ts +105 -2
  25. package/src/controller/materialization.controller.spec.ts +25 -0
  26. package/src/controller/materialization.controller.ts +60 -0
  27. package/src/controller/model.controller.ts +24 -0
  28. package/src/controller/query.controller.ts +83 -10
  29. package/src/json_utils.spec.ts +51 -0
  30. package/src/json_utils.ts +33 -0
  31. package/src/mcp/handler_utils.ts +10 -2
  32. package/src/mcp/query_envelope.spec.ts +229 -0
  33. package/src/mcp/query_envelope.ts +240 -0
  34. package/src/mcp/server.protocol.spec.ts +128 -16
  35. package/src/mcp/skills/build_skills_bundle.ts +94 -4
  36. package/src/mcp/skills/skills_bundle.json +1 -1
  37. package/src/mcp/skills/skills_bundle.spec.ts +113 -4
  38. package/src/mcp/tool_response.spec.ts +108 -0
  39. package/src/mcp/tool_response.ts +138 -0
  40. package/src/mcp/tools/compile_tool.spec.ts +112 -4
  41. package/src/mcp/tools/compile_tool.ts +61 -30
  42. package/src/mcp/tools/docs_search_tool.ts +6 -16
  43. package/src/mcp/tools/execute_query_tool.spec.ts +154 -3
  44. package/src/mcp/tools/execute_query_tool.ts +131 -155
  45. package/src/mcp/tools/get_context_tool.spec.ts +63 -3
  46. package/src/mcp/tools/get_context_tool.ts +43 -46
  47. package/src/mcp/tools/reload_package_tool.ts +3 -29
  48. package/src/mcp_config.spec.ts +919 -0
  49. package/src/mcp_config.ts +425 -0
  50. package/src/oom_guards.integration.spec.ts +11 -3
  51. package/src/package_load/package_load_pool.ts +2 -0
  52. package/src/package_load/package_load_worker.ts +17 -5
  53. package/src/package_load/protocol.ts +6 -0
  54. package/src/query_metadata_metrics.ts +49 -0
  55. package/src/server.ts +99 -3
  56. package/src/service/build_plan.spec.ts +125 -0
  57. package/src/service/build_plan.ts +108 -7
  58. package/src/service/compile_fragment_techniques.spec.ts +156 -0
  59. package/src/service/connection.spec.ts +371 -1
  60. package/src/service/connection.ts +77 -14
  61. package/src/service/connection_config.spec.ts +60 -0
  62. package/src/service/connection_config.ts +75 -0
  63. package/src/service/duckdb_instance_isolation.spec.ts +137 -0
  64. package/src/service/environment.ts +57 -3
  65. package/src/service/materialization_config_validation.spec.ts +99 -0
  66. package/src/service/materialization_config_validation.ts +120 -0
  67. package/src/service/materialization_schedule_surface.spec.ts +124 -0
  68. package/src/service/materialization_service.spec.ts +119 -0
  69. package/src/service/materialization_service.ts +186 -3
  70. package/src/service/materialization_test_fixtures.ts +86 -21
  71. package/src/service/model.spec.ts +45 -1
  72. package/src/service/model.ts +171 -23
  73. package/src/service/model_limits.spec.ts +28 -0
  74. package/src/service/model_limits.ts +21 -0
  75. package/src/service/package.ts +24 -1
  76. package/src/service/package_manifest.spec.ts +137 -4
  77. package/src/service/package_manifest.ts +140 -5
  78. package/src/service/persist_annotation_validation.spec.ts +12 -0
  79. package/src/service/persist_annotation_validation.ts +9 -4
  80. package/src/service/query_metadata.spec.ts +408 -0
  81. package/src/service/query_metadata.ts +492 -0
  82. package/src/service/query_metadata_identity.spec.ts +149 -0
  83. package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +37 -12
@@ -18,6 +18,7 @@ import {
18
18
  } from "./get_context_tool";
19
19
  import { embeddingText } from "./embedding_index";
20
20
  import type { EnvironmentStore } from "../../service/environment_store";
21
+ import { PackageNotFoundError } from "../../errors";
21
22
  import { DuckDBConnection } from "../../storage/duckdb/DuckDBConnection";
22
23
  import { createEntityEmbeddingsTable } from "../../storage/duckdb/schema";
23
24
  import {
@@ -132,9 +133,15 @@ describe("get_context sanitize", () => {
132
133
 
133
134
  // Capture the tool handler that registerGetContextTool passes to McpServer.tool,
134
135
  // so each discovery tier can be exercised against a mocked EnvironmentStore.
136
+ type Content = Array<{
137
+ type?: string;
138
+ text?: string;
139
+ resource?: { text: string };
140
+ }>;
141
+
135
142
  type Handler = (params: Record<string, unknown>) => Promise<{
136
143
  isError?: boolean;
137
- content: Array<{ resource: { text: string } }>;
144
+ content: Content;
138
145
  }>;
139
146
 
140
147
  function captureHandler(store: Partial<EnvironmentStore>): Handler {
@@ -149,8 +156,12 @@ function captureHandler(store: Partial<EnvironmentStore>): Handler {
149
156
  return handler;
150
157
  }
151
158
 
152
- function parse(result: { content: Array<{ resource: { text: string } }> }) {
153
- return JSON.parse(result.content[0].resource.text);
159
+ function parse(result: { content: Content }) {
160
+ return JSON.parse(result.content[0].resource!.text);
161
+ }
162
+
163
+ function textBlock(result: { content: Content }) {
164
+ return result.content.find((b) => b.type === "text")?.text;
154
165
  }
155
166
 
156
167
  // A model with one source (order_items) carrying one dimension (state).
@@ -242,6 +253,53 @@ describe("get_context discovery tiers", () => {
242
253
  const parsed = parse(result);
243
254
  expect(parsed.results).toEqual([]);
244
255
  expect(parsed.error).toContain("could not be resolved");
256
+ // Suggestions and a text block, same as this tool's three siblings. Both
257
+ // were absent before: the payload carried a bare message, and a
258
+ // text-only client saw nothing at all.
259
+ expect(parsed.suggestions.length).toBeGreaterThan(0);
260
+ expect(textBlock(result)).toContain("could not be resolved");
261
+ });
262
+
263
+ it("reports an unknown package as not-found, not as an internal fault", async () => {
264
+ // Pins the classification, not just that an error came back. Before this
265
+ // routed through classifyToolError every failure arrived as the raw
266
+ // message with no remediation, so a typo'd package name gave the agent
267
+ // nothing to act on.
268
+ const handler = captureHandler({
269
+ getEnvironment: async () =>
270
+ ({
271
+ getPackage: async () => {
272
+ throw new PackageNotFoundError("Package 'nope' not found");
273
+ },
274
+ }) as never,
275
+ });
276
+ const result = await handler({
277
+ environmentName: "malloy-samples",
278
+ packageName: "nope",
279
+ query: "state",
280
+ });
281
+ expect(result.isError).toBe(true);
282
+ const parsed = parse(result);
283
+ expect(parsed.results).toEqual([]);
284
+ expect(parsed.error).toContain("Resource not found");
285
+ expect(parsed.error).toContain("nope");
286
+ expect(textBlock(result)).toContain("Resource not found");
287
+ });
288
+
289
+ it("reports a non-Error throwable without inventing 'Unknown error'", async () => {
290
+ // The old per-site `error instanceof Error ? error.message : "Unknown
291
+ // error"` turned a thrown string into exactly the unhelpful text this
292
+ // tool's callers reported. classifyToolError stringifies it instead.
293
+ const handler = captureHandler({
294
+ listEnvironments: async () => {
295
+ throw "the store exploded";
296
+ },
297
+ });
298
+ const result = await handler({});
299
+ const parsed = parse(result);
300
+ expect(parsed.error).toContain("the store exploded");
301
+ expect(parsed.error).not.toContain("Unknown error");
302
+ expect(textBlock(result)).toContain("the store exploded");
245
303
  });
246
304
 
247
305
  it("tier 3: package without a query lists only its sources", async () => {
@@ -299,6 +357,8 @@ describe("get_context discovery tiers", () => {
299
357
  const parsed = parse(result);
300
358
  expect(parsed.results).toEqual([]);
301
359
  expect(parsed.error).toContain("not initialized");
360
+ expect(parsed.suggestions.length).toBeGreaterThan(0);
361
+ expect(textBlock(result)).toContain("not initialized");
302
362
  });
303
363
 
304
364
  it("tier 3: lists every source, not just the first 10", async () => {
@@ -8,7 +8,8 @@ import {
8
8
  embeddingConfigured,
9
9
  getEmbeddingProvider,
10
10
  } from "../../service/embedding_provider";
11
- import { buildMalloyUri } from "../handler_utils";
11
+ import { buildMalloyUri, classifyToolError } from "../handler_utils";
12
+ import { jsonResource, jsonToolError } from "../tool_response";
12
13
  import { logger } from "../../logger";
13
14
  import { entityRowKey, trySemanticSearch } from "./embedding_index";
14
15
 
@@ -261,46 +262,45 @@ async function getPackageIndex(
261
262
 
262
263
  const GET_CONTEXT_DESCRIPTION = `Discover what a Publisher deployment exposes and retrieve the model entities most relevant to a plain-English question, so you can ground a query in what the model actually defines instead of guessing. This is the starting point when you do not yet know the environment, package, or model names.
263
264
 
264
- ## Progressive discovery
265
- Call it with as much as you know and omit the rest; it answers at the appropriate level:
266
- - No arguments: lists the available environments, each with its package names.
267
- - environmentName only: lists the packages in that environment, with descriptions.
268
- - environmentName + packageName: lists that package's sources.
269
- - environmentName + packageName + query: returns the sources, views, named queries, and dimension/measure fields most relevant to the question.
265
+ ## Contract rules
266
+ - Use the names it returns verbatim; never invent an environment, package, or entity that is not in the results.
267
+ - Start broad and narrow down: environments, then packages, then sources, then a query.
270
268
 
271
269
  ## Parameters
272
- - environmentName (optional): omit to list environments.
273
- - packageName (optional): omit, with environmentName set, to list packages.
274
- - query (optional): a plain-English description of what you need; omit, with environmentName and packageName set, to list the package's sources.
275
- - sourceName (optional): narrow retrieval to entities within one source (the drill-down phase).
276
- - limit (optional): cap the number of results (max 50). Retrieval defaults to 10; the listing tiers return all unless set.
270
+ All optional. Supply what you know and omit the rest; each combination answers at its own level.
271
+ - none: lists the environments, each with its package names.
272
+ - environmentName: lists that environment's packages, with descriptions.
273
+ - + packageName: lists that package's sources.
274
+ - + query: a plain-English description of what you need, returning the sources, views, named queries, and dimension/measure fields most relevant to it.
275
+ - sourceName: narrows retrieval to one source (the drill-down phase).
276
+ - limit: caps results (max 50). Retrieval defaults to 10; the listing levels return all unless set.
277
277
 
278
278
  ## Response
279
279
  A JSON object with a results array whose items carry a kind field. For retrieval, each entity has kind (source / view / query / dimension / measure), name, source, modelPath, and doc; environmentName, packageName, modelPath, and source map directly onto malloy_executeQuery parameters, and for a view or named query you pass its name as queryName with sourceName. When the server is configured with an embedding provider, retrieval is ranked by semantic similarity: the payload then carries a retrieval field ("semantic", or "lexical" when the provider is unavailable) and each semantic entity a score.
280
280
 
281
- ## Contract rules
282
- - Use the names verbatim; do not invent environments, packages, or entities not in the results.
283
- - Start broad and narrow down: list environments, then packages, then sources, then query.
284
-
285
281
  ## Worked example
286
282
  { "environmentName": "examples", "packageName": "storefront", "query": "revenue by product category" }`;
287
283
 
288
284
  /**
289
- * Wrap a JSON payload in the MCP resource-content shape every tier of this tool
290
- * returns. isError marks a tool-level error (e.g. an unknown environment/package).
285
+ * Every tier of this tool answers with `results`, so an error keeps that key
286
+ * (empty) alongside `error`. Callers can read `results` unconditionally without
287
+ * branching on success first.
288
+ *
289
+ * Routed through classifyToolError for the same reason its three sibling tools
290
+ * are: it homes each error class to real remediation, so an unknown package
291
+ * says so instead of arriving as a bare message with no suggestions. It also
292
+ * replaces a per-site `error instanceof Error ? error.message : "Unknown
293
+ * error"`, which was the one path in this file that could produce exactly the
294
+ * unhelpful string this tool's callers reported.
291
295
  */
292
- function jsonResource(uri: string, payload: unknown, isError = false) {
293
- const content = [
296
+ function contextError(uri: string, identifier: string, error: unknown) {
297
+ return jsonToolError(
298
+ uri,
299
+ classifyToolError("getContext", identifier, error),
294
300
  {
295
- type: "resource" as const,
296
- resource: {
297
- type: "application/json",
298
- uri,
299
- text: JSON.stringify(payload),
300
- },
301
+ results: [],
301
302
  },
302
- ];
303
- return isError ? { isError: true, content } : { content };
303
+ );
304
304
  }
305
305
 
306
306
  /**
@@ -348,16 +348,17 @@ export function registerGetContextTool(
348
348
  results,
349
349
  });
350
350
  } catch (error) {
351
- const message =
352
- error instanceof Error ? error.message : "Unknown error";
353
351
  logger.warn(
354
352
  "[MCP Tool getContext] listing environments failed",
355
- { error: message },
353
+ {
354
+ error:
355
+ error instanceof Error ? error.message : String(error),
356
+ },
356
357
  );
357
- return jsonResource(
358
+ return contextError(
358
359
  buildMalloyUri({}, "get-context"),
359
- { error: message, results: [] },
360
- true,
360
+ "environments",
361
+ error,
361
362
  );
362
363
  }
363
364
  }
@@ -384,19 +385,17 @@ export function registerGetContextTool(
384
385
  { results },
385
386
  );
386
387
  } catch (error) {
387
- const message =
388
- error instanceof Error ? error.message : "Unknown error";
389
388
  logger.warn("[MCP Tool getContext] listing packages failed", {
390
389
  environmentName,
391
- error: message,
390
+ error: error instanceof Error ? error.message : String(error),
392
391
  });
393
- return jsonResource(
392
+ return contextError(
394
393
  buildMalloyUri(
395
394
  { environment: environmentName },
396
395
  "get-context",
397
396
  ),
398
- { error: message, results: [] },
399
- true,
397
+ environmentName,
398
+ error,
400
399
  );
401
400
  }
402
401
  }
@@ -410,21 +409,19 @@ export function registerGetContextTool(
410
409
  packageName,
411
410
  );
412
411
  } catch (error) {
413
- const message =
414
- error instanceof Error ? error.message : "Unknown error";
415
412
  logger.warn("[MCP Tool getContext] index build failed", {
416
413
  environmentName,
417
414
  packageName,
418
415
  sourceName,
419
- error: message,
416
+ error: error instanceof Error ? error.message : String(error),
420
417
  });
421
- return jsonResource(
418
+ return contextError(
422
419
  buildMalloyUri(
423
420
  { environment: environmentName, package: packageName },
424
421
  "get-context",
425
422
  ),
426
- { error: message, results: [] },
427
- true,
423
+ `${environmentName}/${packageName}`,
424
+ error,
428
425
  );
429
426
  }
430
427
 
@@ -5,6 +5,7 @@ import { EnvironmentStore } from "../../service/environment_store";
5
5
  import { PackageController } from "../../controller/package.controller";
6
6
  import { type ErrorDetails } from "../error_messages";
7
7
  import { buildMalloyUri, classifyToolError } from "../handler_utils";
8
+ import { jsonResource, jsonToolError } from "../tool_response";
8
9
 
9
10
  // Zod shape for malloy_reloadPackage. environmentName/packageName mirror the
10
11
  // other tools and point the agent at malloy_getContext for name discovery.
@@ -109,19 +110,7 @@ export function registerReloadPackageTool(
109
110
  }),
110
111
  };
111
112
 
112
- return {
113
- isError: false,
114
- content: [
115
- {
116
- type: "resource" as const,
117
- resource: {
118
- type: "application/json",
119
- uri,
120
- text: JSON.stringify(payload),
121
- },
122
- },
123
- ],
124
- };
113
+ return jsonResource(uri, payload);
125
114
  } catch (error) {
126
115
  // Unknown environment/package, or a compile error in the reloaded
127
116
  // package: surface as a clean isError payload rather than a
@@ -136,22 +125,7 @@ export function registerReloadPackageTool(
136
125
  `${environmentName}/${packageName}`,
137
126
  error,
138
127
  );
139
- return {
140
- isError: true,
141
- content: [
142
- {
143
- type: "resource" as const,
144
- resource: {
145
- type: "application/json",
146
- uri,
147
- text: JSON.stringify({
148
- error: errorDetails.message,
149
- suggestions: errorDetails.suggestions,
150
- }),
151
- },
152
- },
153
- ],
154
- };
128
+ return jsonToolError(uri, errorDetails);
155
129
  }
156
130
  },
157
131
  );