Repository navigation
perf(ai): load only the called tool on a cold MCP tools/call - #2686
Merged
Merged
Maple Review Bot / Maple / review
succeeded
Nov 16, 2026 in 1m 24s
Confidence 10/10 · No issues found
🟢 Confidence 10/10 · safe to merge. The lazy path is pinned name and alias against the full registry, and the joined label has its own test; nothing is left unpinned.
no findings · tests covered · risk medium · 1/1 new units observable
Splits the MCP registry into a core plus the full catalog and gives tools/call a per-tool module map, so it imports one tool instead of all 134; joined now distinguishes a waited-on build. Safe to merge. The open McpQueryErrors come from tool query handlers, not this wiring.
tool-lookup.tsimports one tool's module pertools/call, cached per executorregistry-core.tsownsdefine, decode, render and next-call checks for both pathsmaple.mcp.executor_buildgainsjoinedfor a build that was already running@maple/security-audit/storekeeps the audit engine out of the MCP tool graph
Fixed since the last review
- ✅
F1 · A failedimport()of a suggested tool now fails a call that already ran
Production impact
Open errors in the changed files (2)
| Issue | Service | Occurrences | File |
|---|---|---|---|
| @maple/mcp/errors/McpQueryError (8 issues) | maple-ai | 105 | apps/ai/src/mcp/tools/registry.ts |
| @maple/mcp/errors/McpQueryError (2 issues) | maple-chat | 12 | apps/ai/src/mcp/tools/registry.ts |
After this merges, Maple checks whether they stop.
Production traffic of the changed files (last 7 days)
| File | Calls/day | Busiest operations |
|---|---|---|
apps/ai/src/mcp/dispatcher.ts |
73k | McpToolDispatcher.call 26k/day, 0.0% errMcpToolExecutor.execute 26k/day, 0.0% errMcpToolDispatcher.call 10k/day, 0.1% err |
apps/ai/src/mcp/tool-catalog.ts |
48k | POST /mcp 22k/day, 0.0% errPOST /mcp 22k/day, 0.0% errinitialize 2.4k/day, 0.0% err |
apps/ai/src/mcp/tools/registry-core.ts |
38k | McpToolRegistry.execute 26k/day, 0.0% errMcpToolRegistry.execute 10k/day, 0.1% errtools/list 1.7k/day, 0.0% err |
apps/ai/src/mcp/tools/registry.ts |
38k | McpToolRegistry.execute 26k/day, 0.0% errMcpToolRegistry.execute 10k/day, 0.1% errtools/list 1.7k/day, 0.0% err |
apps/ai/src/mcp/executor-loader.ts |
2.4k | initialize 2.4k/day, 0.0% err |
apps/ai/scripts/generate-mcp-tool-descriptors.ts |
1.7k | tools/list 1.7k/day, 0.0% err |
apps/ai/src/mcp/tool-descriptors-render.ts |
1.7k | tools/list 1.7k/day, 0.0% err |
Ingest cost of new log lines
apps/ai/src/mcp/tools/registry-core.ts:319: If this logs once per call, about 305 MB/month: the file's operations run 38k times a day.apps/ai/src/mcp/tools/registry-core.ts:447: If this logs once per call, about 305 MB/month: the file's operations run 38k times a day.apps/ai/src/mcp/tools/registry-core.ts:460: If this logs once per call, about 305 MB/month: the file's operations run 38k times a day.apps/ai/src/mcp/tools/registry-core.ts:500: If this logs once per call, about 305 MB/month: the file's operations run 38k times a day.apps/ai/src/mcp/tools/registry-core.ts:578: If this logs once per call, about 305 MB/month: the file's operations run 38k times a day.
What was checked
- F1 is fixed:
finishcatches a failed next-call load per call and drops that hint (registry-core.ts:443), pinned byregistry-core.test.ts:46 - Aliases, unknown names and prototype keys resolve as before through the generated map (
tool-lookup.test.ts:24,:63), includingnamesForper surface - No tool module imports
./registry, so no single-tool load drags in the catalog (grep oversrc/mcp/tools)
Observability coverage: 1 of 1 changes observable
| Change | Kind | Observable | Evidence |
|---|---|---|---|
Per-tool module load on a cold tools/call |
in-process work | yes | Runs inside the McpToolRegistry.execute span; a failed load logs maple.mcp.tool and maple.mcp.next_call (registry-core.ts:447) |
3ab9fda · Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.
Loading