perf: trim redundant prose from built-in tool schemas#338
Merged
Conversation
The execute_sql/search_objects tools are registered per-source in
multi-source mode, so every byte of their description and parameter
docs is replicated O(n) across sources. Remove prose that merely
restates what the structured JSON Schema already encodes:
- search_objects description: drop the "(schemas, tables, columns,
...)" list, which duplicates the object_type enum
- pattern param: drop "Default: %" (already in .default("%"))
- limit param: drop "(default: 100, max: 1000)" (already in
.default(100).max(1000))
Zero information loss — the model still receives every fact via the
JSON Schema's enum/default/maximum. Per-source tool identity is
preserved, so MCP-client per-source selection and permissioning are
unaffected.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces repeated natural-language prose in built-in MCP tool descriptions/parameter docs to lower per-source tool-list context size in multi-source mode, relying on structured schema fields (enum/default/maximum) instead.
Changes:
- Shortened
search_objectstool description text in tool registration metadata. - Trimmed
patternandlimitparameter descriptions in both the MCP Zod schema and the REST API “tool metadata” copy.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/utils/tool-metadata.ts |
Trims search_objects tool/param prose used for MCP registration and for /api/sources tool metadata. |
src/tools/search-objects.ts |
Trims Zod .describe(...) strings for pattern and limit in the MCP tool input schema. |
The REST API tool metadata (/api/sources, web UI) uses ToolParameter, which carries no enum/default/maximum — so prose is the only place that info lives, unlike the MCP path where the JSON Schema encodes it. Trimming those API-only copies lost information with no token benefit (the REST API is not in the model context). Per Copilot review: - Restore "Default: %" on pattern and "(default: 100, max: 1000)" on limit in buildSearchObjectsTool (API copy) - Add the allowed object_type values to its param description, since the shared tool description no longer lists them The MCP Zod schema trims in search-objects.ts are unchanged — that's where the per-source token win is, and the JSON Schema still carries enum/default/maximum there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
In multi-source mode,
execute_sqlandsearch_objectsare registered per source (execute_sql_prod,execute_sql_staging, …), so every byte of their description and parameter docs is replicatedO(n)across sources in the MCPtools/list. This trims prose from the MCP schema that merely restates what the structured JSON Schema already encodes — lossless context savings on the MCP path.Trimmed in the MCP path (
search-objects.tsZod schema + the shared tool description):search_objectsdescription: the(schemas, tables, columns, procedures, functions, indexes)list — duplicates theobject_typeenumpatternparam:". Default: %"— already in.default("%")limitparam:" (default: 100, max: 1000)"— already in.default(100).max(1000)On the MCP path the model still receives every fact via the schema's
enum/default/maximum, so there is no information loss there.REST API / web UI (
/api/sources)The REST tool metadata uses
ToolParameter, which has no enum/default/maximum fields — so prose is the only place that info lives. The API copies therefore keep the descriptive text (Default: %,default: 100, max: 1000), and theobject_typeparam description spells out its allowed values, since the shared tool description no longer lists them. The REST API is not in the model context, so keeping it verbose costs no tokens. (Thanks @copilot for catching this.)Context
This came out of #266. The originally-proposed fix there was to collapse the per-source tools into a single
execute_sql(sql, source_id)+ alist_sourcesdiscovery tool (O(1)context). That collapse was rejected because it removes per-source tool identity in the MCP client — users would lose the ability to select/enable/permission a specific source's tool (e.g. always-deny writes to prod), since that only works whilesource_idis part of the tool name. Under MCP's flat tool list, per-source selectability and anO(1)tool count are mutually exclusive.This PR is the alternative: keep per-source tools (selectability preserved), reduce the per-tool MCP token cost instead. It's the lossless floor — stays
O(n)in count, but removes the duplicated prose from the MCP schema with no downside.Test plan
pnpm testforsearch-objects,tool-metadata,execute-sqlsuites — 72 passing"Execute SQL queries","Search and list database objects") pinned bystartsWith/indexOfassertions are preserved🤖 Generated with Claude Code