Skip to content

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

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

karl-power wants to merge 4 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
MCP-only serialization and patch validation; persistence behavior unchanged and covered by integration tests.

Overview
Fixes MCP round-trips so agents can pipe get → save/patch without strict clients rejecting unknown fields.

Dashboard filters: clickstack_get_dashboard and save responses now run filters through toMcpOutputFilters, which resolves variableName and strips schema-fixed literals (e.g. isBroadcastEnabled / isVariableEnabled on most types, minSelections / maxSelections on CONNECTION/DATA_SOURCE) derived from DashboardFilterSchema. QUERY_EXPRESSION still exposes the mode flags agents can set. Persistence still fills fixed values on save; REST output is unchanged.

Tiles: clickstack_patch_dashboard allows an optional tile.id when it equals tileId and errors if they differ; the patch input schema documents this for tiles from clickstack_get_dashboard_tile.

Tests: Integration tests assert Ajv validation against advertised tool schemas (getToolSchemaErrors) for filter and tile round-trips; unit coverage for toMcpOutputFilters.

Reviewed by Cursor Bugbot for commit 477c6e7. 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 Dec 2, 2026 11:40am UTC
hyperdx-storybook Ready Ready Preview Dec 2, 2026 11:40am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 477c6e7

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

github-actions Bot commented Nov 30, 2026 •

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 109 in total (1.10%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 490 passed • 1 skipped • 1119s

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

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The change is correct and well-covered: the tile.id guard is sound (a mismatch is rejected before any write, and the merge always sets id: tileId), REST output is confirmed unchanged (toMcpOutputFilters is imported only by the MCP get/save tools), the get→save round-trip is exercised for all 7 filter types via Ajv, and the prior "2 changesets intentional?" comment is resolved by the consolidation commit. The notes below are hardening and test-robustness recommendations.

🟡 P2 — recommended

  • packages/api/src/mcp/tools/dashboards/variables.ts:388 — The fixed-field strip list is built at module load by testing each filter sub-schema with instanceof z.ZodLiteral against DashboardFilterSchema, an unenforced coupling with two silent-regression modes: if @hyperdx/api and @hyperdx/common-utils ever resolve different zod module instances the instanceof yields false for every field and nothing is stripped, and the heuristic equates "literal in the storage schema" with "rejected by the hand-authored MCP input schema" so the two can drift apart — either case breaks the round trip with no build-time or runtime error.
    • Fix: Add a module-load or test assertion that each known filter type resolves to its expected non-empty fixed-field set, and detect literals structurally (e.g. via the schema's def type name) rather than by cross-package class identity.
    • adversarial, correctness, maintainability, kieran-typescript
  • packages/api/src/mcp/__tests__/mcpTestUtils.ts:52 — getToolSchemaErrors is the only verifier of the "get output is valid save input" contract, but every call site asserts toEqual([]) and no test proves the helper can return a non-empty array, so the round-trip assertions could pass vacuously if the compiled schema omits additionalProperties:false or Ajv drops the deleted draft-07 constraints under strict:false.
    • Fix: Add a negative-control test asserting a known-invalid payload (e.g. a STATIC_LIST filter carrying isBroadcastEnabled) yields a non-empty error array.
    • testing
🔵 P3 nitpicks (4)
  • packages/api/src/mcp/tools/dashboards/variables.ts:116 — The agent-facing error text points readers to isVariableEnabled on filters returned by clickstack_get_dashboard, but that flag is now stripped from get output for every non-QUERY_EXPRESSION type.
    • Fix: Reword the message to reference variableName/type instead of the omitted flag.
  • packages/api/src/mcp/tools/dashboards/variables.ts:384 — The comment describes the stripped fields as "the mode flags of every type but QUERY_EXPRESSION" but the reflection also drops minSelections/maxSelections on DATA_SOURCE and CONNECTION.
    • Fix: Extend the comment to state it strips every non-discriminator literal field, including the fixed selection limits.
  • packages/api/src/mcp/tools/dashboards/variables.ts:403 — toMcpOutputFilters has no return annotation, so lodash omit widens the result to Partial<ExternalDashboardFilterWithId>[], leaving the doc comment's "valid input to clickstack_save_dashboard" claim unenforced by the compiler.
    • Fix: Give the helper an explicit narrowed return type via a typed strip helper rather than relying on omit's widened inference.
  • packages/api/src/mcp/__tests__/dashboards/getDashboard.int.test.ts:151 — Explicit per-type stripping is asserted only for QUERY_EXPRESSION (retained) and STATIC_LIST (dropped); the other five types are covered only indirectly through the Ajv round-trip.
    • Fix: Iterate all returned filters asserting none carry fields the save schema rejects, or add explicit per-type assertions.
    • testing, correctness, adversarial

Reviewers (10): correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, kieran-typescript, api-contract, adversarial, previous-comments.

Testing gaps:

  • The auto-derived variableName path is untested — round-trip fixtures all set explicit variable names, so a display name that derives to a token failing DASHBOARD_VARIABLE_NAME_PATTERN_ANCHORED would not round-trip and is uncaught.
  • No test asserts the REST path still emits isBroadcastEnabled/isVariableEnabled/minSelections/maxSelections; "REST unchanged" is established only structurally.
  • The all-7-types round-trip runs with promqlEnabled:true; the non-promql save schema is covered only by smaller pre-existing cases, and the unknown/preset filter-type ?? [] fallback is untested.

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

Comment thread .changeset/mcp-filter-roundtrip.md Resolved

This branch was successfully deployed

2 active (outdated) 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

automerge 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