@centrali-io/centrali-mcp 9.8.0 → 9.9.0

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.
@@ -291,21 +291,9 @@ ${VARIABLE_DECLARATION_HINT}`, {
291
291
  const input = { name };
292
292
  if (description !== undefined)
293
293
  input.description = description;
294
- if (variables !== undefined) {
295
- // Typed declarations require the canonical create path,
296
- // which expects a full QueryDefinition (including
297
- // 'resource'). `recordSlug` is the URL-level source of
298
- // truth for the target collection — apply it last so a
299
- // caller-supplied `queryDefinition.resource` cannot
300
- // silently retarget the create.
301
- input.query = Object.assign(Object.assign({}, queryDefinition), { resource: recordSlug });
294
+ input.query = Object.assign(Object.assign({}, queryDefinition), { resource: recordSlug });
295
+ if (variables !== undefined)
302
296
  input.variables = variables;
303
- }
304
- else {
305
- // No typed declarations — keep the legacy slug-based path
306
- // for back-compat with pre-Phase-4 callers.
307
- input.queryDefinition = queryDefinition;
308
- }
309
297
  const result = yield sdk.savedQueries.create(recordSlug, input);
310
298
  return {
311
299
  content: [
@@ -353,20 +341,11 @@ ${VARIABLE_DECLARATION_HINT}`, {
353
341
  input.name = name;
354
342
  if (description !== undefined)
355
343
  input.description = description;
356
- if (variables !== undefined) {
357
- // Canonical update: requires `query` (with resource) when
358
- // queryDefinition is also being updated; otherwise just
359
- // ship the variables change. Apply `resource` last so a
360
- // caller-supplied `queryDefinition.resource` cannot trip
361
- // the server's "resource cannot change on update" guard.
362
- if (queryDefinition !== undefined) {
363
- input.query = Object.assign(Object.assign({}, queryDefinition), { resource: recordSlug });
364
- }
365
- input.variables = variables;
366
- }
367
- else if (queryDefinition !== undefined) {
368
- input.queryDefinition = queryDefinition;
344
+ if (queryDefinition !== undefined) {
345
+ input.query = Object.assign(Object.assign({}, queryDefinition), { resource: recordSlug });
369
346
  }
347
+ if (variables !== undefined)
348
+ input.variables = variables;
370
349
  const result = yield sdk.savedQueries.update(recordSlug, queryId, input);
371
350
  return {
372
351
  content: [
@@ -419,7 +398,7 @@ ${CANONICAL_QUERY_DEFINITION_HINT}
419
398
 
420
399
  ${JOINS_HINT}
421
400
 
422
- Typed dry-run is not yet wired on the server: '/saved-queries/test' resolves '\${var}' placeholders via legacy string substitution and does not honor typed 'variableDeclarations'. Use create_saved_query + execute_saved_query (or update_saved_query) to validate typed parameters end-to-end.`, {
401
+ This tool sends untyped runtime values to the canonical '/saved-queries/test' endpoint. Use create_saved_query + execute_saved_query to validate typed parameter declarations end-to-end.`, {
423
402
  recordSlug: zod_1.z.string().describe("The collection's record slug to test against"),
424
403
  queryDefinition: zod_1.z
425
404
  .record(zod_1.z.string(), zod_1.z.any())
@@ -430,7 +409,7 @@ Typed dry-run is not yet wired on the server: '/saved-queries/test' resolves '\$
430
409
  .describe("Optional runtime values bound to '\${var}' placeholders. Substituted via legacy string substitution on the test path (every value is stringified)."),
431
410
  }, (_a) => __awaiter(this, [_a], void 0, function* ({ recordSlug, queryDefinition, variables }) {
432
411
  try {
433
- const input = { queryDefinition };
412
+ const input = { query: Object.assign(Object.assign({}, queryDefinition), { resource: recordSlug }) };
434
413
  if (variables !== undefined)
435
414
  input.variables = variables;
436
415
  const result = yield sdk.savedQueries.test(recordSlug, input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centrali-io/centrali-mcp",
3
- "version": "9.8.0",
3
+ "version": "9.9.0",
4
4
  "description": "Centrali MCP Server - AI assistant integration for Centrali workspaces",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -26,7 +26,7 @@
26
26
  "author": "Blueinit",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
- "@centrali-io/centrali-sdk": "^9.8.0",
29
+ "@centrali-io/centrali-sdk": "^9.9.0",
30
30
  "@modelcontextprotocol/sdk": "^1.28.0"
31
31
  },
32
32
  "devDependencies": {
@@ -314,20 +314,8 @@ ${VARIABLE_DECLARATION_HINT}`,
314
314
  try {
315
315
  const input: Record<string, any> = { name };
316
316
  if (description !== undefined) input.description = description;
317
- if (variables !== undefined) {
318
- // Typed declarations require the canonical create path,
319
- // which expects a full QueryDefinition (including
320
- // 'resource'). `recordSlug` is the URL-level source of
321
- // truth for the target collection — apply it last so a
322
- // caller-supplied `queryDefinition.resource` cannot
323
- // silently retarget the create.
324
- input.query = { ...(queryDefinition as object), resource: recordSlug };
325
- input.variables = variables;
326
- } else {
327
- // No typed declarations — keep the legacy slug-based path
328
- // for back-compat with pre-Phase-4 callers.
329
- input.queryDefinition = queryDefinition;
330
- }
317
+ input.query = { ...(queryDefinition as object), resource: recordSlug };
318
+ if (variables !== undefined) input.variables = variables;
331
319
 
332
320
  const result = await sdk.savedQueries.create(recordSlug, input as any);
333
321
  return {
@@ -382,19 +370,10 @@ ${VARIABLE_DECLARATION_HINT}`,
382
370
  if (name !== undefined) input.name = name;
383
371
  if (description !== undefined) input.description = description;
384
372
 
385
- if (variables !== undefined) {
386
- // Canonical update: requires `query` (with resource) when
387
- // queryDefinition is also being updated; otherwise just
388
- // ship the variables change. Apply `resource` last so a
389
- // caller-supplied `queryDefinition.resource` cannot trip
390
- // the server's "resource cannot change on update" guard.
391
- if (queryDefinition !== undefined) {
392
- input.query = { ...(queryDefinition as object), resource: recordSlug };
393
- }
394
- input.variables = variables;
395
- } else if (queryDefinition !== undefined) {
396
- input.queryDefinition = queryDefinition;
373
+ if (queryDefinition !== undefined) {
374
+ input.query = { ...(queryDefinition as object), resource: recordSlug };
397
375
  }
376
+ if (variables !== undefined) input.variables = variables;
398
377
 
399
378
  const result = await sdk.savedQueries.update(recordSlug, queryId, input as any);
400
379
  return {
@@ -456,7 +435,7 @@ ${CANONICAL_QUERY_DEFINITION_HINT}
456
435
 
457
436
  ${JOINS_HINT}
458
437
 
459
- Typed dry-run is not yet wired on the server: '/saved-queries/test' resolves '\${var}' placeholders via legacy string substitution and does not honor typed 'variableDeclarations'. Use create_saved_query + execute_saved_query (or update_saved_query) to validate typed parameters end-to-end.`,
438
+ This tool sends untyped runtime values to the canonical '/saved-queries/test' endpoint. Use create_saved_query + execute_saved_query to validate typed parameter declarations end-to-end.`,
460
439
  {
461
440
  recordSlug: z.string().describe("The collection's record slug to test against"),
462
441
  queryDefinition: z
@@ -469,7 +448,7 @@ Typed dry-run is not yet wired on the server: '/saved-queries/test' resolves '\$
469
448
  },
470
449
  async ({ recordSlug, queryDefinition, variables }) => {
471
450
  try {
472
- const input: Record<string, any> = { queryDefinition };
451
+ const input: Record<string, any> = { query: { ...(queryDefinition as object), resource: recordSlug } };
473
452
  if (variables !== undefined) input.variables = variables;
474
453
 
475
454
  const result = await sdk.savedQueries.test(recordSlug, input as any);
@@ -85,7 +85,7 @@ test("create: recordSlug overrides caller-supplied queryDefinition.resource", as
85
85
  assert.deepEqual(call.input.variables, { status: { type: "string", required: true } });
86
86
  });
87
87
 
88
- test("create: legacy path used when no variables declared", async () => {
88
+ test("create: canonical path used without variable declarations", async () => {
89
89
  const { server, sdk } = setup();
90
90
  const handler = server.handlers.get("create_saved_query");
91
91
  await handler({
@@ -94,8 +94,8 @@ test("create: legacy path used when no variables declared", async () => {
94
94
  queryDefinition: { where: { "data.status": { eq: "open" } } },
95
95
  });
96
96
  const call = sdk.calls.find((c) => c.method === "create");
97
- assert.ok(call.input.queryDefinition, "legacy field present");
98
- assert.equal(call.input.query, undefined, "no canonical query field");
97
+ assert.equal(call.input.query.resource, "orders");
98
+ assert.equal(call.input.queryDefinition, undefined);
99
99
  });
100
100
 
101
101
  test("update: recordSlug overrides caller-supplied queryDefinition.resource", async () => {
@@ -128,7 +128,7 @@ test("update: variables-only edit ships {variables} without query", async () =>
128
128
  assert.equal(call.input.variables, null, "variables cleared");
129
129
  });
130
130
 
131
- test("test_saved_query: never ships variableDeclarations (server doesn't honor it yet)", async () => {
131
+ test("test_saved_query: uses the canonical route without exposing typed declarations", async () => {
132
132
  const { server, sdk } = setup();
133
133
  const handler = server.handlers.get("test_saved_query");
134
134
  await handler({
@@ -142,7 +142,64 @@ test("test_saved_query: never ships variableDeclarations (server doesn't honor i
142
142
  });
143
143
  const call = sdk.calls.find((c) => c.method === "test");
144
144
  assert.equal(call.input.variableDeclarations, undefined);
145
- // Stays on the legacy slug-based test endpoint (no canonical `query`).
146
- assert.equal(call.input.query, undefined);
147
- assert.ok(call.input.queryDefinition);
145
+ assert.equal(call.input.query.resource, "orders");
146
+ assert.equal(call.input.queryDefinition, undefined);
147
+ });
148
+
149
+ test('saved-query lifecycle crosses MCP and the real SDK using canonical routes', async () => {
150
+ const { SmartQueriesManager } = require('../../centrali-sdk/dist/index.js');
151
+ const server = makeFakeServer();
152
+ const rows = new Map();
153
+ const requests = [];
154
+ const collection = { slug: 'orders', records: [{ amount: 20 }] };
155
+ const manager = new SmartQueriesManager('acme', async (method, path, body, params) => {
156
+ requests.push({ method, path, body, params });
157
+ const base = 'data/workspace/acme/api/v1/saved-queries';
158
+ assert.ok(path.startsWith(base));
159
+ assert.ok(!path.includes('/slug/'), 'must never call a retired route');
160
+ if (method === 'POST' && path === base) {
161
+ const row = { id: `query-${rows.size}`, recordSlug: body.query.resource, ...body };
162
+ rows.set(row.id, row);
163
+ return { data: row };
164
+ }
165
+ if (method === 'GET' && path === base) {
166
+ return { data: [...rows.values()].filter(r => !params?.recordSlug || r.recordSlug === params.recordSlug) };
167
+ }
168
+ const id = path.slice(base.length + 1).split('/')[0];
169
+ const row = rows.get(id);
170
+ if (!row) throw new Error('[404] Saved query not found');
171
+ if (method === 'GET') return { data: row };
172
+ if (method === 'PUT') { Object.assign(row, body); return { data: row }; }
173
+ if (method === 'DELETE') { rows.delete(id); return { data: null }; }
174
+ assert.equal(method, 'POST');
175
+ assert.equal(path, `${base}/${id}/execute`);
176
+ return { data: collection.records.filter(r => r.amount === body.variables.amount), meta: {} };
177
+ });
178
+ registerSavedQueryTools(server, { savedQueries: manager });
179
+ const invoke = async (name, args) => {
180
+ const result = await server.handlers.get(name)(args);
181
+ assert.ok(!result.isError, JSON.stringify(result));
182
+ return JSON.parse(result.content[0].text);
183
+ };
184
+ const created = await invoke('create_saved_query', { recordSlug: 'orders', name: 'Amount',
185
+ queryDefinition: { where: { 'data.amount': { eq: '${amount}' } } },
186
+ variables: { amount: { type: 'number', required: true } } });
187
+ const target = { recordSlug: 'orders', queryId: created.id };
188
+ assert.equal((await invoke('list_saved_queries', {})).length, 1);
189
+ assert.equal((await invoke('list_saved_queries', { recordSlug: 'orders' }))[0].id, created.id);
190
+ assert.deepEqual(await invoke('list_saved_queries', { recordSlug: 'unrelated' }), []);
191
+ assert.equal((await invoke('get_saved_query', target)).id, created.id);
192
+ assert.equal((await invoke('execute_saved_query', { ...target, variables: { amount: 20 } })).length, 1);
193
+ assert.deepEqual(await invoke('execute_saved_query', { ...target, variables: { amount: 999 } }), []);
194
+ assert.equal((await invoke('update_saved_query', { ...target, name: 'Renamed' })).name, 'Renamed');
195
+ await invoke('update_saved_query', { ...target, queryDefinition: { where: { 'data.amount': { gte: 10 } } } });
196
+ const deletion = await server.handlers.get('delete_saved_query')(target);
197
+ assert.ok(!deletion.isError);
198
+ assert.equal(rows.size, 0);
199
+ assert.deepEqual(collection.records, [{ amount: 20 }], 'query deletion must leave collection records intact');
200
+ const missing = await server.handlers.get('get_saved_query')(target);
201
+ assert.equal(missing.isError, true);
202
+ assert.match(missing.content[0].text, /404/);
203
+ assert.ok(requests.some(r => r.method === 'DELETE'));
204
+ assert.deepEqual(requests.find(r => r.method === 'PUT').body, { name: 'Renamed' });
148
205
  });