Skip to content

feat: add tusk drift query CLI commands for span querying#214

Merged
sohankshirsagar merged 4 commits intomainfrom
sohan/mcp-cli-commands
Apr 1, 2026
Merged

feat: add tusk drift query CLI commands for span querying#214
sohankshirsagar merged 4 commits intomainfrom
sohan/mcp-cli-commands

Conversation

@sohankshirsagar
Copy link
Copy Markdown
Contributor

@sohankshirsagar sohankshirsagar commented Mar 31, 2026

Summary

Adds 6 new CLI commands under tusk drift query that expose the same span querying capabilities as the https://github.com/Use-Tusk/drift-mcp, allowing users to search, analyze, and debug recorded API traffic directly from
the CLI. This enables a skill-driven workflow where users can install the skill (will be available on https://github.com/Use-Tusk/tusk-skills shortly after this pr is merged) instead of configuring an MCP server.

Changes

  • internal/driftquery/types.go — Go structs for filter types (StringFilter, NumberFilter, BooleanFilter, SpanWhereClause, JsonbFilter) and 6 tool input types, matching the MCP's types.ts
    with camelCase JSON tags
  • internal/api/drift_query.go — 6 new TuskClient methods (QueryDriftSpans, GetDriftSchema, ListDriftDistinctValues, AggregateDriftSpans, GetDriftTrace, GetDriftSpansByIds)
    using makeJSONRequestWithBody, returning json.RawMessage to avoid maintaining response structs
  • cmd/drift_query.go — Parent tusk drift query command + shared helpers: setupDriftQueryCloud, resolveQueryServiceID (flag > TUSK_DRIFT_SERVICE_ID env > config),
    buildWhereFromFlags, JSON parsing helpers, splitComma
  • cmd/drift_query_spans.go — Search spans with convenience flags (--name, --package-name, --trace-id, --min-duration, etc.) and advanced JSON flags (--where, --jsonb-filters)
  • cmd/drift_query_distinct.go — List unique field values (--field required)
  • cmd/drift_query_aggregate.go — Aggregate metrics (--metrics required, --group-by, --time-bucket)
  • cmd/drift_query_trace.go — Get full trace tree by trace ID (positional arg)
  • cmd/drift_query_schema.go — Get schema info and example payloads
  • cmd/drift_query_spans_by_ids.go — Fetch spans by ID (--ids required)

Design decisions

  • json.RawMessage for responses — Commands print backend JSON directly via printJSON rather than parsing into typed Go structs. This avoids duplicated maintenance when backend response
    shapes change.
  • Service ID resolution adds TUSK_DRIFT_SERVICE_ID env var support (new to CLI, matches MCP behavior) alongside --service-id flag and .tusk/config.yaml.
  • Convenience flags + raw JSON — Simple filters use --name, --package-name etc. Complex nested filters (AND/OR, JSONB paths) use --where and --jsonb-filters as JSON strings, which is fine since the primary consumer is an AI agent via the skill.

Tusk Drift enables you to record and replay traces from real traffic. These recorded traces make up
an API test suite, which you can run locally or in CI/CD pipelines.

## Concepts overview

A **trace** represents the full path of an inbound request in your application.

A **span** represents a unit of work or operation in a trace. We capture all outbound requests made from your service (e.g., database calls, HTTP requests) in the path of a trace.

Further reading: <https://opentelemetry.io/docs/concepts/signals/traces/>

## Setup

Setup involves creating a `.tusk/config.yaml` file in the directory of the service you wish to test.
This lets Tusk know how to start your service and wait for it to be ready during replay mode.

You can run `tusk drift setup` to start an AI agent to automatically set up your service for Tusk Drift or `tusk drift init` to start a configuration wizard.

## Test workflow

1. Instrument your app with the Tusk SDK.
1. Once your app is up and ready, send traffic to it.
    - Tusk will record traces in `.tusk/traces`.
    - Shut down your app when you're done.
1. Run `tusk drift run` to run these traces locally.
1. Set up a workflow to run tests in your CI/CD pipeline.

Usage:
  tusk drift [command]

Available Commands:
  init        Set up a new service with Tusk
  init-cloud  Initialize Tusk Drift Cloud for this service
  list        List available traces for replay
  run         Run API tests
  setup       AI-powered setup wizard for Tusk Drift

Flags:
      --config string   config file (default is .tusk/config.yaml)
  -h, --help            help for drift

Global Flags:
      --debug     debug output
  -v, --version   show version and exit

Use "tusk drift [command] --help" for more information about a command. CLI commands for span querying
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="cmd/drift_query_aggregate.go">

<violation number="1" location="cmd/drift_query_aggregate.go:40">
P2: `--limit` is documented as 1-100 but is never validated before sending the API request.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@sohankshirsagar sohankshirsagar added the Tusk - Pause For Current PR Pause Tusk for future commits in the current PR label Mar 31, 2026
@sohankshirsagar sohankshirsagar merged commit 612f120 into main Apr 1, 2026
23 of 29 checks passed
@sohankshirsagar sohankshirsagar deleted the sohan/mcp-cli-commands branch April 1, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tusk - Pause For Current PR Pause Tusk for future commits in the current PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants