Add fields param to search_code and get_file_contents#2775
Draft
tommaso-moro wants to merge 2 commits into
Draft
Add fields param to search_code and get_file_contents#2775tommaso-moro wants to merge 2 commits into
tommaso-moro wants to merge 2 commits into
Conversation
de798fe to
b19ce6a
Compare
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>
b19ce6a to
3326613
Compare
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>
3326613 to
a877d9c
Compare
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.
What
Adds an optional
fieldsarray parameter tosearch_codeandget_file_contentsso callers can request only the fields they need, reducing tool response size and context usage. The feature is gated behind thefields_paramfeature flag and instrumented so we can measure adoption and realized savings.How
fieldsfiltering —search_codefilters each result item (selectable:name,path,sha,repository,text_matches);get_file_contentsfilters each directory entry (selectable:type,name,path,size,sha,url,git_url,html_url,download_url). Filtering is ignored for single-file responses. Whenfieldsis omitted, behavior is unchanged.fieldsand 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,fieldsis not advertised at all.mcp.fields.tool_call(adoption) andmcp.fields.bytes_full/bytes_sent/bytes_saved(effectiveness). Tags are limited totoolandfilteredso 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
_ff_fields_paramsnapshots; the legacy variants own the canonical snapshots. README anddocs/feature-flags.mdregenerated.script/lintclean;script/test(full race suite) passing.