[secops-mcp] Architectural notes: supporting both events and YARA-L 2.0 stats across search_security_events, search_udm, and get_stats
Status
Not actionable right now. Please do not pick up this issue yet.
This issue captures architectural findings and our staged plan for handling Chronicle SIEM YARA-L 2.0 statistical queries across search_security_events, search_udm, and get_stats in #336 and #246.
Architectural opinion and evidence
Splitting UDM event search and UDM statistical aggregation into mutually exclusive execution paths that drop or reject each other's responses was a legacy SDK artifact that actively trips up language models using MCP tools. search_udm and search_security_events should transparently return both events and stats payloads, for three reasons:
- Chronicle uses a single
:udmSearchREST endpoint for both. In early versions ofgoogle/secops-wrappersuch as commit6a74609,search_udmandget_statswere separate because both called the legacy UI RPCPOST .../legacy:legacyFetchUdmSearchView, which required separateeventListversusfieldAggregationsrequest fields. Oncegoogle/secops-wrappermigrated both methods ontoGET /v1alpha/{instance}:udmSearchin commits3ba8f0fandace24aa, both methods began sending the exact same HTTP request withquery,timeRange.start_time,timeRange.end_time, andlimit. Whether:udmSearchpopulateseventsorstatsin HTTP 200 responses depends solely on whether the query text includes a YARA-L 2.0outcome:section. - Models cannot predict whether natural language translation will emit
outcome:syntax. When an agent callssearch_security_eventswith prompts like"Count failed user logins by user in the last 24 hours"or"Show top failed login hosts", Chronicle's:translateUdmQueryendpoint decides server-side whether to emit a plain UDM filter or a YARA-L 2.0match:andoutcome:query. The calling model has no way to know that output shape ahead of time. BecauseChronicleClient.search_udminsecops<=0.44.1reads onlyresult.get("events", [])and discardsresult["stats"],search_security_eventsandsearch_udmreturntotal_events: 0with an emptyeventslist even when:udmSearchsucceeded with HTTP 200 statistical rows, whileChronicleClient.get_statsraisesAPIError("No stats found in response")if given a plain filter query. - Why keeping
get_statsalongside stats-capable search tools still helps. Even oncesearch_udmandsearch_security_eventsreturn botheventsandstatsso models never hit a false zero-result trap, a dedicatedget_statstool still earns its keep for direct YARA-L 2.0 aggregations:ChronicleClient.get_statsdefaults totimeout=120seconds instead ofsearch_udm's 30-second timeout for slower multi-day roll-ups, defaultslimittomax_values=60groups instead ofmax_events=10000, and gives models explicit YARA-L 2.0match:,outcome:,order:, andlimit:examples so they do not hallucinate pipe| statssyntax.
What we are doing right now
- Accept and land
get_statsin #336 and #246. Works immediately on releasedsecops>=0.35.1without waiting on an upstream SDK release, provides the 120-second timeout and YARA-L 2.0 aggregation guidance today, and honors the open community contribution in #246. - Fix response data loss upstream in
google/secops-wrapper. Opened https://github.com/google/secops-wrapper/issues/227 and https://github.com/google/secops-wrapper/pull/228 soChronicleClient.search_udmandChronicleClient.nl_searchattach normalizedresponse["stats"]matchingget_stats()and foldtooManyResultsintomore_data_availablewhenever:udmSearchreturnsstats.
What we will do if google/secops-wrapper#228 lands
Once https://github.com/google/secops-wrapper/pull/228 merges and ships in a new PyPI release of secops, we will make this issue actionable to:
- Bump the minimum
secopsversion inserver/secops/pyproject.tomlandserver/secops/setup.py. - Update
search_security_eventsinserver/secops/secops_mcp/tools/security_events.pyso itsReturns:andTroubleshooting & Iterative Searchingdocstring sections and result logging teach models to inspectevents["stats"]when:translateUdmQuerygenerates a YARA-L 2.0outcome:query, rather than treatingtotal_events: 0as a failed search. - Update
search_udminserver/secops/secops_mcp/tools/search.pyto document optionalstatsandmore_data_availablefields, useOptional[str] = Noneparameter typing, log statistical row counts accurately, and add unit tests foroutcome:responses. - Align tool descriptions across
search_security_events,search_udm, andget_statsso models understand thatsearch_security_eventsandsearch_udmreturn both events and stats, whileget_statsis tuned for direct multi-day YARA-L 2.0 aggregations.
If google/secops-wrapper does not cut a new PyPI release due to Maintenance Mode, secops-mcp can achieve the same behavior client-side in search_security_events and search_udm by detecting YARA-L 2.0 outcome: queries and delegating execution to chronicle.get_stats.
SDK reference notes
- Chronicle strips the leading
$fromoutcome:variable names inStatsData.results[].column, so$login_count = count(metadata.id)produces column"login_count". secops.chronicle.stats.process_stats_resultscastsint64Valtoint,doubleValtofloat,stringValtostr,timestampValto timezone-awaredatetime,listcells fromarray_distinctto Pythonlist, and empty cells toNone.secops.chronicle.stats.get_statsignores legacymax_events,case_insensitive, andmax_attemptsparameters. Onlyquery,start_time,end_time,max_values, andtimeoutare sent to Chronicle, and case-insensitive matching in YARA-L 2.0 requiresnocasein the query text.