Skip to content

Add fields param to search_code and get_file_contents#2775

Draft
tommaso-moro wants to merge 2 commits into
mainfrom
tommaso-moro-add-fields-param-filtering
Draft

Add fields param to search_code and get_file_contents#2775
tommaso-moro wants to merge 2 commits into
mainfrom
tommaso-moro-add-fields-param-filtering

Conversation

@tommaso-moro

@tommaso-moro tommaso-moro commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What

Adds an optional fields array parameter to search_code and get_file_contents so callers can request only the fields they need, reducing tool response size and context usage. The feature is gated behind the fields_param feature flag and instrumented so we can measure adoption and realized savings.

How

  • fields filteringsearch_code filters each result item (selectable: name, path, sha, repository, text_matches); get_file_contents filters each directory entry (selectable: type, name, path, size, sha, url, git_url, html_url, download_url). Filtering is ignored for single-file responses. When fields is omitted, behavior is unchanged.
  • Feature flag — each tool registers two mutually exclusive variants following the existing dual-variant flag pattern: a flag-enabled variant that advertises fields and filters, and a legacy variant with the original schema that acts as a kill switch when the flag is off. When the flag is off, fields is not advertised at all.
  • Telemetry — best-effort, low-cardinality metrics emitted at each tool's filter point: mcp.fields.tool_call (adoption) and mcp.fields.bytes_full / bytes_sent / bytes_saved (effectiveness). Tags are limited to tool and filtered so cardinality stays bounded — repo, owner, user, query, and the requested field list are never tagged. Metrics are discarded by the noop sink in the open-source build; a real sink is injected by the hosted deployment.

Testing

  • Unit tests for field filtering, flag gating (both variants), and telemetry emission (adoption + realized savings).
  • Toolsnaps updated: the flag-enabled variants own the _ff_fields_param snapshots; the legacy variants own the canonical snapshots. README and docs/feature-flags.md regenerated.
  • script/lint clean; script/test (full race suite) passing.

@tommaso-moro tommaso-moro force-pushed the tommaso-moro-add-fields-param-filtering branch from de798fe to b19ce6a Compare July 3, 2026 07:23
Add an optional `fields` array parameter to the `search_code` and
`get_file_contents` tools so callers can request only the fields they
need, reducing tool response size and context usage.

- search_code: filters each result item to the selected fields while
  preserving the total_count / incomplete_results wrapper.
- get_file_contents: filters each directory entry when listing a
  directory; ignored for single-file responses.

Adds shared filterFields / filterEachField helpers and per-tool field
enums, plus unit tests and regenerated toolsnaps and docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tommaso-moro tommaso-moro force-pushed the tommaso-moro-add-fields-param-filtering branch from b19ce6a to 3326613 Compare July 3, 2026 08:09
Register search_code and get_file_contents as two mutually exclusive
variants gated by the new `fields_param` feature flag, following the
existing dual-variant flag pattern:

- The flag-enabled variant advertises the optional `fields` parameter and
  filters each result to the requested subset. It owns the
  `<tool>_ff_fields_param` toolsnap.
- The Legacy* variant exposes the original schema with no `fields`
  parameter and never filters, acting as a kill switch when the flag is
  off. It owns the canonical toolsnap.

Add best-effort, low-cardinality telemetry at each tool's filter point to
measure adoption and realized savings:

- `mcp.fields.tool_call` (increment) tagged by tool and whether the
  response was filtered.
- `mcp.fields.bytes_full` / `bytes_sent` / `bytes_saved` (counters) tagged
  by tool, emitted only when a response was filtered.

Tags are limited to `tool` and `filtered` to bound cardinality; repo,
owner, user, query, and the requested field list are never tagged. The
local server discards these via the noop metrics sink, while hosted
deployments inject a real sink. Metrics accessors now fall back to a noop
sink when no exporter is configured so emitting telemetry never panics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tommaso-moro tommaso-moro force-pushed the tommaso-moro-add-fields-param-filtering branch from 3326613 to a877d9c Compare July 3, 2026 09:04
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.

2 participants