Skip to content

feat(traffic): MCP toolkit + UI dashboard (Phase 2 slices 3 + 4)#435

Merged
arberx merged 1 commit intoarberx/post-pr429-next-stagefrom
arberx/stacked-pr-431
May 8, 2026
Merged

feat(traffic): MCP toolkit + UI dashboard (Phase 2 slices 3 + 4)#435
arberx merged 1 commit intoarberx/post-pr429-next-stagefrom
arberx/stacked-pr-431

Conversation

@arberx
Copy link
Copy Markdown
Member

@arberx arberx commented May 8, 2026

Summary

Stacked on top of #431. Closes API → CLI → MCP → UI parity for the server-side traffic ingestion shipped in slices 1+2.

  • Slice 3 (MCP): 5 traffic ops promoted to included; new traffic toolkit registers canonry_traffic_sources_list, canonry_traffic_source_get, canonry_traffic_events, canonry_traffic_connect_cloud_run, canonry_traffic_sync (loaded on demand). Aero picks them up automatically.
  • Slice 4 (UI): new /traffic and /traffic/$projectName/$sourceId pages with sources table, ScoreGauge tiles, hourly stacked-bar chart (ChartPrimitives), filterable events table, Connect Cloud Run drawer (paste/upload SA JSON, write-only). Sidebar entry uses the Radar icon. UI/CLI parity preserved — every metric on screen is what canonry traffic status/sources/events --format json returns.

Bumps to 4.15.0.

Test plan

  • pnpm typecheck clean across all packages
  • pnpm lint clean (pre-commit hook also runs it)
  • pnpm test — 2142 tests pass; canonry package alone is 563 (was 561, +5 traffic-tool registry/handler cases, +1 toolkit-count assertion, +stdio smoke test)
  • Vite build succeeds (pnpm --filter @ainyc/canonry-web run build)
  • Local dev-server smoke test: /traffic route renders without console errors (gated by dashboard password without auth, expected)
  • End-to-end smoke once a real Cloud Run source exists: connect → sync → events panel populates → sidebar dot reflects status (requires GCP credentials, defer to manual QA)

Definition of done

  • 5 traffic tools registered in MCP, classified included, gated under traffic toolkit
  • mcp-registry and mcp-stdio tests cover the new tools (toolkit listing, eager-mode count, handler dispatch, stdio invocation read+write)
  • Dashboard shows sources, source detail, events, with connect + sync flows
  • Every visible metric maps to an existing API/CLI surface (no UI-only math) — list view fans out to /traffic/sources/:id for parity with canonry traffic status
  • pnpm typecheck && pnpm lint && pnpm test all green
  • Version bumped 4.14.0 → 4.15.0 in both package.json files
  • PR opened with --base arberx/post-pr429-next-stage

Explicitly NOT in this PR

  • OAuth-mode Cloud Run sync (still throws on oauth authMode — separate slice)
  • Doctor checks (cloud-run.auth.*) — separate slice
  • Intelligence correlations feeding crawler/AI-referral signals — separate slice

🤖 Generated with Claude Code

Adds the MCP toolkit and the dashboard surface for the server-side traffic
ingestion shipped in slices 1+2, closing API → CLI → MCP → UI parity.

Slice 3 — MCP toolkit
- Promote 5 traffic ops to `included` in openapi-classification.ts
- Add 5 tools to tool-registry.ts (sources_list, source_get, events,
  connect_cloud_run, sync), tagged with the new `traffic` tier
- Add `traffic` toolkit to toolkits.ts so it loads on demand alongside
  monitoring/setup/gsc/ga/agent
- Wire input schemas to packages/contracts Zod schemas
- Tests cover registry tier counts, eager-mode count, handler dispatch,
  plus a stdio smoke test that loads the toolkit and calls one read
  (sources_list) + one write (sync)
- Aero auto-picks them up via mcp-to-agent-tool.ts (no AERO_EXCLUDED entry)

Slice 4 — UI dashboard
- New /traffic top-level page: project picker + sources table with
  status, last sync, 24h crawler / AI-referral hits, sample count, plus
  a Connect-Cloud-Run drawer (paste-or-upload SA JSON, write-only key)
- New /traffic/$projectName/$sourceId detail page: ScoreGauge tiles,
  ToneBadge status, latest run summary, hourly stacked-bar chart via
  ChartPrimitives (Recharts only — no direct import), filterable events
  table by kind / window
- React Query hooks in queries/server-traffic.ts; toneFromTrafficSourceStatus
  helper centralizes the status → MetricTone map
- Sidebar entry (Radar icon), mobile nav entry, breadcrumb mapping
- traffic-sync run completion now invalidates the new server-traffic
  query namespace alongside the existing GA traffic keys
- UI/CLI parity: every metric on screen comes from the same DTOs returned
  by `canonry traffic status/sources/events --format json`

Bumps to 4.15.0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@arberx arberx merged commit a7b3737 into arberx/post-pr429-next-stage May 8, 2026
@arberx arberx deleted the arberx/stacked-pr-431 branch May 8, 2026 18:46
arberx added a commit that referenced this pull request May 9, 2026
Adds the MCP toolkit and the dashboard surface for the server-side traffic
ingestion shipped in slices 1+2, closing API → CLI → MCP → UI parity.

Slice 3 — MCP toolkit
- Promote 5 traffic ops to `included` in openapi-classification.ts
- Add 5 tools to tool-registry.ts (sources_list, source_get, events,
  connect_cloud_run, sync), tagged with the new `traffic` tier
- Add `traffic` toolkit to toolkits.ts so it loads on demand alongside
  monitoring/setup/gsc/ga/agent
- Wire input schemas to packages/contracts Zod schemas
- Tests cover registry tier counts, eager-mode count, handler dispatch,
  plus a stdio smoke test that loads the toolkit and calls one read
  (sources_list) + one write (sync)
- Aero auto-picks them up via mcp-to-agent-tool.ts (no AERO_EXCLUDED entry)

Slice 4 — UI dashboard
- New /traffic top-level page: project picker + sources table with
  status, last sync, 24h crawler / AI-referral hits, sample count, plus
  a Connect-Cloud-Run drawer (paste-or-upload SA JSON, write-only key)
- New /traffic/$projectName/$sourceId detail page: ScoreGauge tiles,
  ToneBadge status, latest run summary, hourly stacked-bar chart via
  ChartPrimitives (Recharts only — no direct import), filterable events
  table by kind / window
- React Query hooks in queries/server-traffic.ts; toneFromTrafficSourceStatus
  helper centralizes the status → MetricTone map
- Sidebar entry (Radar icon), mobile nav entry, breadcrumb mapping
- traffic-sync run completion now invalidates the new server-traffic
  query namespace alongside the existing GA traffic keys
- UI/CLI parity: every metric on screen comes from the same DTOs returned
  by `canonry traffic status/sources/events --format json`

Bumps to 4.15.0.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
arberx added a commit that referenced this pull request May 9, 2026
…ice 2) (#431)

* feat(traffic): read endpoints + CLI status/sources/events (Phase 2 slice 2)

Adds the read surface that slice 1 deferred so an agent can see what
syncs ingested without a DB query. Three new GET routes (`/traffic/sources`,
`/traffic/sources/:id` with last-24h totals + latest run, `/traffic/events`
with kind/since/until/limit/sourceId filters), three matching CLI commands
(`traffic status`, `traffic sources`, `traffic events`) all with --format
json, and ApiClient methods + OpenAPI entries.

Folds in the two correctness fixes flagged in the slice 1 review:
upstream and auth-token failures now throw providerError() (502) so CLI
exits 2 (system error, retryable) rather than 1 (user error), and the
failed-run + source updates share a transaction so a mid-handler crash
can't leave the run failed but the source still "connected".

Events totals reflect the full window even when limit truncates the rows
array, so a paginated query never undercounts. MCP toolkit and UI remain
deferred to slice 3+.

* fix(traffic): validate --since-minutes / --limit before parsing crashes the CLI

Non-numeric values (e.g. `--since-minutes abc`) flowed through `parseInt` as
NaN and crashed the CLI with `RangeError: Invalid time value` at
`new Date(NaN).toISOString()`. `--limit abc` round-tripped to the API as
`limit=NaN` and bounced back as a 400 instead of being caught locally.
Switch both options to the existing `parseIntegerOption` helper so bad input
fails fast with a usage error.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(traffic): MCP toolkit + UI dashboard (Phase 2 slices 3 + 4) (#435)

Adds the MCP toolkit and the dashboard surface for the server-side traffic
ingestion shipped in slices 1+2, closing API → CLI → MCP → UI parity.

Slice 3 — MCP toolkit
- Promote 5 traffic ops to `included` in openapi-classification.ts
- Add 5 tools to tool-registry.ts (sources_list, source_get, events,
  connect_cloud_run, sync), tagged with the new `traffic` tier
- Add `traffic` toolkit to toolkits.ts so it loads on demand alongside
  monitoring/setup/gsc/ga/agent
- Wire input schemas to packages/contracts Zod schemas
- Tests cover registry tier counts, eager-mode count, handler dispatch,
  plus a stdio smoke test that loads the toolkit and calls one read
  (sources_list) + one write (sync)
- Aero auto-picks them up via mcp-to-agent-tool.ts (no AERO_EXCLUDED entry)

Slice 4 — UI dashboard
- New /traffic top-level page: project picker + sources table with
  status, last sync, 24h crawler / AI-referral hits, sample count, plus
  a Connect-Cloud-Run drawer (paste-or-upload SA JSON, write-only key)
- New /traffic/$projectName/$sourceId detail page: ScoreGauge tiles,
  ToneBadge status, latest run summary, hourly stacked-bar chart via
  ChartPrimitives (Recharts only — no direct import), filterable events
  table by kind / window
- React Query hooks in queries/server-traffic.ts; toneFromTrafficSourceStatus
  helper centralizes the status → MetricTone map
- Sidebar entry (Radar icon), mobile nav entry, breadcrumb mapping
- traffic-sync run completion now invalidates the new server-traffic
  query namespace alongside the existing GA traffic keys
- UI/CLI parity: every metric on screen comes from the same DTOs returned
  by `canonry traffic status/sources/events --format json`

Bumps to 4.15.0.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>

* fix(traffic): source-scoped latestRun + composite /traffic/status endpoint

Three corrections from review feedback against the server-side ingestion plan:

1. `latestRun` on `GET /traffic/sources/:id` was filtered only by project +
   `traffic-sync`, so any second source seeded for the same project would
   surface another source's run. Add nullable `runs.source_id` (migration 51),
   populate it on traffic-sync insert, and require `runs.sourceId === row.id`
   in the detail query. Test exercises the multi-source isolation path
   directly.

2. `canonry traffic status --format json` was a client-side fan-out
   (list-sources + N×detail). That violates the single-call read rule and
   leaves the dashboard re-implementing the same fan-out. Add
   `GET /traffic/status` returning `{ sources: TrafficSourceDetailDto[] }`,
   wire the CLI through `ApiClient.trafficStatus`, and assert the new
   endpoint's per-source entries match `/traffic/sources/:id` byte-for-byte.

3. `latestRun.status` in the contract was `z.string()` instead of the
   canonical run-status enum. Switched to `runStatusSchema` so MCP / agent
   clients get the same machine contract as other run DTOs.

Also surfaces `traffic` in `canonry --help` (under Integrations) and adds it
to the telemetry `SUBCOMMAND_COMMANDS` set so subcommands track properly.

Cursor / `insertId` dedupe in sync and the canonical
`/traffic/{crawlers,referrals,timeline}` surfaces remain deferred to slice 3.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* feat(traffic): expose canonry_traffic_status MCP tool

Slice 3 added the traffic toolkit; the new /traffic/status composite needs a
matching tool so agents can use the single-call read instead of N+1
list+detail. Mirrors the pattern of canonry_traffic_sources_list /
canonry_traffic_source_get and ships under the existing 'traffic' tier.

Test counts updated: total tools 72→73, read tools 48→49, traffic toolkit
5→6, eager stdio listing 74→75.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant