fix(hyperdx): tolerate JSON-encoded array/number params from MCP transport#432
Merged
JonasJesus42 merged 1 commit intomainfrom May 7, 2026
Merged
Conversation
…sport Some MCP transport bridges JSON-stringify structured params (arrays, objects) and numeric params before delivering them to the server. Real session reports: - QUERY_CHART_DATA: series rejected (expected array, received string) — 6+ failures - GET_LOG_DETAILS: groupBy rejected (expected array, received string) — 2-3 failures - SEARCH_LOGS: limit rejected (expected number, received string) Add a small coerce helper (arr() / num()) and wrap every array and number input field across the HyperDX tools so they accept either the raw type or a JSON/numeric string. Mirrors the same pattern already in vtex/server/tools/custom/reorder-collection.ts. Adds unit tests for the helper and the queryChartDataInputSchema. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A real HyperDX MCP session against the deployed worker (
sites-hyperdx.decocache.com/mcp) hit repeated zod validation failures because the MCP transport was JSON-encoding structured params before delivering them:QUERY_CHART_DATA—seriesrejected as string (expected "array", received "string") — 6+ failuresGET_LOG_DETAILS—groupByrejected as string — 2–3 failuresSEARCH_LOGS—limitrejected as string — 1 failureSome MCP bridges stringify nested arrays/numbers, which is awkward for the agent to recover from. The fix is to make our input schemas tolerant on both shapes.
Changes
hyperdx/server/lib/coerce.ts: tiny helpersarr(schema)—z.preprocessthat JSON-parses string inputs that look like arrays/objects, then defers to the inner schemanum()—z.coerce.number()hyperdx.ts,dashboards.ts,alerts.ts) and shared schemas (types.ts)vtex/server/tools/custom/reorder-collection.tscoerce.test.ts(12 tests) covering passthrough, JSON parsing, malformed fallthrough, optional/default, nested object arrays, numeric coercion, and end-to-endqueryChartDataInputSchemaparsing of stringifiedseries+ nested stringifiedgroupByTest plan
bun test(47 pass, 0 fail acrosshyperdx)bun run build(compiles cleanly)queryChartDataInputSchema.parse({ series: '[{...}]', granularity: '5 minute' })succeeds{ groupBy: '["service","level"]', limit: "100" }parses to{ groupBy: ["service","level"], limit: 100 }🤖 Generated with Claude Code
Summary by cubic
Allows HyperDX tools to accept JSON-encoded arrays/objects and numeric strings from some MCP transports, fixing validation errors on inputs like
series,groupBy, andlimit. Improves compatibility with real MCP sessions without changing outputs.arr()andnum()coercion helpers inhyperdx/server/lib/coerce.tsto parse JSON-looking strings and numeric strings before validating withzod.hyperdx.ts,dashboards.ts,alerts.ts, and shared schemas intypes.ts. Output schemas unchanged.coerce.test.tswith unit tests and an end-to-end parse test forqueryChartDataInputSchema.Written for commit 4a22a81. Summary will update on new commits.