@malloy-publisher/server 0.0.197 → 0.0.198-dev1

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 (54) hide show
  1. package/README.docker.md +47 -0
  2. package/build.ts +26 -1
  3. package/dist/app/api-doc.yaml +54 -20
  4. package/dist/app/assets/{EnvironmentPage-BVkQH_xQ.js → EnvironmentPage-Dpee_Kn6.js} +1 -1
  5. package/dist/app/assets/{HomePage-BgH9UkjK.js → HomePage-DLRWTNoL.js} +1 -1
  6. package/dist/app/assets/{MainPage-DiBxABem.js → MainPage-DsVt5QGM.js} +1 -1
  7. package/dist/app/assets/{ModelPage-oS70fj83.js → ModelPage-AwAugZ37.js} +1 -1
  8. package/dist/app/assets/{PackagePage-F_qLDAdv.js → PackagePage-XQ-EWGTC.js} +1 -1
  9. package/dist/app/assets/{RouteError-WqpffppN.js → RouteError-3Mv8JQw7.js} +1 -1
  10. package/dist/app/assets/{WorkbookPage-_YmC-ebR.js → WorkbookPage-DHYYpcYc.js} +1 -1
  11. package/dist/app/assets/{core-B8L9xCYT.es-BcRLJTnC.js → core-DfcpQGVP.es-DQggNOdX.js} +1 -1
  12. package/dist/app/assets/{index-C3XPaTaS.js → index-BUp81Qdm.js} +1 -1
  13. package/dist/app/assets/{index-rg8Ok8nl.js → index-D1pdwrUW.js} +1 -1
  14. package/dist/app/assets/{index-BMViiwtJ.js → index-Dv5bF4Ii.js} +4 -4
  15. package/dist/app/assets/{index.umd-CCAfKkxY.js → index.umd-CQH4LZU8.js} +1 -1
  16. package/dist/app/index.html +1 -1
  17. package/dist/compile_worker.mjs +628 -0
  18. package/dist/instrumentation.mjs +36 -36
  19. package/dist/server.mjs +1781 -809
  20. package/package.json +1 -1
  21. package/src/compile/compile_pool.spec.ts +227 -0
  22. package/src/compile/compile_pool.ts +729 -0
  23. package/src/compile/compile_worker.ts +683 -0
  24. package/src/compile/protocol.ts +251 -0
  25. package/src/config.spec.ts +81 -0
  26. package/src/config.ts +126 -0
  27. package/src/controller/compile.controller.ts +3 -1
  28. package/src/controller/model.controller.ts +8 -1
  29. package/src/controller/package.controller.ts +70 -29
  30. package/src/controller/query.controller.ts +3 -0
  31. package/src/errors.ts +13 -0
  32. package/src/health.spec.ts +90 -0
  33. package/src/health.ts +86 -71
  34. package/src/mcp/tools/discovery_tools.ts +6 -2
  35. package/src/mcp/tools/execute_query_tool.ts +12 -0
  36. package/src/path_safety.spec.ts +158 -0
  37. package/src/path_safety.ts +140 -0
  38. package/src/server.ts +29 -0
  39. package/src/service/environment.ts +616 -199
  40. package/src/service/environment_admission.spec.ts +180 -0
  41. package/src/service/environment_store.spec.ts +0 -19
  42. package/src/service/environment_store.ts +24 -21
  43. package/src/service/filter_integration.spec.ts +110 -0
  44. package/src/service/givens_integration.spec.ts +192 -0
  45. package/src/service/manifest_service.spec.ts +7 -2
  46. package/src/service/manifest_service.ts +8 -2
  47. package/src/service/materialization_service.ts +14 -3
  48. package/src/service/model.spec.ts +105 -0
  49. package/src/service/model.ts +317 -10
  50. package/src/service/model_worker_path.spec.ts +125 -0
  51. package/src/service/package_memory_governor.spec.ts +173 -0
  52. package/src/service/package_memory_governor.ts +233 -0
  53. package/src/service/package_race.spec.ts +208 -0
  54. package/tests/integration/concurrent_package/concurrent_package.integration.spec.ts +280 -0
@@ -1,6 +1,4 @@
1
- import * as path from "path";
2
1
  import { components } from "../api";
3
- import { PUBLISHER_DATA_DIR } from "../constants";
4
2
  import { BadRequestError, FrozenConfigError } from "../errors";
5
3
  import { logger } from "../logger";
6
4
  import { EnvironmentStore } from "../service/environment_store";
@@ -37,15 +35,38 @@ export class PackageController {
37
35
  environmentName,
38
36
  false,
39
37
  );
40
- const _package = await environment.getPackage(packageName, reload);
41
- const packageLocation = _package.getPackageMetadata().location;
42
- if (reload && packageLocation) {
43
- await this.downloadPackage(
44
- environmentName,
45
- packageName,
46
- packageLocation,
47
- );
38
+
39
+ if (reload) {
40
+ // Resolve the package's source location from the currently-cached
41
+ // metadata WITHOUT triggering a stale-state reload. If a `location`
42
+ // is set, route the reload through `installPackage` so that
43
+ // download-then-load happens atomically; otherwise fall back to an
44
+ // in-place reload of the existing on-disk content.
45
+ let location: string | undefined;
46
+ try {
47
+ const cached = await environment.getPackage(packageName, false);
48
+ location = cached.getPackageMetadata().location;
49
+ } catch {
50
+ // Not previously loaded — nothing to reinstall from.
51
+ }
52
+ if (location) {
53
+ const reinstalled = await environment.installPackage(
54
+ packageName,
55
+ (stagingPath) =>
56
+ this.downloadInto(
57
+ environmentName,
58
+ packageName,
59
+ location,
60
+ stagingPath,
61
+ ),
62
+ );
63
+ return reinstalled.getPackageMetadata();
64
+ }
65
+ const _package = await environment.getPackage(packageName, true);
66
+ return _package.getPackageMetadata();
48
67
  }
68
+
69
+ const _package = await environment.getPackage(packageName, false);
49
70
  return _package.getPackageMetadata();
50
71
  }
51
72
 
@@ -60,21 +81,32 @@ export class PackageController {
60
81
  if (!body.name) {
61
82
  throw new BadRequestError("Package name is required");
62
83
  }
84
+ const packageName = body.name;
63
85
  const environment = await this.environmentStore.getEnvironment(
64
86
  environmentName,
65
87
  false,
66
88
  );
89
+ let result;
67
90
  if (body.location) {
68
- await this.downloadPackage(environmentName, body.name, body.location);
91
+ const bodyLocation = body.location;
92
+ result = await environment.installPackage(packageName, (stagingPath) =>
93
+ this.downloadInto(
94
+ environmentName,
95
+ packageName,
96
+ bodyLocation,
97
+ stagingPath,
98
+ ),
99
+ );
100
+ } else {
101
+ result = await environment.addPackage(packageName);
69
102
  }
70
- const result = await environment.addPackage(body.name);
71
103
  await this.environmentStore.addPackageToDatabase(
72
104
  environmentName,
73
- body.name,
105
+ packageName,
74
106
  );
75
107
 
76
108
  if (options?.autoLoadManifest === true) {
77
- await this.tryLoadExistingManifest(environmentName, body.name);
109
+ await this.tryLoadExistingManifest(environmentName, packageName);
78
110
  }
79
111
 
80
112
  return result;
@@ -151,12 +183,20 @@ export class PackageController {
151
183
  false,
152
184
  );
153
185
  if (body.location) {
154
- await this.downloadPackage(
155
- environmentName,
156
- packageName,
157
- body.location,
186
+ // Re-install: stream the new content into a staging dir (no lock)
187
+ // and atomically swap it in (under the lock).
188
+ const bodyLocation = body.location;
189
+ await environment.installPackage(packageName, (stagingPath) =>
190
+ this.downloadInto(
191
+ environmentName,
192
+ packageName,
193
+ bodyLocation,
194
+ stagingPath,
195
+ ),
158
196
  );
159
197
  }
198
+ // Apply metadata changes (publisher.json) under the same per-package
199
+ // mutex via `Environment.updatePackage`.
160
200
  const result = await environment.updatePackage(packageName, body);
161
201
  await this.environmentStore.addPackageToDatabase(
162
202
  environmentName,
@@ -166,17 +206,18 @@ export class PackageController {
166
206
  return result;
167
207
  }
168
208
 
169
- private async downloadPackage(
209
+ /**
210
+ * Run the right downloader for the given location into `targetPath`.
211
+ * This used to point at the canonical package directory, but the
212
+ * install pipeline now passes a sibling staging dir so the long-running
213
+ * download doesn't hold the per-package mutex.
214
+ */
215
+ private async downloadInto(
170
216
  environmentName: string,
171
217
  packageName: string,
172
218
  packageLocation: string,
219
+ targetPath: string,
173
220
  ) {
174
- const absoluteTargetPath = path.join(
175
- this.environmentStore.serverRootPath,
176
- PUBLISHER_DATA_DIR,
177
- environmentName,
178
- packageName,
179
- );
180
221
  const isCompressedFile = packageLocation.endsWith(".zip");
181
222
  if (
182
223
  packageLocation.startsWith("https://") ||
@@ -184,20 +225,20 @@ export class PackageController {
184
225
  ) {
185
226
  await this.environmentStore.downloadGitHubDirectory(
186
227
  packageLocation,
187
- absoluteTargetPath,
228
+ targetPath,
188
229
  );
189
230
  } else if (packageLocation.startsWith("gs://")) {
190
231
  await this.environmentStore.downloadGcsDirectory(
191
232
  packageLocation,
192
233
  environmentName,
193
- absoluteTargetPath,
234
+ targetPath,
194
235
  isCompressedFile,
195
236
  );
196
237
  } else if (packageLocation.startsWith("s3://")) {
197
238
  await this.environmentStore.downloadS3Directory(
198
239
  packageLocation,
199
240
  environmentName,
200
- absoluteTargetPath,
241
+ targetPath,
201
242
  isCompressedFile,
202
243
  );
203
244
  }
@@ -207,7 +248,7 @@ export class PackageController {
207
248
  // so we need to mount them on the right place.
208
249
  await this.environmentStore.mountLocalDirectory(
209
250
  packageLocation,
210
- absoluteTargetPath,
251
+ targetPath,
211
252
  environmentName,
212
253
  packageName,
213
254
  );
@@ -4,6 +4,7 @@ import { API_PREFIX } from "../constants";
4
4
  import { ModelNotFoundError } from "../errors";
5
5
  import { EnvironmentStore } from "../service/environment_store";
6
6
  import type { FilterParams } from "../service/filter";
7
+ import type { GivenValue } from "@malloydata/malloy";
7
8
 
8
9
  type ApiQuery = components["schemas"]["QueryResult"];
9
10
 
@@ -32,6 +33,7 @@ export class QueryController {
32
33
  compactJson: boolean = false,
33
34
  filterParams?: FilterParams,
34
35
  bypassFilters?: boolean,
36
+ givens?: Record<string, GivenValue>,
35
37
  ): Promise<ApiQuery> {
36
38
  const environment = await this.environmentStore.getEnvironment(
37
39
  environmentName,
@@ -49,6 +51,7 @@ export class QueryController {
49
51
  query,
50
52
  filterParams,
51
53
  bypassFilters,
54
+ givens,
52
55
  );
53
56
  const renderLogs = validateRenderTags(result);
54
57
  return {
package/src/errors.ts CHANGED
@@ -28,6 +28,8 @@ export function internalErrorToHttpError(error: Error) {
28
28
  return httpError(409, error.message);
29
29
  } else if (error instanceof InvalidStateTransitionError) {
30
30
  return httpError(409, error.message);
31
+ } else if (error instanceof ServiceUnavailableError) {
32
+ return httpError(503, error.message);
31
33
  } else {
32
34
  return httpError(500, error.message);
33
35
  }
@@ -122,3 +124,14 @@ export class InvalidStateTransitionError extends Error {
122
124
  super(message);
123
125
  }
124
126
  }
127
+
128
+ /**
129
+ * Thrown when the publisher is temporarily refusing a request to keep
130
+ * RSS under the configured `PUBLISHER_MAX_MEMORY_BYTES` cap. Mapped to
131
+ * HTTP 503 so an upstream proxy / client can retry with back-off.
132
+ */
133
+ export class ServiceUnavailableError extends Error {
134
+ constructor(message: string) {
135
+ super(message);
136
+ }
137
+ }
@@ -0,0 +1,90 @@
1
+ import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
2
+ import { Server } from "http";
3
+ import { performGracefulShutdownAfterDrain } from "./health";
4
+ import { logger } from "./logger";
5
+
6
+ // Regression test for the graceful-shutdown ordering bug that caused
7
+ // [winston] Attempt to write logs with no transports: {"message":"Waiting 50 seconds..."}
8
+ // to appear in production logs. logger.close() must run after every
9
+ // logger.* call, including the "Waiting ... seconds after server close
10
+ // before exit..." message.
11
+ //
12
+ // Tests call performGracefulShutdownAfterDrain directly rather than
13
+ // emitting SIGTERM, so module-level operationalState is not mutated
14
+ // and the spec stays isolated from sibling tests in the same process.
15
+ describe("performGracefulShutdownAfterDrain: shutdown ordering", () => {
16
+ const originalExit = process.exit;
17
+ let callOrder: string[];
18
+
19
+ beforeEach(() => {
20
+ callOrder = [];
21
+
22
+ spyOn(logger, "info").mockImplementation(((msg: string) => {
23
+ callOrder.push(`info:${msg}`);
24
+ return logger;
25
+ }) as never);
26
+ spyOn(logger, "close").mockImplementation((() => {
27
+ callOrder.push("close");
28
+ return logger;
29
+ }) as never);
30
+ // Silence warn/error calls so spec output stays clean. They are
31
+ // not load-bearing for these assertions.
32
+ spyOn(logger, "warn").mockImplementation((() => logger) as never);
33
+ spyOn(logger, "error").mockImplementation((() => logger) as never);
34
+
35
+ process.exit = ((_code?: number) => {
36
+ callOrder.push("exit");
37
+ }) as never;
38
+ });
39
+
40
+ afterEach(() => {
41
+ process.exit = originalExit;
42
+ });
43
+
44
+ const fakeServer = (): Server => ({ listening: false }) as unknown as Server;
45
+
46
+ it("logs the 'Waiting ...' message before closing the logger", async () => {
47
+ await performGracefulShutdownAfterDrain(fakeServer(), fakeServer(), 0.05);
48
+
49
+ const waitingIdx = callOrder.findIndex((entry) =>
50
+ entry.startsWith("info:Waiting"),
51
+ );
52
+ const closeIdx = callOrder.indexOf("close");
53
+ const exitIdx = callOrder.indexOf("exit");
54
+
55
+ expect(waitingIdx).toBeGreaterThanOrEqual(0);
56
+ expect(closeIdx).toBeGreaterThanOrEqual(0);
57
+ expect(exitIdx).toBeGreaterThanOrEqual(0);
58
+ expect(waitingIdx).toBeLessThan(closeIdx);
59
+ expect(closeIdx).toBeLessThan(exitIdx);
60
+ });
61
+
62
+ it("emits no logger.info calls after logger.close", async () => {
63
+ await performGracefulShutdownAfterDrain(fakeServer(), fakeServer(), 0.05);
64
+
65
+ const closeIdx = callOrder.indexOf("close");
66
+ const lateInfoIdx = callOrder.findIndex(
67
+ (entry, idx) => idx > closeIdx && entry.startsWith("info:"),
68
+ );
69
+ expect(closeIdx).toBeGreaterThanOrEqual(0);
70
+ expect(lateInfoIdx).toBe(-1);
71
+ });
72
+
73
+ it("closes the logger exactly once", async () => {
74
+ await performGracefulShutdownAfterDrain(fakeServer(), fakeServer(), 0.05);
75
+
76
+ const closes = callOrder.filter((entry) => entry === "close").length;
77
+ expect(closes).toBe(1);
78
+ });
79
+
80
+ it("skips the 'Waiting ...' message when gracefulCloseTimeoutSeconds is 0", async () => {
81
+ await performGracefulShutdownAfterDrain(fakeServer(), fakeServer(), 0);
82
+
83
+ const waitingCalls = callOrder.filter((entry) =>
84
+ entry.startsWith("info:Waiting"),
85
+ );
86
+ expect(waitingCalls.length).toBe(0);
87
+ expect(callOrder.indexOf("close")).toBeGreaterThanOrEqual(0);
88
+ expect(callOrder.indexOf("exit")).toBeGreaterThanOrEqual(0);
89
+ });
90
+ });
package/src/health.ts CHANGED
@@ -41,32 +41,6 @@ export function markReady(): void {
41
41
  }
42
42
  }
43
43
 
44
- /**
45
- * Marks the service as degraded: one or more environments failed to
46
- * initialize. The surviving environments are still queryable, and
47
- * callers polling /api/v0/status see operationalState="degraded" plus
48
- * a failedEnvironments list.
49
- *
50
- * Readiness probe (/health/readiness) returns 503 — degraded pods are
51
- * pulled out of K8s load-balancer rotation so traffic does not get
52
- * routed to a replica that can only serve a fraction of the configured
53
- * environments. Operators should fix the failing config and restart
54
- * the pod; if you want degraded traffic to be served anyway (e.g. for
55
- * a single-replica local dev instance), poll /api/v0/status directly
56
- * instead of /health/readiness.
57
- */
58
- export function markDegraded(): void {
59
- if (operationalState !== "draining") {
60
- operationalState = "degraded";
61
- ready = false;
62
- logger.warn(
63
- "Service marked as degraded; one or more environments failed to initialize. Readiness probe will fail until the config is fixed and the process restarts.",
64
- );
65
- } else {
66
- logger.error("Service is already draining - cannot mark as degraded");
67
- }
68
- }
69
-
70
44
  /**
71
45
  * Marks the service as not ready (readiness probe will return 503).
72
46
  */
@@ -83,8 +57,8 @@ export function markNotReady(): void {
83
57
  * 2. Waits shutdownDrainDurationSeconds to allow in-flight requests to complete
84
58
  * 3. Sets preGracefulShutdownCompleted flag (enables drainingGuard middleware to reject new requests)
85
59
  * 4. Closes main server and MCP server (stops accepting new connections)
86
- * 5. Closes logger
87
- * 6. Waits shutdownGracefulCloseTimeoutSeconds (if > 0) for final cleanup
60
+ * 5. Waits shutdownGracefulCloseTimeoutSeconds (if > 0) for final cleanup
61
+ * 6. Closes logger (last, so any logs emitted during cleanup are flushed)
88
62
  * 7. Exits process
89
63
  *
90
64
  * Note: drainingGuard only rejects requests after step 3 completes. During step 2,
@@ -118,51 +92,92 @@ export function registerSignalHandlers(
118
92
  }, shutdownDrainDurationSeconds * 1000),
119
93
  );
120
94
 
121
- const closeServer = (server: Server, name: string) =>
122
- new Promise<void>((resolve) => {
123
- if (server && server.listening) {
124
- server.close((err) => {
125
- if (err) {
126
- logger.error(`${name} close error:`, err);
127
- } else {
128
- logger.info(`${name} closed`);
129
- }
130
- resolve();
131
- });
132
- } else {
133
- resolve();
134
- }
135
- });
136
-
137
- await Promise.all([
138
- closeServer(server, "Main server"),
139
- closeServer(mcpServer, "MCP server"),
140
- ]);
141
-
142
- try {
143
- await shutdownSDK();
144
- logger.info("OpenTelemetry SDK shut down");
145
- } catch (_error) {
146
- /* do nothing */
147
- }
148
-
149
- try {
150
- logger.close();
151
- } catch (_error) {
152
- /* do nothing */
153
- }
154
-
155
- if (shutdownGracefulCloseTimeoutSeconds > 0) {
156
- logger.info(
157
- `Waiting ${shutdownGracefulCloseTimeoutSeconds} seconds after server close before exit...`,
158
- );
159
- await new Promise((resolve) =>
160
- setTimeout(resolve, shutdownGracefulCloseTimeoutSeconds * 1000),
161
- );
162
- }
163
- process.exit(0);
95
+ await performGracefulShutdownAfterDrain(
96
+ server,
97
+ mcpServer,
98
+ shutdownGracefulCloseTimeoutSeconds,
99
+ );
164
100
  });
165
101
  }
102
+
103
+ /**
104
+ * Performs the post-drain shutdown work: closes both HTTP servers,
105
+ * shuts down the OpenTelemetry SDK, waits the optional graceful-close
106
+ * window so any in-flight cleanup can finish logging, closes the
107
+ * winston logger, and exits the process.
108
+ *
109
+ * Exported so unit tests can exercise the close + log + exit ordering
110
+ * without emitting SIGTERM (which would leave module-level
111
+ * operationalState stuck in "draining" and leak into sibling specs).
112
+ */
113
+ export async function performGracefulShutdownAfterDrain(
114
+ server: Server,
115
+ mcpServer: Server,
116
+ shutdownGracefulCloseTimeoutSeconds: number,
117
+ ): Promise<void> {
118
+ const closeServer = (server: Server, name: string) =>
119
+ new Promise<void>((resolve) => {
120
+ if (server && server.listening) {
121
+ server.close((err) => {
122
+ if (err) {
123
+ logger.error(`${name} close error:`, err);
124
+ } else {
125
+ logger.info(`${name} closed`);
126
+ }
127
+ resolve();
128
+ });
129
+ } else {
130
+ resolve();
131
+ }
132
+ });
133
+
134
+ await Promise.all([
135
+ closeServer(server, "Main server"),
136
+ closeServer(mcpServer, "MCP server"),
137
+ ]);
138
+
139
+ try {
140
+ await shutdownSDK();
141
+ logger.info("OpenTelemetry SDK shut down");
142
+ } catch (_error) {
143
+ /* do nothing */
144
+ }
145
+
146
+ try {
147
+ // Drain in-flight compiles and terminate worker_threads before
148
+ // we exit so a slow compile doesn't leave orphan worker
149
+ // processes. Lazy-imported to avoid pulling the pool module
150
+ // into the health.ts dep graph for tests that don't exercise
151
+ // the compile path.
152
+ const { getCompilePool } = await import("./compile/compile_pool");
153
+ await getCompilePool().shutdown();
154
+ logger.info("Malloy compile worker pool shut down");
155
+ } catch (_error) {
156
+ /* do nothing */
157
+ }
158
+
159
+ if (shutdownGracefulCloseTimeoutSeconds > 0) {
160
+ logger.info(
161
+ `Waiting ${shutdownGracefulCloseTimeoutSeconds} seconds after server close before exit...`,
162
+ );
163
+ await new Promise((resolve) =>
164
+ setTimeout(resolve, shutdownGracefulCloseTimeoutSeconds * 1000),
165
+ );
166
+ }
167
+
168
+ // Close the logger last so anything emitted during the wait window
169
+ // above (or by other shutdown paths still running) reaches its
170
+ // transports. Closing earlier triggers winston's
171
+ // "Attempt to write logs with no transports" warning on any
172
+ // subsequent logger call.
173
+ try {
174
+ logger.close();
175
+ } catch (_error) {
176
+ /* do nothing */
177
+ }
178
+
179
+ process.exit(0);
180
+ }
166
181
  /**
167
182
  * Middleware that returns 503 for non-health and metrics requests when service is draining.
168
183
  * Must be registered before application routes.
@@ -222,8 +222,12 @@ export function registerTools(
222
222
  throw new Error(`Model not found: ${modelPath}`);
223
223
  }
224
224
 
225
- // Use the new getModelFileText method
226
- const fileText = await pkg.getModelFileText(modelPath);
225
+ // Route through the Environment so the disk read is serialized
226
+ // against installPackage / deletePackage.
227
+ const fileText = await environment.getModelFileText(
228
+ packageName,
229
+ modelPath,
230
+ );
227
231
 
228
232
  console.log(
229
233
  `[MCP LOG] Successfully retrieved model text for ${modelPath}`,
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { z } from "zod";
4
+ import type { GivenValue } from "@malloydata/malloy";
4
5
  import { logger } from "../../logger";
5
6
  import { EnvironmentStore } from "../../service/environment_store";
6
7
  import { getMalloyErrorDetails, type ErrorDetails } from "../error_messages";
@@ -30,6 +31,12 @@ const executeQueryShape = {
30
31
  .describe(
31
32
  "Filter parameter values keyed by filter name. Used with sources that declare #(filter) annotations.",
32
33
  ),
34
+ givens: z
35
+ .record(z.unknown())
36
+ .optional()
37
+ .describe(
38
+ "Per-query given values that override model defaults. Keys are given names declared in the model's given: block.",
39
+ ),
33
40
  };
34
41
 
35
42
  // Type inference is handled automatically by the MCP server based on the executeQueryShape
@@ -56,6 +63,7 @@ export function registerExecuteQueryTool(
56
63
  sourceName,
57
64
  queryName,
58
65
  filterParams,
66
+ givens,
59
67
  } = params;
60
68
 
61
69
  logger.info("[MCP Tool executeQuery] Received params:", { params });
@@ -128,6 +136,8 @@ export function registerExecuteQueryTool(
128
136
  undefined,
129
137
  query,
130
138
  filterParams,
139
+ undefined,
140
+ givens as Record<string, GivenValue> | undefined,
131
141
  );
132
142
  const { validateRenderTags } = await import(
133
143
  "@malloydata/render-validator"
@@ -174,6 +184,8 @@ export function registerExecuteQueryTool(
174
184
  queryName,
175
185
  undefined,
176
186
  filterParams,
187
+ undefined,
188
+ givens as Record<string, GivenValue> | undefined,
177
189
  );
178
190
  const { validateRenderTags } = await import(
179
191
  "@malloydata/render-validator"