feat(mcp): insights_view MCP App — time-series explorer (KLA-402)#19
Merged
Conversation
eba971a to
fc1e1c6
Compare
f44ca08 to
a840dc4
Compare
5 tasks
fc1e1c6 to
b6ef360
Compare
6fdbc29 to
e8bdee1
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit e8bdee1. Configure here.
Adds the Directory Insights time-series dashboard as an interactive MCP App. Parameters mirror `jc insights query` (service, event_type, last, start, end, user); the rendered app shows a stacked bar chart by time bucket with a top-users ranking alongside. Server side (apps_insights.go): - insightsViewArgs: typed inputs so the JSON schema auto-derives; LLMs see the same shape they already know from the CLI - fetchInsightsViewData: CountEvents for true total, QueryEvents capped at 10k for the sample, aggregate into bins keyed by bucket start (bucket size auto-chosen from window: 5m/1h/6h/1d), tally top 10 users, keep 20-event preview - resolveInsightsWindow: parses last/start/end, defaults to 24h, validates start < end; uses local duration parser anchored on our nowFunc so tests stay deterministic (api.ParseTimeRange uses its own wall-clock) - bucketSizeFor: 5m / 1h / 6h / 1d depending on window length addToolWithMetaTyped[In any]: generic variant of addToolWithMeta so apps that take parameters (insights_view now, user_view / device_view next) get an auto-derived JSON input schema from the typed arg struct. Still wires rate limiting, audit logging, and Meta with _meta.ui.resourceUri. Client side (apps_html/insights.html): - Filter form (service, last, event_type, user) with Apply + Refresh buttons - Proactive fetch on load, re-fetches on filter submit via jcApp.callTool - Per-bucket stacked bar chart with event-type color legend; top-users list - Warning banner when the window is large enough that we sampled vs fetched all events - Uses the shared jcApp scaffolding from common.js; no inline postMessage re-implementation. Purely content + rendering. Tests (apps_insights_test.go): - TestBucketSizeFor — auto-picked bucket size - TestResolveInsightsWindow — defaults, Last override, start/end ordering - TestFetchInsightsViewData_Aggregates — fixture of 5 events, verifies total, event type set, top-user ranking, bin count, sum of bin counts - TestFetchInsightsViewData_EventTypeFilter — filter narrows correctly - TestInsightsView_HasUIMetadata — tool exposes _meta.ui.resourceUri - TestInsightsResource_ServesHTMLWithInjection — ui:// resource has common.js injected and the marker stripped Stacks on juergen/mcp-apps-refactor (PR #18) since it depends on addToolWithMetaTyped and the renderAppHTML helper introduced there. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b6ef360 to
a5cddd4
Compare
Medium: insights.html onToolResult race
The initialized flag was set to true BEFORE the try-catch in
onToolResult. If parseToolResult threw or returned null, the flag was
already set and the setTimeout fallback (which uses the more robust
load() path) never fired — the UI locked on the loading spinner with
no recovery. Now the flag only flips after a successful render.
Low: consolidate addToolWithMeta to delegate
addToolWithMeta and addToolWithMetaTyped had ~25 lines of identical
rate-limiting + audit-logging + tool-filtering wrapper. Any future fix
would need to land in both places. Collapsed to a 1-line shim that
calls the typed variant with struct{}, so the wrapper exists once.
Call sites unchanged (s.addToolWithMeta still works).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
e8bdee1 to
daf3c88
Compare
Collaborator
Author
|
Addressed both Bugbot findings on this PR in daf3c88:
|
jrennichjc
approved these changes
Apr 28, 2026
jrennichjc
previously approved these changes
Apr 28, 2026
jrennichjc
approved these changes
Apr 28, 2026
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
UX
Interactive filter form (service / last / event_type / user), stacked bars by time bucket with legend, top-10-users list alongside. Refresh re-runs the query.
Scope
New:
Modified:
Key design choices
Test plan
🤖 Generated with Claude Code
Note
Medium Risk
Adds a new MCP App tool that queries and aggregates Directory Insights events (including time-window parsing and sampling limits), which could affect performance/behavior of Insights calls. Also changes the tool-registration helper to support generic typed inputs, potentially impacting how future tools’ schemas/handlers are derived.
Overview
Introduces a new MCP App,
insights_view, that serves aui://jc/insightsHTML dashboard and a parameterized tool to fetch/aggregate Directory Insights events into time buckets with top-user rankings, preview events, and truncation warnings (10k event cap).Refactors app tool registration by adding generic
addToolWithMetaTyped[In](auto-derived JSON input schema) and keepingaddToolWithMetaas a no-args wrapper;registerAppToolsnow registers this typed-input app explicitly. Tests are added/updated to cover window parsing, bucketing/aggregation, UI metadata/resource injection, and the expected tool list/count.Reviewed by Cursor Bugbot for commit daf3c88. Bugbot is set up for automated code reviews on this repo. Configure here.