Skip to content

Commit 6401b60

Browse files
Merge branch 'main' into brandon/mcp-output-telemetry
2 parents 01f6014 + 0000fa4 commit 6401b60

69 files changed

Lines changed: 2245 additions & 966 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/line-interpolation.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@hyperdx/common-utils': patch
3+
'@hyperdx/api': patch
4+
'@hyperdx/app': patch
5+
---
6+
7+
feat: Add a line interpolation display setting (smooth, linear, step)
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

‎.changeset/mcp-tool-annotations.md‎

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+
feat(mcp): declare readOnlyHint, destructiveHint, idempotentHint, and openWorldHint on every MCP tool
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperdx/api': patch
3+
'@hyperdx/common-utils': patch
4+
---
5+
6+
fix(mcp): describe every MCP tool input, drop descriptions that restate schema constraints, and keep tool descriptions under Claude Code's 2 KB limit

‎packages/api/openapi.json‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,16 @@
18471847
"description": "Set the y-axis lower bound to the minimum of the displayed data instead of zero, making small fluctuations between series easier to see.\n",
18481848
"default": false
18491849
},
1850+
"lineInterpolation": {
1851+
"type": "string",
1852+
"enum": [
1853+
"smooth",
1854+
"linear",
1855+
"step"
1856+
],
1857+
"example": "step",
1858+
"description": "How points are connected. Defaults to \"smooth\" when omitted.\n"
1859+
},
18501860
"numberFormat": {
18511861
"$ref": "#/components/schemas/NumberFormat",
18521862
"description": "Number formatting options for displayed values."
@@ -2006,6 +2016,16 @@
20062016
"description": "Fill missing time buckets with zero instead of leaving gaps.",
20072017
"default": true
20082018
},
2019+
"lineInterpolation": {
2020+
"type": "string",
2021+
"enum": [
2022+
"smooth",
2023+
"linear",
2024+
"step"
2025+
],
2026+
"example": "step",
2027+
"description": "How points are connected. Defaults to \"linear\" when omitted.\n"
2028+
},
20092029
"numberFormat": {
20102030
"$ref": "#/components/schemas/NumberFormat",
20112031
"description": "Number formatting options for displayed values."
@@ -2620,6 +2640,16 @@
26202640
"type": "boolean",
26212641
"description": "Set the y-axis lower bound to the minimum of the displayed data instead of zero, making small fluctuations between series easier to see.\n",
26222642
"default": false
2643+
},
2644+
"lineInterpolation": {
2645+
"type": "string",
2646+
"enum": [
2647+
"smooth",
2648+
"linear",
2649+
"step"
2650+
],
2651+
"example": "step",
2652+
"description": "How points are connected. Defaults to \"smooth\" when omitted.\n"
26232653
}
26242654
}
26252655
}
@@ -2688,6 +2718,16 @@
26882718
"type": "boolean",
26892719
"description": "Expand date range boundaries to the query granularity interval.",
26902720
"default": true
2721+
},
2722+
"lineInterpolation": {
2723+
"type": "string",
2724+
"enum": [
2725+
"smooth",
2726+
"linear",
2727+
"step"
2728+
],
2729+
"example": "step",
2730+
"description": "How points are connected. Defaults to \"linear\" when omitted.\n"
26912731
}
26922732
}
26932733
}

‎packages/api/src/mcp/__tests__/dashboards/saveDashboard.int.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
399399
},
400400
compareToPreviousPeriod: true,
401401
fitYAxisToData: true,
402+
lineInterpolation: 'step' as const,
402403
};
403404
const sqlNumberConfig = {
404405
configType: 'sql' as const,
@@ -996,6 +997,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
996997
numberFormat,
997998
compareToPreviousPeriod: true,
998999
fitYAxisToData: true,
1000+
lineInterpolation: 'linear' as const,
9991001
seriesLimit: 5,
10001002
};
10011003
const barConfig = {
@@ -1009,6 +1011,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
10091011
const stackedLineConfig = {
10101012
...barConfig,
10111013
displayType: 'stacked_line' as const,
1014+
lineInterpolation: 'step' as const,
10121015
};
10131016
const tableConfig = {
10141017
displayType: 'table' as const,

‎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', {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { McpContext } from '@/mcp/tools/types';
2+
3+
import { createTestClient } from './mcpTestUtils';
4+
5+
describe('MCP tool annotations', () => {
6+
const context: McpContext = { teamId: 'team-id', userId: 'user-id' };
7+
8+
it('declares every behavior hint as a boolean on every tool', async () => {
9+
const client = await createTestClient(context);
10+
const { tools } = await client.listTools();
11+
expect(tools.length).toBeGreaterThan(0);
12+
13+
const missing = tools.flatMap(tool =>
14+
Object.entries({
15+
readOnlyHint: tool.annotations?.readOnlyHint,
16+
destructiveHint: tool.annotations?.destructiveHint,
17+
idempotentHint: tool.annotations?.idempotentHint,
18+
openWorldHint: tool.annotations?.openWorldHint,
19+
})
20+
.filter(([, value]) => typeof value !== 'boolean')
21+
.map(([hint]) => `${tool.name}.annotations.${hint}`),
22+
);
23+
24+
expect(missing).toEqual([]);
25+
});
26+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { McpContext } from '@/mcp/tools/types';
2+
3+
import { createTestClient } from './mcpTestUtils';
4+
5+
describe('MCP tool descriptions', () => {
6+
const context: McpContext = { teamId: 'team-id', userId: 'user-id' };
7+
8+
// Claude Code truncates tool descriptions and server instructions past
9+
// this many UTF-8 bytes.
10+
const CLAUDE_CODE_METADATA_LIMIT = 2048;
11+
12+
it('keeps tool descriptions and server instructions within the Claude Code limit', async () => {
13+
const client = await createTestClient(context);
14+
const { tools } = await client.listTools();
15+
expect(tools.length).toBeGreaterThan(0);
16+
17+
const texts = [
18+
['instructions', client.getInstructions() ?? ''] as const,
19+
...tools.map(tool => [tool.name, tool.description ?? ''] as const),
20+
];
21+
22+
expect(
23+
texts.filter(([, text]) => text.trim() === '').map(([name]) => name),
24+
).toEqual([]);
25+
26+
const oversized = texts
27+
.map(([name, text]) => [name, Buffer.byteLength(text, 'utf8')] as const)
28+
.filter(([, bytes]) => bytes > CLAUDE_CODE_METADATA_LIMIT);
29+
30+
expect(oversized).toEqual([]);
31+
});
32+
});

‎packages/api/src/mcp/__tests__/toolSchemas.test.ts‎

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,25 @@ describe('MCP tool input schemas', () => {
7979

8080
expect(tools.length).toBeGreaterThan(0);
8181

82-
const offenders = tools.flatMap(tool => walk(tool.inputSchema, tool.name));
82+
const offenders = tools.flatMap(tool =>
83+
walk(tool.inputSchema, tool.name, providerRejections),
84+
);
8385

8486
expect(offenders).toEqual([]);
8587
});
88+
89+
it('describe every input property', async () => {
90+
const client = await createTestClient(context);
91+
const { tools } = await client.listTools();
92+
93+
expect(tools.length).toBeGreaterThan(0);
94+
95+
const missing = tools.flatMap(tool =>
96+
walk(tool.inputSchema, tool.name, undescribedProperties),
97+
);
98+
99+
expect(missing).toEqual([]);
100+
});
86101
});
87102

88103
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -93,13 +108,26 @@ function isUnknownArray(value: unknown): value is unknown[] {
93108
return Array.isArray(value);
94109
}
95110

96-
/** JSON pointer path -> problem, for every offending node under `node`. */
97-
function walk(node: unknown, path: string): string[] {
111+
type SchemaCheck = (node: Record<string, unknown>, path: string) => string[];
112+
113+
/** JSON pointer path -> problem, for every node under `node` that fails `check`. */
114+
function walk(node: unknown, path: string, check: SchemaCheck): string[] {
98115
if (isUnknownArray(node)) {
99-
return node.flatMap((child, i) => walk(child, `${path}/${i}`));
116+
return node.flatMap((child, i) => walk(child, `${path}/${i}`, check));
100117
}
101118
if (!isRecord(node)) return [];
102119

120+
const found = check(node, path);
121+
for (const [key, value] of Object.entries(node)) {
122+
found.push(...walk(value, `${path}/${key}`, check));
123+
}
124+
return found;
125+
}
126+
127+
function providerRejections(
128+
node: Record<string, unknown>,
129+
path: string,
130+
): string[] {
103131
const found: string[] = [];
104132

105133
const enumValues = node.enum;
@@ -120,9 +148,22 @@ function walk(node: unknown, path: string): string[] {
120148
);
121149
}
122150

123-
for (const [key, value] of Object.entries(node)) {
124-
found.push(...walk(value, `${path}/${key}`));
125-
}
126-
127151
return found;
128152
}
153+
154+
function undescribedProperties(
155+
node: Record<string, unknown>,
156+
path: string,
157+
): string[] {
158+
if (!isRecord(node.properties)) return [];
159+
return Object.entries(node.properties).flatMap(([key, prop]) => {
160+
if (!isRecord(prop)) return [];
161+
// zod-to-json-schema dedupes a reused schema into a bare $ref pointer;
162+
// the description lives on the referenced definition.
163+
if (Object.keys(prop).length === 1 && '$ref' in prop) return [];
164+
const { description } = prop;
165+
return typeof description === 'string' && description.trim() !== ''
166+
? []
167+
: [`${path}/properties/${key}: missing description`];
168+
});
169+
}

0 commit comments

Comments
 (0)