@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.
- package/README.docker.md +1 -0
- package/dist/app/api-doc.yaml +269 -10
- package/dist/app/assets/{EnvironmentPage-DXEaZIPx.js → EnvironmentPage-DTZQ4Gxc.js} +1 -1
- package/dist/app/assets/{HomePage-kofsqpZt.js → HomePage-C5mlDPXK.js} +1 -1
- package/dist/app/assets/{LightMode-CNhIlIlJ.js → LightMode-DGNmhG0u.js} +1 -1
- package/dist/app/assets/{MainPage-Bgqo8jCy.js → MainPage-CVL_wmP4.js} +1 -1
- package/dist/app/assets/{MaterializationsPage-CgBlgGz2.js → MaterializationsPage-DmzMBCpy.js} +1 -1
- package/dist/app/assets/{ModelPage-B0TjoDtf.js → ModelPage-Dbvf4QbB.js} +1 -1
- package/dist/app/assets/{PackagePage-BL8vnFj1.js → PackagePage-DxdHc2Qs.js} +1 -1
- package/dist/app/assets/{RouteError-BzPby0X2.js → RouteError-OJdT4tCd.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-CTEP_9r3.js → ThemeEditorPage-Bk7s0KXY.js} +1 -1
- package/dist/app/assets/{WorkbookPage-BwM3BmKw.js → WorkbookPage-j_vCWdN3.js} +1 -1
- package/dist/app/assets/{core-CK68iv6w.es-CpRxXBt7.js → core-Rj_4rRnA.es-DoIfLxDJ.js} +1 -1
- package/dist/app/assets/{index-B33zGctF.js → index-B_jKMR35.js} +4 -4
- package/dist/app/assets/{index-CmkW1MiE.js → index-D-rDyK11.js} +1 -1
- package/dist/app/assets/{index-tXJXwdyj.js → index-DWIe_hK0.js} +1 -1
- package/dist/app/assets/{index-BkiWKaAF.js → index-hw-xn0X7.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +53 -3
- package/dist/server.mjs +20277 -925
- package/package.json +1 -1
- package/src/config.ts +35 -1
- package/src/controller/connection.controller.spec.ts +46 -0
- package/src/controller/connection.controller.ts +105 -2
- package/src/controller/materialization.controller.spec.ts +25 -0
- package/src/controller/materialization.controller.ts +60 -0
- package/src/controller/model.controller.ts +24 -0
- package/src/controller/query.controller.ts +83 -10
- package/src/json_utils.spec.ts +51 -0
- package/src/json_utils.ts +33 -0
- package/src/mcp/handler_utils.ts +10 -2
- package/src/mcp/query_envelope.spec.ts +229 -0
- package/src/mcp/query_envelope.ts +240 -0
- package/src/mcp/server.protocol.spec.ts +128 -16
- package/src/mcp/skills/build_skills_bundle.ts +94 -4
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/mcp/skills/skills_bundle.spec.ts +113 -4
- package/src/mcp/tool_response.spec.ts +108 -0
- package/src/mcp/tool_response.ts +138 -0
- package/src/mcp/tools/compile_tool.spec.ts +112 -4
- package/src/mcp/tools/compile_tool.ts +61 -30
- package/src/mcp/tools/docs_search_tool.ts +6 -16
- package/src/mcp/tools/execute_query_tool.spec.ts +154 -3
- package/src/mcp/tools/execute_query_tool.ts +131 -155
- package/src/mcp/tools/get_context_tool.spec.ts +63 -3
- package/src/mcp/tools/get_context_tool.ts +43 -46
- package/src/mcp/tools/reload_package_tool.ts +3 -29
- package/src/mcp_config.spec.ts +919 -0
- package/src/mcp_config.ts +425 -0
- package/src/oom_guards.integration.spec.ts +11 -3
- package/src/package_load/package_load_pool.ts +2 -0
- package/src/package_load/package_load_worker.ts +17 -5
- package/src/package_load/protocol.ts +6 -0
- package/src/query_metadata_metrics.ts +49 -0
- package/src/server.ts +99 -3
- package/src/service/build_plan.spec.ts +125 -0
- package/src/service/build_plan.ts +108 -7
- package/src/service/compile_fragment_techniques.spec.ts +156 -0
- package/src/service/connection.spec.ts +371 -1
- package/src/service/connection.ts +77 -14
- package/src/service/connection_config.spec.ts +60 -0
- package/src/service/connection_config.ts +75 -0
- package/src/service/duckdb_instance_isolation.spec.ts +137 -0
- package/src/service/environment.ts +57 -3
- package/src/service/materialization_config_validation.spec.ts +99 -0
- package/src/service/materialization_config_validation.ts +120 -0
- package/src/service/materialization_schedule_surface.spec.ts +124 -0
- package/src/service/materialization_service.spec.ts +119 -0
- package/src/service/materialization_service.ts +186 -3
- package/src/service/materialization_test_fixtures.ts +86 -21
- package/src/service/model.spec.ts +45 -1
- package/src/service/model.ts +171 -23
- package/src/service/model_limits.spec.ts +28 -0
- package/src/service/model_limits.ts +21 -0
- package/src/service/package.ts +24 -1
- package/src/service/package_manifest.spec.ts +137 -4
- package/src/service/package_manifest.ts +140 -5
- package/src/service/persist_annotation_validation.spec.ts +12 -0
- package/src/service/persist_annotation_validation.ts +9 -4
- package/src/service/query_metadata.spec.ts +408 -0
- package/src/service/query_metadata.ts +492 -0
- package/src/service/query_metadata_identity.spec.ts +149 -0
- 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:
|
|
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:
|
|
153
|
-
return JSON.parse(result.content[0].resource
|
|
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
|
-
##
|
|
265
|
-
|
|
266
|
-
-
|
|
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
|
-
|
|
273
|
-
-
|
|
274
|
-
-
|
|
275
|
-
-
|
|
276
|
-
-
|
|
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
|
-
*
|
|
290
|
-
*
|
|
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
|
|
293
|
-
|
|
296
|
+
function contextError(uri: string, identifier: string, error: unknown) {
|
|
297
|
+
return jsonToolError(
|
|
298
|
+
uri,
|
|
299
|
+
classifyToolError("getContext", identifier, error),
|
|
294
300
|
{
|
|
295
|
-
|
|
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
|
-
{
|
|
353
|
+
{
|
|
354
|
+
error:
|
|
355
|
+
error instanceof Error ? error.message : String(error),
|
|
356
|
+
},
|
|
356
357
|
);
|
|
357
|
-
return
|
|
358
|
+
return contextError(
|
|
358
359
|
buildMalloyUri({}, "get-context"),
|
|
359
|
-
|
|
360
|
-
|
|
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
|
|
392
|
+
return contextError(
|
|
394
393
|
buildMalloyUri(
|
|
395
394
|
{ environment: environmentName },
|
|
396
395
|
"get-context",
|
|
397
396
|
),
|
|
398
|
-
|
|
399
|
-
|
|
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
|
|
418
|
+
return contextError(
|
|
422
419
|
buildMalloyUri(
|
|
423
420
|
{ environment: environmentName, package: packageName },
|
|
424
421
|
"get-context",
|
|
425
422
|
),
|
|
426
|
-
{
|
|
427
|
-
|
|
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
|
);
|