Repository navigation
feat(mcp): add search_timelines and search_logs tools (#1043) - #1091
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements and registers two new Model Context Protocol (MCP) tools: search_timelines and search_logs. It introduces the backend search and filtering logic in pkg/server/workbench to query timelines and logs using CEL expressions, along with Markdown templates to format the tool outputs. Comprehensive unit tests are also added to verify the correctness of the search algorithms and handler implementations. I have no feedback to provide as the implementation is clean and well-tested.
kyasbal
force-pushed
the
push-zmoomsxxzxow
branch
2 times, most recently
from
October 2, 2026 01:14
8b32d5b to
1a59c24
Compare
6 tasks
kyasbal
force-pushed
the
push-zmoomsxxzxow
branch
3 times, most recently
from
October 2, 2026 08:36
f33d4cf to
5fa7b34
Compare
kyasbal
force-pushed
the
push-zmoomsxxzxow
branch
from
October 7, 2026 00:39
5fa7b34 to
d1d769d
Compare
6 tasks
K53
pushed a commit
to K53/khi
that referenced
this pull request
Oct 26, 2026
…investigation (GoogleCloudPlatform#1177) * feat(mcp): add MCP server foundation with HTTP transport and Markdown templates (GoogleCloudPlatform#1038) (GoogleCloudPlatform#1057) * feat(mcp): add MCP server foundation with HTTP transport and Markdown templates (GoogleCloudPlatform#1038) * fix(mcp): use constants.VERSION for MCP server implementation version * feat(mcp): add inspection list and AI summary resources (GoogleCloudPlatform#1039) (GoogleCloudPlatform#1058) * feat(mcp): add inspection list and AI summary resources (GoogleCloudPlatform#1039) * refactor(inspection): rename pkg/core/inspection/ai to pkg/core/inspection/summary * refactor(task,summary): add coretask.WithTitle/WithDescription and fail fast on invalid summary calls * feat(inspection): extend InspectionNameRegistry and runner type metadata for MCP (GoogleCloudPlatform#1040) (GoogleCloudPlatform#1061) * feat(mcp): add inspection-types resource and create/update_inspection_features tools (GoogleCloudPlatform#1040) (GoogleCloudPlatform#1066) * feat(mcp): add dry_run_inspection and run_inspection tools (GoogleCloudPlatform#1040) (GoogleCloudPlatform#1067) * feat(mcp): add dry_run_inspection and run_inspection tools (GoogleCloudPlatform#1040) * refactor(mcp): simplify convertMCPParameters to accept string, bool, and string arrays * refactor(mcp): remove redundant TaskInputKeyTimezoneShiftHours deletion * feat(mcp): add wait_inspection and cancel_inspection tools (GoogleCloudPlatform#1040) (GoogleCloudPlatform#1068) * feat(workbench): share workbenches by inspection ID and evict only on demand (GoogleCloudPlatform#1041) (GoogleCloudPlatform#1072) * feat(workbench): share workbenches by inspection ID and evict only on demand (GoogleCloudPlatform#1041) * fix(workbench): clear removed subscriber reference when unsubscribing * test(workbench): remove redundant workbenchID variable assignments * feat(mcp): add WorkbenchHandler with on-demand loading and WORKBENCH_LOADING response (GoogleCloudPlatform#1041) (GoogleCloudPlatform#1073) * feat(workbench): validate bool return type in CEL queries (GoogleCloudPlatform#1042) (GoogleCloudPlatform#1080) * feat(workbench): add CEL reference documentation generator (GoogleCloudPlatform#1042) (GoogleCloudPlatform#1081) * feat(workbench): add CEL reference documentation generator (GoogleCloudPlatform#1042) * fix(workbench): remove redundant nil checks before protobuf getters in reference.go * refactor(workbench): use text/template for CEL reference generation * feat(workbench): add filter and timeline read layer for MCP (GoogleCloudPlatform#1042) (GoogleCloudPlatform#1082) * feat(workbench): add filter and timeline read layer for MCP (GoogleCloudPlatform#1042) * fix(workbench): escape non-identifier keys in BuildTimelineQuery * feat(mcp): add timelinePath, appliedFilter, and CEL error template helpers (GoogleCloudPlatform#1042) (GoogleCloudPlatform#1083) * feat(mcp): add timelinePath, appliedFilter, and CEL error template helpers (GoogleCloudPlatform#1042) * refactor(mcp): use embedded template for FormatAppliedFilter * feat(workbench): add SearchTimelines tree aggregation for MCP (GoogleCloudPlatform#1043) (GoogleCloudPlatform#1089) * feat(workbench): add SearchTimelines tree aggregation for MCP (GoogleCloudPlatform#1043) * perf(workbench): iterate matched bitmap and cache default timeline types (GoogleCloudPlatform#1043) * fix(workbench): count all severities by style definition in SearchTimelines (GoogleCloudPlatform#1043) Resolve each matched log to its severity definition in the style chunk instead of comparing raw integer severities, and remove the integer Severity fields of cel.EventInfo and cel.RevisionInfo that no longer have readers. * refactor(workbench): build severity and timeline type maps once at workbench load (GoogleCloudPlatform#1043) The style chunk does not change while the workbench is open, so SearchTimelines no longer rebuilds the severity map and the timeline type description map from it on every call. buildStyleMaps builds both maps once when BuildBaseSearchIndex runs at load, and SearchTimelines reuses them through Workbench.styles. * fix(workbench): deduplicate logs across descendants when aggregating severity counts (GoogleCloudPlatform#1043) * feat(workbench): add SearchLogs cross-timeline aggregation for MCP (GoogleCloudPlatform#1043) (GoogleCloudPlatform#1090) * feat(workbench): add SearchLogs cross-timeline aggregation for MCP (GoogleCloudPlatform#1043) * refactor(workbench): use time.Time.Compare in buildSortedTimelineGroups (GoogleCloudPlatform#1043) * fix(workbench): count log severities by style definition in SearchLogs (GoogleCloudPlatform#1043) Resolve each matched log to its severity definition in the style chunk instead of mapping integer severity orders to hardcoded labels, and drop the removed integer Severity field from the test fixtures. * refactor(workbench): reuse the severity map built at workbench load in SearchLogs (GoogleCloudPlatform#1043) SearchLogs no longer rebuilds the severity map from the style chunk on every call. It looks up severity definitions in the map that buildStyleMaps builds once when the workbench loads. * fix(workbench): sample logs evenly across time range in SearchLogs (GoogleCloudPlatform#1043) * feat(mcp): add search_timelines and search_logs tools (GoogleCloudPlatform#1043) (GoogleCloudPlatform#1091) * feat(mcp): add search_timelines and search_logs tools (GoogleCloudPlatform#1043) * fix(mcp): render all severity counts in search tools (GoogleCloudPlatform#1043) * fix(mcp): replace broken CEL resource references in tool descriptions (GoogleCloudPlatform#1043) * chore: merge main into epic/mcp (GoogleCloudPlatform#1124) fix(workbench): treat missing CEL path levels as empty strings instead of aborting the timeline filter (GoogleCloudPlatform#1123) * fix(workbench): treat missing CEL path levels as empty strings instead of aborting the timeline filter * fix(workbench): reject non-string keys in CEL path lookups instead of resolving them to empty strings * fix(workbench): make CEL path equality reflexive by unwrapping pathMap operands * test(workbench): cover timelines without a path level that still match the CEL filter * feat(workbench): add body truncation, timeline logs, and log detail read methods (GoogleCloudPlatform#1044) (GoogleCloudPlatform#1128) * feat(workbench): add body truncation, timeline logs, and log detail read methods (GoogleCloudPlatform#1044) * fix(workbench): drop test-only limits, defensive checks, and duplicate truncation marker in timeline log reads (GoogleCloudPlatform#1044) * fix(workbench): drop unreachable linked timeline check in GetLogDetail (GoogleCloudPlatform#1044) * refactor(workbench): derive chunk truncation, embed linked timeline, and share index helpers in timeline log reads (GoogleCloudPlatform#1044) * test(workbench): cover rune-boundary and invalid UTF-8 cuts in the body round-trip test (GoogleCloudPlatform#1044) * feat(workbench): add resource revision, manifest, and diff read methods (GoogleCloudPlatform#1044) (GoogleCloudPlatform#1129) * feat(workbench): add resource revision, manifest, and diff read methods (GoogleCloudPlatform#1044) * fix(workbench): use the fixed body limit and drop defensive checks in resource history reads (GoogleCloudPlatform#1044) * refactor(workbench): adopt shared index helpers and BodyChunk, clarify range names, and extend resource history tests (GoogleCloudPlatform#1044) * refactor(workbench): name the matched revision count matchedCount in GetResourceRevisions (GoogleCloudPlatform#1044) * refactor(workbench): make RevisionSelector unable to hold an invalid state via RevisionAtIndex and RevisionAtTime (GoogleCloudPlatform#1044, GoogleCloudPlatform#1127) * feat(mcp): add get_timeline_logs, get_log, and resource history tools (GoogleCloudPlatform#1044) (GoogleCloudPlatform#1130) * feat(mcp): add get_timeline_logs, get_log, and resource history tools (GoogleCloudPlatform#1044) * fix(mcp): validate byteOffset, drop duplicate truncation marker, and clarify revision window header (GoogleCloudPlatform#1044) * refactor(mcp): adopt BodyChunk and OtherTimeline, validate byteOffset upper bound, split format helpers, and extend template tests (GoogleCloudPlatform#1044) * refactor(mcp): separate other timeline template data, skip unused diff rendering, and neutralize the byteOffset range message (GoogleCloudPlatform#1044) * refactor(mcp): build the manifest revision selector with RevisionAtIndex and RevisionAtTime (GoogleCloudPlatform#1044, GoogleCloudPlatform#1127) * feat(mcp): support file input inspection types via request_file_upload (GoogleCloudPlatform#1047) (GoogleCloudPlatform#1131) * feat(upload): add single-PUT upload URLs for file form fields (GoogleCloudPlatform#1047) * feat(mcp): support file input inspection types via request_file_upload (GoogleCloudPlatform#1047) * fix(uploadurl): record the failure when an upload session cannot start (GoogleCloudPlatform#1047) * refactor(uploadurl): name the upload URL token urlToken to distinguish it from upload tokens (GoogleCloudPlatform#1047) * fix(upload): roll back the upload status when a chunk session cannot start (GoogleCloudPlatform#1047) * feat(uploadurl): accept a single upload per upload URL (GoogleCloudPlatform#1047) * refactor(uploadurl): export StatusProcessing and reuse it for the MCP upload status * refactor(mcp,uploadurl): rename Upload to UploadStatus, uploadURLs to uploadURLIssuer, and targets to targetsByURLToken * refactor(mcp): look up the upload token from the form fields instead of the render model * test(upload,mcp): cover the upload URL route, unexpired URL tokens, recovery after a verification error, and empty groups * refactor(uploadurl): claim an upload URL in one locked step after the size checks * docs(uploadurl): describe StatusProcessing as covering both storing and verifying * refactor(mcp): rename dry run locals and the render model field for clarity * test(uploadurl): assert the first upload status in the single-use URL test * refactor(uploadurl): check the claim error with err != nil before choosing the status * fix(inspection): prevent runner state corruption when withRunContextValues fails in Run (GoogleCloudPlatform#1142) * fix(inspection): prevent runner state corruption when withRunContextValues fails in Run * fix(inspection): close builder file writer when run context setup or execution fails * refactor(inspection): use context.AfterFunc for run context resource cleanup * fix(gcpcommon,mcp): sync dynamic query resource name defaults and record fetched log counts (GoogleCloudPlatform#1120) (GoogleCloudPlatform#1144) * fix(gcpcommon): resolve query resource name defaults before reading and sync form metadata * fix(summary,mcp): record and display fetched log counts per executed query * test(metadata,gcpcommon): add unit tests for UpdateGroupChildTextFieldDefault and query LogCount * fix(mcp): improve dry-run defaults, filter vocabulary, CEL guidance, and wait timeout (GoogleCloudPlatform#1134) (GoogleCloudPlatform#1143) * fix(mcp): show and pin the default values that dry runs fill in * fix(mcp): explain how to pass each field type and report non-array set values as field errors * fix(mcp): keep wait_inspection below the tool call timeout of MCP clients * fix(mcp): render applied filter queries as YAML literal blocks * feat(mcp): add server instructions and a filter vocabulary section * fix(mcp): use an explicit indentation indicator for tab-led filter queries * fix(mcp): refine filter vocabulary, CEL body() guidance, wait timeout, and GoogleCloudPlatform#1134 review items * style(mcp): format inspection_run.go with goimports * fix(mcp): truncate long field choice lists in dry_run_inspection and clarify @Managed namespace default (GoogleCloudPlatform#1145) * fix(mcp): compact dry_run_inspection output and split inspection_form.go * fix(mcp,k8scontainer): keep field descriptions in dry_run_inspection and clarify @Managed namespace default * test(mcp): update logFileDryRunText in inspection_upload_test.go to keep description * fix(mcp,workbench): improve resource revision/manifest output and search_timelines match counts (GoogleCloudPlatform#1146) * fix(mcp): report revisions, manifests, and diffs without a recorded body * fix(mcp): distinguish direct timeline matches from ancestor nodes in search_timelines * feat(mcp,workbench): omit metadata.managedFields by default in get_resource_manifest * test(workbench): fix expected YAML in TestGetResourceManifest_IncludeManagedFields * test(workbench): simplify TestSearchTimelines assertions with cmp.Diff * feat(web,server): add timeline-only render route (/render/:inspectionId) for screenshot capture (GoogleCloudPlatform#1149) * feat(web,server): add timeline-only render route (/render/:inspectionId) for screenshot capture * refactor(web): move timeline renderer bridge types to common/schema * refactor(web): namespace timeline renderer under window.__khiCDPBridge.timelineRenderer * fix(web): setup GLContextManager before registering render loop handler * feat(cdp,docker): add headless Chrome CDP browser lifecycle and multi-target Dockerfile (GoogleCloudPlatform#1154) * feat(cdp,docker): add headless Chrome CDP browser lifecycle and multi-target Dockerfile * fix(cdp): synchronize Client.Call and Client.Close with a mutex * refactor(cdp): encapsulate raw CDP calls behind high-level Client methods * feat(mcp): add render_timelines MCP tool with headless Chrome CDP renderer (GoogleCloudPlatform#1150) * feat(mcp): add render_timelines MCP tool with headless Chrome CDP renderer * refactor(mcp): invoke window.__khiCDPBridge.timelineRenderer from CDP renderer * fix(mcp): fail fast on CDP transport errors during render page navigation * refactor(mcp): use shared cdp.Browser in ChromeTimelineImageRenderer and conditionally register render_timelines * refactor(mcp): use high-level cdp.Client methods in ChromeTimelineImageRenderer * test(mcp): simplify handleRenderTimelines test assertions using cmp.Diff on CallToolResult * feat(mcp,workbench): add validate_report MCP tool and ValidationRule framework (GoogleCloudPlatform#1153) * feat(mcp,workbench): add validate_report MCP tool and ValidationRule framework * fix(workbench): handle nil TrigramIndex and escaped opening backticks in report validation * refactor(workbench): split InlineCodeGroundingRule into separate file * refactor(workbench,mcp): rename InlineCodeGroundingRule to LogExistenceRule * refactor(mcp,workbench): extract pkg/server/mcp/md package and pass raw report string to ValidationRule * refactor(mcp): split pkg/server/mcp/md into format.go and extract.go * test(mcp): assert exact output with cmp.Diff in TestWorkbenchHandler_HandleValidateReport * test(web): declare bound inputs on StubTimelineFrameComponent in TimelineRenderSmartComponent spec * chore: merge main into epic/mcp (GoogleCloudPlatform#1161) * fix(workbench): treat missing CEL path levels as empty strings instead of aborting the timeline filter (GoogleCloudPlatform#1123) * fix(workbench): treat missing CEL path levels as empty strings instead of aborting the timeline filter * fix(workbench): reject non-string keys in CEL path lookups instead of resolving them to empty strings * fix(workbench): make CEL path equality reflexive by unwrapping pathMap operands * test(workbench): cover timelines without a path level that still match the CEL filter * feat(k8saudit): resolve undetermined resource names from request/response metadata and generateName (GoogleCloudPlatform#1148) * feat(k8saudit): resolve undetermined resource names from request/response metadata and generateName * fix(k8saudit): fall back to response metadata.generateName and simplify Status kind check * refactor(k8saudit): rename primaryName to nameFromLogFields and only read metadata.name from response * revert(k8saudit): revert unnecessary changes in mapper_error.go * build(deps): update npm dependencies to supersede Dependabot PRs (GoogleCloudPlatform#1155) Update root, web/, and scripts/msdf-generator/ npm dependencies to consolidate and supersede the 11 open Dependabot PRs on GitHub: - GoogleCloudPlatform#1152: follow-redirects (1.16.0 -> 1.16.1 in /web) - GoogleCloudPlatform#1151: hono (4.13.7 -> 4.13.13 in /web) - GoogleCloudPlatform#1147: @angular/router (21.2.22 -> 21.2.25 in /web, along with peer @angular/* packages) - GoogleCloudPlatform#1141: brace-expansion (1.1.18 -> 1.1.21, 5.0.9 -> 5.0.12 in /web) - GoogleCloudPlatform#1140: handlebars (4.7.9 -> 4.7.10 in /web) - GoogleCloudPlatform#1139: handlebars (4.7.9 -> 4.7.10 in /scripts/msdf-generator) - GoogleCloudPlatform#1138: source-map-js (1.2.1 -> 1.2.2 in /web) - GoogleCloudPlatform#1137: proxy-addr (2.0.7 -> 2.0.8 in /web) - GoogleCloudPlatform#1135: serialize-javascript (7.1.1 -> 7.1.2 in /web) - GoogleCloudPlatform#1117: markdown-it (14.3.0 -> 15.0.1) and markdownlint-cli2 (0.23.2 -> 0.23.3) - GoogleCloudPlatform#1062: js-yaml (5.2.2 -> 5.4.1) and markdownlint-cli2 (0.23.2 -> 0.23.3) * build(deps): update Go to 1.27.3, Node.js to 26.12.1, and golangci-lint to v2.15.0 (GoogleCloudPlatform#1159) * build(deps): update Go to 1.27.3, Node.js to 26.12.1, and golangci-lint to v2.15.0 * fix(make): add container fallback to format-go when GOLANGCILINT_CMD is empty * chore(agent): remove requirement for user approval before push (GoogleCloudPlatform#1160) * feat(khifile,inspection): record filter vocabulary metadata in KHI v6 files (GoogleCloudPlatform#1165) * refactor(mcp,workbench): simplify CEL references to static files and update serverInstructions * feat(khifile,inspection): record filter vocabulary metadata in KHI v6 files * style(khifile): use cmp.Compare for timeline type label tie-breaking * test(inspectioncore): use protocmp.Transform to compare FilterVocabularyMetadata proto * test(workbench): simplify workbench tests and share inspection server setup (GoogleCloudPlatform#1166) * test(workbench): simplify workbench tests and share inspection server setup * test(workbench): use struct for want values in table tests * feat(mcp): include Filter vocabulary in inspection summary (GoogleCloudPlatform#1167) * feat(mcp): include Filter vocabulary in inspection summary * docs(mcp): use singular kind in cel-timeline examples and realistic logType labels in golden test * docs(mcp): unify timeline path syntax on path["<key>"] * test(core,server): simplify core, server, and task unit tests (GoogleCloudPlatform#1168) * test(core,server): simplify core, server, and task unit tests * test(init): specify expected MCP and render tool state in test cases * test(web): simplify timeline render and workbench client specs (GoogleCloudPlatform#1170) * test(web): simplify timeline render and workbench client specs * test(web): fix failing Angular specs in timeline frame and render smart tests * test(web): stub GLContextManager setup in timeline frame spec to prevent WebGL context leak * test(mcp): simplify workbench tool, renderer, and template tests (GoogleCloudPlatform#1171) * test(mcp): simplify inspection tool and server tests (GoogleCloudPlatform#1172)
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.
Background & Problem
Part 3 of #1043 (stacked on top of Parts 1 & 2, Epic #1049).
Now that
Workbench.SearchTimelinesandWorkbench.SearchLogsare available,WorkbenchHandlerneeds to register thesearch_timelinesandsearch_logsMCP tools and render their outputs using embedded Markdown templates.Solution Approach
search_timelinesandsearch_logsinWorkbenchHandler.Register(pkg/server/mcp/workbench_handler.go).handleSearchTimelinesandhandleSearchLogsinpkg/server/mcp/workbench_search.go, validating CEL filters upfront viaworkbench.ValidateFilterandmdtemplate.CELErrorResult, acquiring the workbench viaacquireWorkbench, and rendering results via embedded templates:pkg/server/mcp/templates/search_timelines.md.tmplpkg/server/mcp/templates/search_logs.md.tmplRemaining Issues & Future Work
get_timeline_events,get_timeline_revisions,get_log_body,get_revision_manifest,get_revision_diff) are tracked in MCP: Tools for log details and resource history #1044.Fixes #1043