Skip to content

Commit 24d324c

Browse files
fix(mcp): default whereLanguage to lucene when creating a saved search (#3404)
## Summary `clickstack_save_saved_search` stores a new saved search without `whereLanguage` when the caller omits it. The app reads a missing value as Lucene, but alerts read it as SQL (`buildSearchChartConfig` falls back to `'sql'`). So a Lucene filter such as `level:error` looks fine in the search page while the search's alerts evaluate it as SQL and break. Found by @pulpdrew in review of #3396. - On create, an omitted `whereLanguage` is now stored as `lucene`, which matches the app and the tool's description. - On update, an omitted `whereLanguage` still keeps the stored value. A schema-level `.default('lucene')` would have overwritten a stored `sql` value on every update that left the field out, so the default lives on the create path only. Stacked on #3396, which kept its changes to descriptions only. ### How to reproduce **Starting point:** local `yarn dev`, with an MCP client connected (see `MCP.md`). **On `main`:** 1. Call `clickstack_save_saved_search` with a `name`, a `sourceId`, and `where: "level:error"`, and no `whereLanguage`. 2. Call `clickstack_get_saved_search` with the returned id. `whereLanguage` is missing. **On this branch:** 1. Repeat the steps above. `whereLanguage` is `lucene`. 2. Update the same search with `whereLanguage: "sql"`, then update it again without `whereLanguage`. It stays `sql`. `packages/api/src/mcp/__tests__/savedSearches.int.test.ts` covers both cases. ### References - Related PRs: #3396 (base)
1 parent e494a46 commit 24d324c

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hyperdx/api': patch
3+
---
4+
5+
fix(mcp): store whereLanguage as lucene when clickstack_save_saved_search creates a search without one, so its alerts no longer parse a Lucene filter as SQL

‎packages/api/src/mcp/__tests__/savedSearches.int.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ describe('MCP Saved Search Tools', () => {
239239
expect(output.where).toBe('');
240240
expect(output.select).toBe('');
241241
expect(output.tags).toEqual([]);
242+
expect(output.whereLanguage).toBe('lucene');
242243
});
243244

244245
it('should create a saved search with SQL where language', async () => {
@@ -378,6 +379,24 @@ describe('MCP Saved Search Tools', () => {
378379
expect(updated?.where).toBe('StatusCode:Ok');
379380
});
380381

382+
it('should keep the stored whereLanguage when an update omits it', async () => {
383+
const savedSearch = await createTestSavedSearch({
384+
where: "StatusCode = 'Error'",
385+
whereLanguage: 'sql',
386+
});
387+
388+
const result = await callTool(client, 'clickstack_save_saved_search', {
389+
id: savedSearch._id.toString(),
390+
name: 'Renamed',
391+
sourceId: traceSource._id.toString(),
392+
where: "StatusCode = 'Ok'",
393+
});
394+
395+
expect(result.isError).toBeFalsy();
396+
const updated = await SavedSearch.findById(savedSearch._id);
397+
expect(updated?.whereLanguage).toBe('sql');
398+
});
399+
381400
it('should return error for non-existent saved search on update', async () => {
382401
const fakeId = '000000000000000000000000';
383402
const result = await callTool(client, 'clickstack_save_saved_search', {

‎packages/api/src/mcp/tools/savedSearches/saveSavedSearch.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export function registerSaveSavedSearch({
6060
name: input.name,
6161
select: input.select ?? '',
6262
where: input.where ?? '',
63-
whereLanguage: input.whereLanguage,
63+
// Alerts read a missing whereLanguage as sql while the app reads it as
64+
// lucene, so a new search must store it explicitly.
65+
whereLanguage: input.whereLanguage ?? (isUpdate ? undefined : 'lucene'),
6466
orderBy: input.orderBy,
6567
source: input.sourceId,
6668
tags: input.tags ?? [],

0 commit comments

Comments
 (0)