mcp-security icon indicating copy to clipboard operation
mcp-security copied to clipboard

[secops-mcp] Architectural notes: supporting both events and YARA-L 2.0 stats across search_security_events, search_udm, and get_stats

Open dandye opened this issue 3 weeks ago • 0 comments

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:

  1. Chronicle uses a single :udmSearch REST endpoint for both. In early versions of google/secops-wrapper such as commit 6a74609, search_udm and get_stats were separate because both called the legacy UI RPC POST .../legacy:legacyFetchUdmSearchView, which required separate eventList versus fieldAggregations request fields. Once google/secops-wrapper migrated both methods onto GET /v1alpha/{instance}:udmSearch in commits 3ba8f0f and ace24aa, both methods began sending the exact same HTTP request with query, timeRange.start_time, timeRange.end_time, and limit. Whether :udmSearch populates events or stats in HTTP 200 responses depends solely on whether the query text includes a YARA-L 2.0 outcome: section.
  2. Models cannot predict whether natural language translation will emit outcome: syntax. When an agent calls search_security_events with prompts like "Count failed user logins by user in the last 24 hours" or "Show top failed login hosts", Chronicle's :translateUdmQuery endpoint decides server-side whether to emit a plain UDM filter or a YARA-L 2.0 match: and outcome: query. The calling model has no way to know that output shape ahead of time. Because ChronicleClient.search_udm in secops<=0.44.1 reads only result.get("events", []) and discards result["stats"], search_security_events and search_udm return total_events: 0 with an empty events list even when :udmSearch succeeded with HTTP 200 statistical rows, while ChronicleClient.get_stats raises APIError("No stats found in response") if given a plain filter query.
  3. Why keeping get_stats alongside stats-capable search tools still helps. Even once search_udm and search_security_events return both events and stats so models never hit a false zero-result trap, a dedicated get_stats tool still earns its keep for direct YARA-L 2.0 aggregations: ChronicleClient.get_stats defaults to timeout=120 seconds instead of search_udm's 30-second timeout for slower multi-day roll-ups, defaults limit to max_values=60 groups instead of max_events=10000, and gives models explicit YARA-L 2.0 match:, outcome:, order:, and limit: examples so they do not hallucinate pipe | stats syntax.

What we are doing right now

  1. Accept and land get_stats in #336 and #246. Works immediately on released secops>=0.35.1 without 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.
  2. 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 so ChronicleClient.search_udm and ChronicleClient.nl_search attach normalized response["stats"] matching get_stats() and fold tooManyResults into more_data_available whenever :udmSearch returns stats.

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:

  1. Bump the minimum secops version in server/secops/pyproject.toml and server/secops/setup.py.
  2. Update search_security_events in server/secops/secops_mcp/tools/security_events.py so its Returns: and Troubleshooting & Iterative Searching docstring sections and result logging teach models to inspect events["stats"] when :translateUdmQuery generates a YARA-L 2.0 outcome: query, rather than treating total_events: 0 as a failed search.
  3. Update search_udm in server/secops/secops_mcp/tools/search.py to document optional stats and more_data_available fields, use Optional[str] = None parameter typing, log statistical row counts accurately, and add unit tests for outcome: responses.
  4. Align tool descriptions across search_security_events, search_udm, and get_stats so models understand that search_security_events and search_udm return both events and stats, while get_stats is 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 $ from outcome: variable names in StatsData.results[].column, so $login_count = count(metadata.id) produces column "login_count".
  • secops.chronicle.stats.process_stats_results casts int64Val to int, doubleVal to float, stringVal to str, timestampVal to timezone-aware datetime, list cells from array_distinct to Python list, and empty cells to None.
  • secops.chronicle.stats.get_stats ignores legacy max_events, case_insensitive, and max_attempts parameters. Only query, start_time, end_time, max_values, and timeout are sent to Chronicle, and case-insensitive matching in YARA-L 2.0 requires nocase in the query text.

dandye avatar Nov 06 '26 22:11 dandye