Skip to content

perf(mcp): add opt-in hot/cold tool discovery - #9046

Merged
gensokyo-dev merged 2 commits into
mainfrom
perf/mcp-catalog-hot-cold
Nov 5, 2026
Merged

gensokyo-dev merged 2 commits into
mainfrom
perf/mcp-catalog-hot-cold

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add opt-in REA_MCP_TOOL_CATALOG_PROFILE=hot-cold: advertise five session/Evidence tools plus discover_tools, then load original named tools on demand. Full advertisement remains the default because client support and whole-task costs vary.

Problem and expected behavior

The 235-tool tools/list result is 4,035,856 UTF-8 bytes. Hot/cold starts with 6 tools / 738,763 bytes and keeps the in-scope inventory discoverable. The default catalog is byte-identical to pinned main 808491685.

Change and scope

  • Keyword/exact-name discovery returns descriptions and configured input schemas. Named handlers, validation, Evidence and family exclusions remain authoritative.
  • Reply encoding must fit the current delivery budget before definitions activate. Oversized pages fail atomically; smaller pages retain complete configured contracts. Errors use the shared bounded delivery policy too.
  • One notification per changed batch; repeated loads emit none. HTTP reconnect resets visibility after the old transport drains.
  • Identity covers inventory/policy independently of loaded state. CLI status, doctor, setup and verifier bindings handle the profile.

Contract and boundary impact

discover_tools({query:"sqlite",limit:1}) loads inspect_sqlite_database; the next call uses that original tool. Discovery performs no analysis and provides no generic execution gateway.

Codex 0.165.0 needs features.mcp_tool_list_changed=true. A canary reader was unavailable by default, callable with refresh enabled, and remained blocked by disabled_tools with refresh enabled. Other harnesses remain unverified.

Evidence and regression coverage

Real Codex 0.165.0, requested alias gpt-6.1-sol / low / code-mode host (resolved model identity unreported), serial trials against immutable builds. Artifacts: [email protected] and public Chinook SQLite. Independent source/SQLite oracles, returned Evidence IDs, unchanged target bytes, cleanup and resources passed 42/42 task trials. Two additional artifact pilots also passed. Rejected MCP calls, discovery misses and recovery costs remain included.

Final revision 98e17d7a1: full catalog → hot/cold, full output schemas, matching prompts, means of 2 fresh agent/server runs per cell; peak is the largest per-trial cgroup peak. Input includes cache; uncached = reported input minus cached input.

Task Input tokens Output tokens Uncached input Wall s CPU s Peak MiB
SQLite 94,924 → 130,378 518 → 518 23,628 → 21,578 32.92 → 34.24 5.55 → 5.09 536 → 478
Package + SQLite 226,768 → 226,700 909 → 862 38,224 → 37,004 46.89 → 45.94 6.30 → 6.33 619 → 586

Final repeats show higher SQLite input and essentially equal combined-task input. Earlier experiments (12 initial-reply trials and 22 trials on b762f9b, including compact/full schemas and discovery-guidance diagnostics) showed substantial variance: full-output semver exports averaged 763,847 → 573,432 input and package/SQLite 367,739 → 261,413; compact-output package/SQLite increased 227,678 → 250,410. The budget fix preserves normal discovery replies byte for byte; differences across repeats demonstrate agent/cache variability. Initial Codex input stayed ~11.4K because its host already defers tool access.

A separate three-hot-tool prototype reduced upfront exposure further but used 104,130 SQLite input tokens in its pilot; the final curated hot set is retained. These observations support an explicit loading option and further evaluation, with no general token-saving claim.

OS caches were warm; remote caching and agent paths varied. Counters cover the local process family at payload exit, including charged file cache; remote inference is unmeasured. Limits: 1 CPU, 4 GiB hard / 3 GiB early stop, no swap. No stops/OOM; cleanup verified. Raw transcripts/hashes/receipts remain local; no experiment reports or data are added.

Validation performed

  • Initial focused config/setup/catalog/deferred/stdio/doctor/HTTP suite: 191 passed.
  • After review: 61 passed, including maximum 20-tool pages with an 8 KiB budget, unchanged visibility on refusal, complete-contract recovery through smaller pages, and oversized unknown-name failures.
  • python3 scripts/run-python-tests.py --analysis-efficiency: 102 passed.
  • npm run check:fast, npm run docs:check, git diff --check: passed; relevant checks repeated after the reply-budget fix.
  • Both generated default catalogs match a separate pinned-main build. Legacy/auto negotiation, schema dialects, paging, atomic failure, idempotent notifications, family exclusion, canonical handlers and HTTP session reset are covered.

Compatibility, safety, and release

Additive opt-in MCP profile. Real providers exercised: static JavaScript and SQLite; native deep providers and other agent clients were not exercised. Product docs are updated. The automatic reply-limit finding is fixed and resolved; Codex GitHub review was unavailable due repository review quota. No manual review request or retrigger was sent.

Author readiness

Human owner: @gensokyo-dev

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

Required CI passed on 98e17d7a1; the actionable automatic finding is fixed/resolved and the automatic Greptile re-review is 5/5. This follows the catalog measurement work in #9035.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T19:41:11.808078Z
We couldn’t complete this review. Comment @codex review to try again.
b762f9b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; the earlier discovery reply-limit issue is fixed.

Summary

Adds opt-in hot/cold tool discovery while keeping full advertising as the default.

  • MCP clients can search a smaller catalog and load tools by name.
  • Operators can choose and check the hot/cold catalog profile.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Initial hot tool catalog"] --> B["Call discover_tools"]
  B --> C{"All names in scope?"}
  C -- No --> D["Return bounded error; load nothing"]
  C -- Yes --> E{"Both reply forms fit?"}
  E -- No --> D
  E -- Yes --> F["Enable original named tools"]
  F --> G["Notify once if visibility changed"]
  G --> H["Client refreshes tools/list"]
Loading

Reviews (2) · Last reviewed commit: "fix(mcp): bound discovery replies before..." · Reviewed by Greptile

Comment thread src/server/ProgressiveToolCatalog.ts Resolved
@gensokyo-dev
gensokyo-dev merged commit 0beedcd into main Nov 5, 2026
59 checks passed
@gensokyo-dev
gensokyo-dev deleted the perf/mcp-catalog-hot-cold branch November 5, 2026 20:27
@morluto morluto added area: mcp MCP server, transport, and tool registration performance Performance regressions, scaling limits, and bounded-resource work labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants