Skip to content

feat(mcp): support savedFilterValues in dashboard tools - #3533

Merged
pulpdrew merged 1 commit into
mainfrom
cursor/mcp-saved-filter-values-611d
Nov 3, 2026
Merged

pulpdrew merged 1 commit into
mainfrom
cursor/mcp-saved-filter-values-611d

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The MCP dashboard tools could not set a dashboard's savedFilterValues (the default filter selections restored every time a dashboard opens). The clickstack_save_dashboard now supports reading and writing these values.

How to reproduce

Ask your MCP enabled agent to create a dashboard with some saved filter values

Observe that they're showing when you open the dashboard:

Screenshot 2026-11-03 at 3 33 34 PM

References

  • Linear Issue: Closes HDX-5887

@pulpdrew
pulpdrew requested a review from a team as a code owner November 3, 2026 16:08
@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4f22b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Minor
@hyperdx/app Minor
@hyperdx/otel-collector Minor

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

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 3, 2026 8:39pm UTC
hyperdx-storybook Ready Ready Preview Nov 3, 2026 8:39pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 6
  • Production lines changed: 166 (+ 343 in test files, excluded from tier calculation)
  • Branch: cursor/mcp-saved-filter-values-611d
  • Author: pulpdrew

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

1 new clone introduced by this PR.

  • packages/api/src/mcp/tools/dashboards/saveDashboard.ts:184-199 ↔ packages/api/src/mcp/tools/dashboards/saveDashboard.ts:296-311 — 16 lines

If one of these duplicates a helper that already exists, import it instead
of redefining it. If the duplication is deliberate, ignore this comment —
the check is advisory and never fails the build.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 114 in total (1.40%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

3 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 2 minor

2 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

1 minor
  • 🔵 packages/api/src/mcp/tools/dashboards/validation.ts:730 — Warning check trims the variable name, but the dashboard loader matches the exact string → parseDashboardFilterValues/resolveFilterSelection (packages/common-utils/src/dashboardFilterValues.ts:80,189) look up byVariable by the exact, untrimmed name, and name is stored untrimmed. An entry like {type:'variable', name:' service'} gets no warning but never applies when the dashboard loads. Either compare value.name without trimming, or trim the name in the schema so the stored value is the one that was checked.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Scope: 6 production files + 1 test file under packages/api/src/mcp/tools/dashboards/ and packages/api/src/utils/zod.ts (base 769c0def3).
Intent: Wire a dashboard's savedFilterValues (default filter selections restored on open) through the MCP tools clickstack_save_dashboard and clickstack_patch_dashboard.

🔴 P0/P1 — must fix

  • packages/api/src/mcp/tools/dashboards/patchDashboard.ts:106 — The patch write overwrites the entire persisted savedFilterValues array with only the agent-supplied sql/variable entries, silently deleting any persisted type: 'adhoc' entries that the dashboard UI saved and that MCP reads deliberately hide via getExternalCompatibleFilterValues.
    • Fix: Before writing, merge the existing type: 'adhoc' entries from existingDashboard.savedFilterValues back into the array being persisted, mirroring the hidden-PromQL-tile and hidden-PROMETHEUS_LABEL-filter preservation already done in these handlers.
  • packages/api/src/mcp/tools/dashboards/saveDashboard.ts:427 — The save-update path has the same defect: setPayload.savedFilterValues = parsed.data.savedFilterValues replaces the whole array, so a save-update (including the documented []-to-clear path) drops hidden adhoc saved values that the agent cannot see or re-supply. A UI user's ad hoc default is lost the next time an agent updates the dashboard.
    • Fix: Reuse the same adhoc-preservation merge against existingDashboard.savedFilterValues so round-tripping through MCP never deletes UI-only saved filter values.

🟡 P2 — recommended

  • packages/api/src/mcp/__tests__/dashboards/saveDashboard.int.test.ts:146 — No test seeds a persisted type: 'adhoc' saved filter value and asserts it survives an MCP save-update, a [] clear, and a patch; the new suite only exercises sql/variable round-trips, so the data-loss regression above is uncovered.
    • Fix: Add integration cases that store an adhoc saved value directly on the Dashboard doc, then assert it is retained after each MCP write path.
🔵 P3 nitpicks (1)
  • packages/api/src/mcp/tools/dashboards/patchDashboard.ts:93 — setPayload is typed Record<string, unknown>, so the savedFilterValues assignment is not compile-checked against the Mongo document shape the way the save-update path's Partial<IDashboard> payload is.
    • Fix: Type the patch setPayload as Partial<IDashboard> for parity and compile-time safety on dashboard-level fields.

Reviewers (7): correctness, testing, maintainability, project-standards, kieran-typescript, api-contract, previous-comments.

Testing gaps: No coverage that hidden adhoc saved filter values persist across MCP write paths; the primary data-loss scenario is untested.

Note: Prior-round bot comments claim a mergeHiddenAdhocFilterValues helper and a re-parse through externalDashboardSavedFilterValueSchema were added to preserve adhoc values; neither is present in the final squashed branch (mergeHiddenAdhocFilterValues does not exist anywhere in the tree), so that fix must be treated as unlanded. The zod.ts refactor that factors the shared sql/variable sub-schemas is behavior-preserving, so the earlier schema-drift concern is adequately mitigated.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 459 passed • 1 skipped • 1638s

Status Count
✅ Passed 459
❌ Failed 0
⚠️ Flaky 3
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@cursor

cursor Bot commented Nov 3, 2026

Copy link
Copy Markdown

Addressed the review findings in commits 4789d39d2 and 943405a70:

  • CI (unit) failure — toolSchemas.test.ts requires every MCP input property to have a description; reusing the external schema left the savedFilterValues sub-fields undescribed. Replaced it with a described MCP variant that mirrors externalDashboardSavedFilterValueSchema.
  • Hidden ADHOC saved values (major) — both the save-update and patch paths now preserve persisted type: 'adhoc' entries via the shared mergeHiddenAdhocFilterValues helper. Tests seed an adhoc value and assert it survives update, update-with-[], and patch.
  • Unmatched variable warning (minor) — both handlers now warn when a variable saved value names no declared filter variable.
  • Combined patch test (minor) — added a case that patches tileId+tile together with savedFilterValues and asserts both the stored tile and the stored values changed.
  • jscpd duplicate (advisory) — the flagged clone is the pre-existing parallel create/update boilerplate in saveDashboard.ts (source-check → validateDashboardTiles → warnings); the two paths differ enough (strip vs. assign filter ids, existing-dashboard lookup, adhoc merge) that I'm leaving them separate rather than hoisting.

All 111 saveDashboard + 28 patchDashboard integration tests and the api unit suite pass locally.

@cursor

cursor Bot commented Nov 3, 2026

Copy link
Copy Markdown

Round 2 responses (commit 2e66b6f5a):

  • 🔵 MCP schema retypes external constraints (drift risk) — Fixed the real concern (patch stored MCP-validated values directly, so drift could let it persist values save/REST reject): clickstack_patch_dashboard now re-parses savedFilterValues through externalDashboardSavedFilterValueSchema — the same authoritative schema clickstack_save_dashboard's body schema and the REST v2 writer use — before storing. The described MCP schema stays for the LLM-facing JSON Schema.
  • 🔵 Concurrent-write rejection message — Updated to "dashboard-level changes (name/tags/savedFilterValues, if any) were not applied."
  • 🟡 P2: patch-with-[] preserving a hidden ADHOC entry — Added that integration test.

Replying, not changing (out of scope / pre-existing):

  • 🟠 REST v2 PUT also deletes hidden ADHOC values — This is pre-existing REST behavior that predates this PR; routers/external-api/v2/dashboards.ts is not touched here. This PR only added the MCP write path and preserves ADHOC on both MCP write paths. Applying the same guard to the REST PUT (and factoring a shared write helper across all three paths) is a sensible follow-up but widens the change, so I'm leaving it for a separate PR.
  • 🔵 Warn on orphaned stored defaults when filters change — replied inline; the warning targets values the call writes, and re-auditing preserved defaults is a broader behavior I'd rather not add here.
  • jscpd duplicate — the clone is the pre-existing parallel create/update boilerplate in saveDashboard.ts; the two paths differ (strip vs. assign filter ids, existing-dashboard lookup, adhoc merge), so I'm keeping them separate.

This is the second round of automated findings, so per AGENTS.md I'll stop here and defer remaining advisory items to a maintainer's scope review.

The failing CI check (E2E Shard 4) is an infra flake — the Next.js webServer timed out starting in CI (Timed out waiting 180000ms); the aggregate E2E run reports 458 passed / 0 failed. This PR is API-only with no app changes.

Verification: make dev-int FILE=saveDashboard 112/112, make dev-int FILE=patchDashboard 28/28, toolSchemas unit 3/3, tsc clean, lint clean.

@pulpdrew

pulpdrew commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Re the P0s - adhoc filters are not supported in external API or MCP yet, and are behind a toggle. This gap will naturally be closed when the external api and MCP schemas are updated to support them.

@brandon-pereira brandon-pereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement!

@pulpdrew
pulpdrew merged commit 95fa364 into main Nov 3, 2026
36 of 38 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — b4f22b15 Deployed Nov 3, 2026 by vercel[bot]
Preview – hyperdx-storybook — b4f22b15 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants