Skip to content

fix(mcp): let fetched dashboard filters and tiles be saved and patched back - #3865

Open
karl-power wants to merge 2 commits into
mainfrom
claude/mcp-filter-roundtrip
Open

karl-power wants to merge 2 commits into
mainfrom
claude/mcp-filter-roundtrip

Conversation

@karl-power

@karl-power karl-power commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Filters and tiles returned by the MCP dashboard tools can now be passed straight back to save and patch.

  • clickstack_get_dashboard and the clickstack_save_dashboard response no longer return filter fields that the filter type fixes to one value: isBroadcastEnabled/isVariableEnabled on every type except QUERY_EXPRESSION, and minSelections/maxSelections on DATA_SOURCE and CONNECTION. The save schema doesn't accept them, so strict MCP clients rejected the get output. Saving fills them back in.
  • The fixed fields are read from DashboardFilterSchema (z.literal fields), so new filter types need no change here. REST output is unchanged.
  • Removing the fields from output keeps the MCP input schemas and prompt unchanged and only shows agents fields they can set, so the alternative of accepting them as optional literals on save wasn't needed.
  • clickstack_patch_dashboard accepts an optional tile.id, so a fetched tile can be passed back as is. An id that doesn't match tileId is rejected.
  • New tests check the round trips against each tool's advertised schema with Ajv, the way strict clients do. The server drops unknown nested keys without an error, so calling the tool alone wouldn't catch this.

How to reproduce

Starting point: yarn dev, with an MCP client that validates tool arguments against the advertised schema.

On main:

  1. Create a dashboard with a STATIC_LIST filter, a SQL_QUERY filter, and one tile.
  2. Call clickstack_get_dashboard, then clickstack_save_dashboard with the returned filters unchanged. It fails with filters.N.isBroadcastEnabled: unknown field and filters.N.isVariableEnabled: unknown field.
  3. Call clickstack_get_dashboard_tile, then clickstack_patch_dashboard with the returned tile. It fails with tile.id: unknown field.

On this branch:

  1. Repeat the steps. Both calls succeed and the dashboard is unchanged.

Without an MCP client: make dev-int FILE=mcp/__tests__/dashboards passes here, and the new tests fail on main.

How to test on Vercel preview

N/A — non-UI change


Note

Low Risk
Scoped MCP serialization and patch validation fixes with broad integration tests; REST API output is unchanged and persistence behavior is preserved.

Overview
MCP dashboard get and save responses now run filters through toMcpOutputFilters, which drops schema-fixed fields (isBroadcastEnabled / isVariableEnabled on non–query-expression types, and selection limits on connection/data-source filters) so agents can pass clickstack_get_dashboard output straight into clickstack_save_dashboard without strict clients rejecting extra keys. QUERY_EXPRESSION filters still expose the mode flags agents can set; save continues to backfill fixed values in storage.

clickstack_patch_dashboard accepts an optional tile.id on the patch payload (must match tileId) so tiles from get tools round-trip unchanged; mismatched ids are rejected.

Tests add getToolSchemaErrors (Ajv against advertised tool schemas) and integration coverage for filter and tile round trips.

Reviewed by Cursor Bugbot for commit 0eb302a. Bugbot is set up for automated code reviews on this repo. Configure here.

clickstack_get_dashboard returned fields such as isBroadcastEnabled and
isVariableEnabled on filter types that fix them to one value, and the MCP
filter schemas don't declare them, so the output could not be passed back
to clickstack_save_dashboard. Omit every field a filter type pins to a
literal in DashboardFilterSchema from MCP output. REST output is unchanged.
clickstack_get_dashboard and clickstack_get_dashboard_tile return each tile
with its id, but the patch tool's tile schema didn't declare one, so clients
that check arguments against the advertised schema rejected a fetched tile.
Accept an optional id and reject it when it differs from tileId.
@karl-power
karl-power requested a review from a team as a code owner November 30, 2026 15:08
@vercel

vercel Bot commented Nov 30, 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 30, 2026 3:13pm UTC
hyperdx-storybook Ready Ready Preview Nov 30, 2026 3:13pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0eb302a

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 Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

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

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

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: 5
  • Production lines changed: 62 (+ 312 in test files, excluded from tier calculation)
  • Branch: claude/mcp-filter-roundtrip
  • Author: karl-power

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

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


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

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 479 passed • 1 skipped • 1162s

Status Count
✅ Passed 479
❌ Failed 0
⚠️ Flaky 12
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The change is correct and the round trip is lossless: every field stripped from MCP output (isBroadcastEnabled, isVariableEnabled, minSelections, maxSelections) is a z.literal pinned by the filter type in DashboardFilterSchema, and the save schema's .default() values reconstruct each one identically — so no stored data can be lost or mutated on a get→save round trip. QUERY_EXPRESSION correctly keeps its mode flags (they are z.boolean().optional(), not literals). The new tile.id is optional and purely additive, and its mismatch guard runs after the both-or-neither check, so existing patch calls are unaffected. REST (external-api v2) output is genuinely untouched — toMcpOutputFilters is only wired into the two MCP tools.

🟡 P2 — recommended

  • packages/api/src/mcp/__tests__/dashboards/saveDashboard.int.test.ts:4175 — DATA_SOURCE fixed-field stripping (minSelections/maxSelections plus the mode flags) is asserted only via expect.objectContaining, which cannot fail on a leaked field, so a regression that stopped stripping them would pass; CONNECTION has a strict toEqual but its sibling DATA_SOURCE does not.
    • Fix: Assert the returned DATA_SOURCE filter with a strict toEqual listing the exact kept keys so any leaked fixed field fails.
    • testing
  • packages/api/src/mcp/tools/dashboards/variables.ts:388 — the strip set (FIXED_FILTER_FIELDS_BY_TYPE) is derived by runtime reflection over DashboardFilterSchema literal fields while the refill .default() values are hand-authored separately in common-utils, and no test enforces that the two stay aligned across all seven filter types, so a future type or a z.literal→z.boolean edit can silently break the round trip or reintroduce a dropped field.
    • Fix: Add a test asserting the derived strip set covers every DashboardFilterSchema member and matches the fields the save schema refills.
    • maintainability, correctness, api-contract, adversarial
🔵 P3 nitpicks (3)
  • packages/api/src/mcp/__tests__/dashboards/promqlTiles.int.test.ts:257 — PROMETHEUS_LABEL fixed-field stripping is asserted only via expect.objectContaining, which ignores extra keys.
    • Fix: Use strict toEqual listing the exact kept keys so a leaked isBroadcastEnabled/isVariableEnabled fails.
  • packages/api/src/mcp/__tests__/dashboards/saveDashboard.int.test.ts:4200 — SQL_QUERY fixed-field stripping is asserted only via toMatchObject, which ignores extra keys.
    • Fix: Use strict toEqual on the returned SQL_QUERY filter.
  • packages/api/src/mcp/tools/dashboards/variables.ts:403 — toMcpOutputFilters has no return annotation, so lodash omit with a dynamic string[] infers Partial<ExternalDashboardFilterWithId>[], erasing the discriminated union; harmless today since all callers immediately JSON.stringify.
    • Fix: Add an explicit return-type annotation or build the stripped object with typed per-type logic.
    • kieran-typescript

Pre-existing (not counted toward verdict):

  • packages/api/src/mcp/tools/dashboards/variables.ts:377 — a variable-enabled filter whose name sanitizes to more than 64 characters produces a derived variableName that the save schema's 64-char cap rejects, breaking the "save accepts get output unchanged" guarantee for that edge case; deriveVariableName predates this diff. adversarial

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

Testing gaps:

  • No strict (non-objectContaining) assertion that DATA_SOURCE, SQL_QUERY, or PROMETHEUS_LABEL output omits its fixed fields; only STATIC_LIST, CONNECTION, and ADHOC have exact-equality coverage.
  • No invariant test that the reflection-derived strip set matches the save-schema refill defaults for every filter type, which is the failure mode most likely to silently reintroduce the original bug.

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

'@hyperdx/api': patch
---

fix: MCP dashboard filters from `clickstack_get_dashboard` can be saved back with `clickstack_save_dashboard` unchanged. MCP output now leaves out the fields a filter type fixes to one value (the mode flags on every type but QUERY_EXPRESSION, and the selection limits on data source and connection variables), which the save schema rejects.

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.

is 2 changesets intentional?

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 0eb302af Deployed Nov 30, 2026 by vercel[bot]
Preview – hyperdx-storybook — 0eb302af Deployed Nov 30, 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