feat(mcp): add hyperdx_event_deltas tool#2333
Conversation
Extract the event-deltas ranking algorithm from the UI (deltaChartUtils.ts) into @hyperdx/common-utils/src/core/eventDeltas.ts so it can be shared between the frontend and the MCP server. Add a new hyperdx_event_deltas MCP tool that compares two row groups (target vs baseline) and ranks properties by how much their value distributions differ. Same algorithm as the in-app Event Deltas view. Changes: - New: packages/common-utils/src/core/eventDeltas.ts (shared algorithm) - New: packages/api/src/mcp/tools/query/eventDeltas.ts (MCP tool) - New: Unit tests for the shared algorithm - New: Integration tests for the MCP tool - Modified: deltaChartUtils.ts re-exports from common-utils - Modified: query/index.ts registers the new tool
🦋 Changeset detectedLatest commit: 71ad6aa The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
E2E Test Results✅ All tests passed • 176 passed • 3 skipped • 1236s
Tests ran across 4 shards in parallel. |
- Remove unresolved import of utils/toon (not available yet), inline JSON.stringify for MCP text output matching existing tool patterns - Remove unused re-exports from deltaChartUtils.ts: flattenData, MIN_PROPERTY_OCCURENCES, rankProperties
🔴 Tier 4 — CriticalTouches auth, data models, config, tasks, OTel pipeline, ClickHouse, or CI/CD. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Deep Review🟡 P2 -- recommended
🔵 P3 nitpicks (22)
Reviewers (7): correctness, adversarial, testing, security, kieran-typescript, maintainability, reliability, performance. Testing gaps:
|
- Remove unused key param from topDeltasForProperty (was using void key) - Hoist duplicate stripTypeWrappers import to top of deltaChartUtils.ts - Simplify default sampleSize to MIN_SAMPLE_SIZE (500) instead of misleading computeEffectiveSampleSize indirection; fix schema description - Add columnMetaUnavailable flag to summary when getColumns fails - Add max_execution_time: 30 to ClickHouse queries (match sibling tools) - Parallelize metadata.getColumns with renderChartConfig in Promise.all - Guard implicitColumnExpression with 'in' check (match helpers.ts pattern) - Capture Date.now() once per describe block in test (avoid flaky timing) - Strengthen includeHidden test: assert hidden.length > 0 and Body entry
P1: Add AbortController to parallel ClickHouse sample queries so that when one rejects, the sibling's in-flight request is aborted instead of leaving an orphaned HTTP stream. P2 fixes: - Add .default(500) to sampleSize Zod schema so JSON schema exposed via tools/list matches runtime default - Emit summary.warning when target or baseline returns 0 rows P3 fixes: - Remove redundant deltasSchema.parse() (MCP already validates input) - Fix hidden entries restarting rank at 1 — continue from visible count - Drop JSON.stringify indent (saves ~30-50% payload whitespace) - Use source.kind === SourceKind.Trace instead of duck-type 'in' check for spanIdExpression - Add hyperdx_event_deltas row to MCP.md tool catalog
Summary
Add the
hyperdx_event_deltasMCP tool that compares two row groups (target vs baseline) and ranks properties by how much their value distributions differ. Uses the same algorithm as the in-app Event Deltas view (DBDeltaChart).What changed
New files
packages/common-utils/src/core/eventDeltas.ts— Pure algorithm functions extracted from the UI:flattenData,getPropertyStatistics,computeComparisonScore,semanticBoost, field classification helpers, sampling config, andrankProperties. Shared by both the UI and MCP server.packages/api/src/mcp/tools/query/eventDeltas.ts— Thehyperdx_event_deltasMCP tool. Validates input, queries ClickHouse for target/baseline row samples, runsrankProperties, and returns ranked property deltas.packages/common-utils/src/__tests__/eventDeltas.test.ts— Unit tests for the shared algorithm.packages/api/src/mcp/__tests__/deltasTool.test.ts— Integration tests for the MCP tool (schema validation, time range rejection, algorithm ranking against ClickHouse data).Modified files
packages/api/src/mcp/tools/query/index.ts— RegistereventDeltastool.packages/app/src/components/deltaChartUtils.ts— Replaced inline algorithm definitions with re-exports from@hyperdx/common-utils/dist/core/eventDeltas. UI-only helpers (mergeValueStatisticsMaps,applyTopNAggregation,computeEntropyScore, filter key converters, constants) remain in place.How the tool works
Given a source ID, a target group (time window + optional filter), and a baseline group, the tool:
renderChartConfigrankPropertiesalgorithm to score every property by distribution deltaTypical uses: slow vs fast spans, before vs after a deploy, failing vs succeeding requests.