External interfaces and automation
HyperDX provides team-scoped ways for people, services, AI clients, and infrastructure tools to use observability data and manage product resources. The versioned API and its OpenAPI contract expose stable HTTP resources, MCP turns common investigations into guided tools, and the CLI supports repeatable terminal work.
Public API surface
The public API is a bearer-key HTTP boundary for querying telemetry and managing team resources. Clients discover sources and connections before they query data or write dashboards, alerts, saved searches, webhooks, or source definitions. See API services and background tasks for the server-side request flow.
Resource interface
The /api/v2 interface returns public resource shapes rather than raw stored records. It covers data access, observability objects, team resources, and notification targets.
- Data access: sources, raw search, and chart series.
- Observability objects: dashboards, saved searches, and alerts.
- Team resources: ClickHouse or Prometheus connections and team membership.
- Notification resources: webhooks used by alerts.
Sources define the telemetry shape that later queries and dashboard tiles use. They support logs, traces, metrics, sessions, and PromQL-backed data. The source endpoints return team-scoped, schema-shaped objects with public string IDs and short granularity values such as 5m and 1h. They keep compatible legacy source records readable while excluding records that cannot satisfy the public schema.
Raw search returns bounded log or trace rows for a source. The caller supplies the time range, filter language, selected columns, ordering, and paging values. The API rejects unsafe select expressions and clients should use a time-based cursor instead of large offsets for deep pages.
Dashboards and alerts expose the product’s saved observability model. Dashboard resources can contain builder, SQL, and PromQL charts, filters, variables, formulas, grouped tabs, and links. Alert resources can monitor saved searches, dashboard tiles, or inline charts. Dashboard writes validate team ownership and relationships among sources, connections, links, filters, formulas, and layout items before persistence.
Webhooks are first-class resources. Clients can validate a proposed destination and template without saving it, then create, replace, list, or delete the destination. Reads omit write-only credentials, and deletion is blocked while an alert still uses the webhook.
References: packages/…/openapi.json• L14-42 packages/…/openapi.json• L2313-2464 packages/…/openapi.json• L3339-3738 packages/…/openapi.json• L6102-6180 packages/…/sources.ts• L24-122 packages/…/sources.ts• L896-1187 packages/…/sources.int.test.ts• L427-537 packages/…/sources.int.test.ts• L588-671 packages/…/dashboards.ts• L24-80 packages/…/dashboards.ts• L540-729
Query and management flow
An automation client normally follows discovery before use. This keeps source IDs, schemas, query paths, and team-owned references explicit instead of relying on guessed table names or fields.
flowchart LR
Client[Automation client] --> Auth[Bearer API key]
Auth --> Discover[Discover sources and connections]
Discover --> Schema[Read source shape]
Schema --> Query[Search rows or query chart series]
Discover --> Manage[Manage dashboards alerts and saved searches]
Manage --> Validate[Validate resource before save]
Manage --> Notify[Attach webhook destination]
REST source, dashboard, and alert updates are whole-resource writes. A client that changes one part should first read the current object and preserve the fields it does not change. Source writes also require a valid team connection, and their public short granularity values are converted before validation. Dashboard validation also checks that a tile’s source and connection match and that links and layout references remain valid. The MCP dashboard surface provides a narrower patch path for a single dashboard property or tile.
References: packages/…/openapi.json• L7882-7915 packages/…/openapi.json• L7153-7988 packages/…/sources.ts• L1046-1160 packages/…/dashboards.ts• L1504-1599 packages/…/saveDashboard.ts• L43-55 packages/…/saveDashboard.ts• L262-375
OpenAPI contract
The OpenAPI document is the machine-readable contract for the versioned API. It defines bearer authentication, operation paths, resource schemas, limits, enums, chart variants, paging rules, validation responses, and the treatment of write-only fields.
Contract publication
The checked-in packages/…/openapi.json artifact supports client generation and review. The running API also publishes interactive and JSON documentation at /api/v2/docs and api/…/docs.json in enabled non-production deployments. Route annotations and the generated artifact must stay aligned when a public field, enum, or response shape changes.
The contract represents builder, SQL, and PromQL chart variants through explicit discriminators. It also describes source kinds, dashboard filters and containers, alert forms, raw search bounds, webhook preflight validation, and Prometheus-compatible connections. PromQL remains a preview capability and requires deployment support before its sources and tiles can be used.
References: packages/…/openapi.json• L1-51 packages/…/openapi.json• L780-834 packages/…/openapi.json• L2862-2939 packages/…/openapi.json• L3692-3738 packages/…/openapi.json• L5678-5767 packages/…/openapi.json• L7882-7915 packages/…/openapi.json• L9058-9072
MCP integration
The Model Context Protocol (MCP) server gives AI clients a structured, team-scoped interface to HyperDX. It uses Streamable HTTP at /api/mcp and the same personal API key model as the external API, so each request resolves to a user and team before tools run.
Tool-based observability access
MCP exposes named tools for source discovery, query work, analysis, and resource management. Tool annotations state whether a tool is read-only, destructive, repeatable, and limited to the current team. This lets an AI client choose safer actions and understand when a create or update may not be idempotent.
Source discovery is the first step. clickstack_list_sources returns a lightweight catalog of sources and connections, including a best-effort preview of recently seen metric names. clickstack_describe_source then provides columns, map keys, sampled values, metric tables, and query guidance. A result can be marked partial when time limits stop value sampling, so the client knows when to verify a field with a query.
The query tools prefer structured builders over raw SQL. The builders cover service health, tables, time series, row search, event patterns, event deltas, emerging signals, and trace investigation. clickstack_sql is the read-only fallback for joins, subqueries, CTEs, window functions, unregistered tables, and summary metric tables.
References: packages/…/index.ts• L1-21 packages/…/builderCatalog.ts• L7-32 packages/…/listSources.ts• L200-224 packages/…/listSources.ts• L327-349 packages/…/describeSource.ts• L477-548 packages/…/annotations.ts• L7-44
Service health analysis
clickstack_service_health provides a bounded triage report for services on a trace source. It compares throughput, error rate, and p50, p95, and p99 latency across a selected window and a comparison window, then ranks services from worst to best.
The report distinguishes a health status from context. Critical and degraded statuses require threshold crossings, while healthy, new-service, traffic-spike, low-volume, and new-error signals help explain the result without treating normal variance as an incident. The tool also reports new operations, top error groups, first and last sightings, and whether an error is ongoing, spread across the window, or a short burst.
The default comparison is the same-length window from the previous day. Clients can choose the previous period, the previous week, or no comparison. If the requested comparison has no data, the tool falls back to the previous period and then to absolute thresholds only. Coverage notes mark cases where service, error-group, or operation limits prevent a complete check.
flowchart TD
Source[Trace source] --> Window[Current time window]
Window --> Compare[Comparison window]
Window --> Stats[Throughput errors and latency]
Compare --> Stats
Stats --> Rank[Rank services and assign status]
Rank --> Errors[Compare error groups and operations]
Errors --> Report[Health report with findings and coverage notes]
References: packages/…/index.ts• L29-58 packages/…/schema.ts• L10-99 packages/…/comparison.ts• L20-63 packages/…/rank.ts• L79-177 packages/…/report.ts• L144-167 packages/…/summary.ts• L61-148 packages/…/serviceHealthTool.int.test.ts• L158-180 packages/…/serviceHealthComparison.test.ts• L65-110 packages/…/serviceHealthRank.test.ts• L30-126
Dashboard and source workflows
MCP dashboard tools support creation, search, validation, tile queries, targeted changes, and full replacement. A save response tells the client to query every saved tile before relying on the dashboard, because a valid chart shape can still produce a bad query or no data. A targeted patch is safer when only one tile or property must change.
PromQL tiles remain on the dashboard when MCP updates a dashboard, but MCP hides them from reads and save responses because the MCP tile-query path cannot validate them. This prevents an AI client from deleting a tile it could not see, while keeping PromQL work on the external API or web path.
Source writes use a flat MCP shape that can round-trip through clickstack_describe_source and clickstack_save_source. The source catalog gives clients IDs and connection relationships; the detailed description gives the schema and sampled values needed to build valid filters and queries.
References: packages/…/saveDashboard.ts• L43-69 packages/…/saveDashboard.ts• L175-229 packages/…/saveDashboard.ts• L315-407 packages/…/promqlTiles.int.test.ts• L9-88 packages/…/schemas.ts• L153-190 packages/…/schemas.ts• L454-541 packages/…/listSources.ts• L207-224 packages/…/describeSource.ts• L551-578
MCP request boundary
MCP uses stateless POST requests with a scoped tool context. The endpoint applies its own rate limit, records client identity for tracing, and closes the transport after each request. Query work uses bounded, read-only ClickHouse execution, and results can include trim or coverage hints when limits affect what the client receives.
References: packages/…/app.ts• L14-82 packages/…/auth.ts• L86-112 packages/…/tracing.ts• L17-139 packages/…/errors.ts• L5-62 packages/…/helpers.ts• L83-97
Webhook safeguards
Webhooks connect alert delivery to external systems. HyperDX validates the destination and template before delivery and keeps credentials out of normal reads, with the external API and MCP sharing the same safety rules. See Alerting and notifications for the alert lifecycle.
Destination validation
Webhook destinations must use supported HTTP forms. HyperDX blocks local, private, link-local, reserved, and service-owned addresses unless an explicit hostname allowlist permits them. Slack destinations use Slack hosts and fixed payload rules, while generic and incident.io destinations support validated templates.
The preflight endpoint checks the body without saving it. It returns field-level errors for invalid schema, service, URL, or template input, and returns a normalized readable form only when the input is valid. Supported Handlebars helpers must compile before a generic or incident.io webhook can be written.
References: packages/…/validators.ts• L17-166 packages/…/webhooks.ts• L439-562 packages/…/openapi.json• L9058-9072
Credential protection
Generic and incident.io destinations can use custom headers, query parameters, and body templates. These values are write-only. An update preserves omitted secrets only when the destination stays the same; changing the service or URL creates a new credential boundary and clears omitted secrets.
Webhook writes detect concurrent destination changes and require the caller to retry from current state. The API also blocks deletion while an alert references the destination. These rules stop an automation client from reusing masked credentials against a new endpoint or leaving an alert without a notification target.
References: packages/…/webhooks.ts• L367-437 packages/…/webhooks.ts• L647-842 packages/…/saveWebhook.ts• L54-80 packages/…/saveWebhook.ts• L159-181
Infrastructure as code
HyperDX supports Terraform as an import path for bringing eligible team resources under infrastructure management. The import manifest identifies resources that a provider can read and write safely, while marking capped, unsupported, or reference-only cases instead of implying complete export.
Resource eligibility
The team settings flow reads /api/iac/import-manifest and reports IDs and names for dashboards, alerts, saved searches, sources, connections, and webhooks. Shared eligibility rules keep bulk and per-resource output consistent.
Some resources remain outside the provider path. Saved-search alerts qualify while tile alerts do not. PromQL sources and provisioned dashboards are withheld from the ClickStack provider path. A connection becomes a managed resource only when the server marks it self-managed; other connections remain ID-only references.
References: packages/…/iac.ts• L88-136 packages/…/iac.ts• L145-232 packages/…/iacEligibility.ts• L10-30 packages/…/iacEligibility.ts• L113-141
Import workflow
Terraform output is intended for review before it changes HyperDX. Resource addresses use immutable resource IDs, while import IDs include the team and resource IDs, so a rename does not become a destroy-and-create change.
The normal sequence is:
- Add the generated
import {}block to a Terraform module. - Set
CLICKSTACK_API_KEYto a personal API access key. - Run
terraform initwith Terraform 1.5 or newer and the supported ClickStack provider version. - Run
terraform plan -generate-config-out=generated.tf. - Review the generated configuration before applying it.
Provider resources are alpha. A later export is not additive, and a whole-dashboard write can remove fields that the provider does not model. Dashboard and webhook validation endpoints can check plan-time bodies without saving them.
References: packages/…/dashboards.ts• L2474-2593 packages/…/webhooks.ts• L439-562 packages/…/iac.ts• L28-42 packages/…/iac.ts• L76-139 packages/…/iac.ts• L204-297 packages/…/useTerraformSnippets.ts• L15-68
Terminal automation
The @hyperdx/cli package publishes the hdx command for interactive investigation and scripts. It works with Cloud and self-hosted instances through the authenticated HyperDX path, so scripts can use team-scoped queries without direct ClickHouse credentials. It also supports repeatable dashboard and saved-search management for workflows that need to move or create product resources from a terminal.
Investigation commands
The CLI supports both a terminal UI and non-interactive commands:
hdx tuisearches and live-tails logs or traces and opens row, trace, and waterfall details.hdx sources,hdx connections,hdx dashboards, andhdx saved-searchesdiscover objects for later commands.hdx dashboards list|export|create|importandhdx saved-searches list|createsupport resource authoring and transfer. Definitions are checked locally before they are sent, and import/export is designed to round-trip dashboard definitions.hdx chartrenders saved or ad-hoc charts in terminal output.hdx queryruns raw ClickHouse SQL through the HyperDX proxy and writes NDJSON by default.hdx team list|current|useselects the team for a multi-team user.hdx upload-sourcemapssupports build and release workflows.
Saved dashboard chart output resolves each tile against its source, time range, granularity, and filters before querying it. The terminal supports common line, bar, number, table, pie, and Markdown views. It reports missing sources, missing connections, and unsupported heatmap, search, event-pattern, and PromQL tiles as explicit per-tile results instead of sending them down the wrong query path.
References: packages/…/package.json• L1-40 packages/…/CHANGELOG.md• L3-15 packages/…/README.md• L6-12 packages/…/README.md• L40-77 packages/…/tileConfig.ts• L90-359 packages/…/tileRender.ts• L47-180
Session and team scope
hdx auth login signs in to an app URL and stores a session at ~/…/session.json with restricted permissions. Later commands reuse the saved server, cookies, and active team unless the app URL or team changes.
The CLI sends ClickHouse queries through the authenticated /clickhouse-proxy endpoint. Discovery commands support JSON output, query commands expose stable success and failure exit behavior, and piped chart output removes terminal colors.
References: packages/…/cli.tsx• L194-238 packages/…/client.ts• L40-71 packages/…/client.ts• L106-132 packages/…/client.ts• L266-277 packages/…/client.ts• L293-400 packages/…/README.md• L190-215
Change checklist
When these files or sections are changed, remember to consider these:
- Keep route annotations, packages/…/openapi.json, and external schemas aligned when a public field, enum, chart discriminator, source kind, or response shape changes.
- When changing dashboard conversion or validation, keep REST and MCP round trips safe for filters, containers, tabs, links, formulas, heatmaps, and PromQL tiles. A hidden PromQL tile must not be removed by an MCP save.
- When changing source discovery, keep source IDs, connection IDs, metric table kinds, metric previews, sampled schema values, and round-trip source configuration consistent.
- When changing source API schemas or conversion, keep team scoping, source-kind fields, legacy read defaults, short granularity values, connection checks, and PromQL deployment gating aligned.
- When changing MCP query guidance, update the shared builder catalog and preserve the rule that raw SQL is a fallback for cases builders cannot express.
- When changing service health thresholds or comparisons, keep the status rules, fallback notes, coverage notes, error novelty, operation discovery, and follow-up guidance aligned.
- When changing webhook validation or updates, preserve URL safety, template compilation, write-only secret handling, same-destination secret retention, concurrency checks, and alert-reference deletion guards across API and MCP.
- When changing Terraform eligibility or generated snippets, keep manifest eligibility, provider import IDs, validation endpoints, and warnings consistent.
- When changing CLI chart handling, keep source resolution, metric table selection, unsupported tile reporting, proxy use, and terminal rendering aligned with the dashboard contract.
- When changing CLI dashboard or saved-search authoring, keep local definition validation, import/export round trips, generated tile IDs, and the external API paths aligned.
- Preserve user, team, and active-team context on every external API, MCP, Terraform, and CLI operation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A client uses a stale or guessed source ID | Query or source operation fails or targets the wrong data shape | List sources first, then describe the selected source before building a query. |
| A source update sends only the changed fields | The replace operation rejects the request or loses omitted source configuration | Read the current source and send the complete source shape. |
| A REST dashboard or alert write sends only one changed field | Omitted configuration can be replaced or lost | Read the current resource and resend the complete required shape. |
| An MCP save hides a PromQL tile from the request | A client may assume the tile was deleted | MCP preserves unseen PromQL tiles; use the external API or web path to edit them. |
| A service-health comparison window has no data | Every service could look new or the report could imply a false incident | Fall back to the previous period, then use absolute thresholds only and state the note. |
| Service-health result limits exclude services or error groups | The report is incomplete | Read coverageNote and narrow the services or filter for a full check. |
| A webhook points to a private, reserved, or service-owned host | Alert delivery is rejected | Use a permitted HTTP(S) destination and the configured hostname allowlist. |
| A webhook changes destination without new credentials | Old secrets are cleared or masked secrets are rejected | Re-enter credentials for the new destination. |
| A webhook is deleted while an alert still uses it | The alert loses its notification target | Reassign or remove the alert first. |
| Terraform skips unsupported or capped resources | The generated import set is partial | Read manifest metadata and generated notes before applying. |
| A CLI session selects the wrong team or expires | Commands fail or query another team | Re-authenticate and inspect or switch the active team. |
| A CLI authoring command sends an invalid dashboard or saved-search definition | The resource is not created or imported | Rely on local schema validation and fix the definition before sending it. |
| A CLI or MCP client sends a PromQL or unsupported tile through ClickHouse | The tile cannot be queried | Use the Prometheus-backed or web path and honor explicit unsupported results. |
Key files
| File | Why to read it |
|---|---|
| packages/…/openapi.json | Defines the machine-readable public API contract and chart, source, search, and webhook schemas. |
| packages/…/dashboards.ts | Defines dashboard API operations and route-level contract annotations. |
| packages/…/dashboards.ts | Defines the public dashboard shape and relationship checks that protect round trips. |
| packages/…/sources.ts | Defines source lifecycle behavior and public granularity forms. |
| packages/…/sources.int.test.ts | Shows team scoping, public source normalization, legacy compatibility, and granularity behavior. |
| packages/…/mcpServer.ts | Defines MCP identity, guidance, and registered tool groups. |
| packages/…/builderCatalog.ts | Defines the preferred builder tools and the raw SQL fallback boundary. |
| packages/…/index.ts | Defines the service-health tool and its investigation contract. |
| packages/…/report.ts | Defines service ranking, status output, error novelty, and coverage notes. |
| packages/…/listSources.ts | Defines lightweight source and metric discovery for AI clients. |
| packages/…/describeSource.ts | Defines schema, sampled-value, and metric discovery for query preparation. |
| packages/…/saveDashboard.ts | Defines MCP dashboard save validation and PromQL preservation. |
| packages/…/webhooks.ts | Defines webhook validation, secret protection, and lifecycle guards. |
| packages/…/iac.ts | Defines the Terraform import manifest. |
| packages/…/iacEligibility.ts | Defines which resources can enter provider workflows. |
| packages/…/README.md | Gives the command-level view of terminal automation. |
| packages/…/package.json | Defines the published hdx command and package entry points. |
| packages/…/CHANGELOG.md | Records dashboard and saved-search authoring support in the current CLI release. |
| packages/…/client.ts | Defines CLI session, team scope, API calls, and query proxy use. |
| packages/…/tileConfig.ts | Resolves saved tiles into queryable terminal configurations. |
| packages/…/tileRender.ts | Maps results to terminal views and explicit unsupported states. |