Commit a4c0640
committed
feat(mcp): smart loading — connect_strategy, tool budget, per-session scoping, meta-tools
Four levers to control MCP server loading, reducing startup time and
context-window bloat for users with many MCP servers.
Lever 1 — connect_strategy (per-server):
startup (default): connect at Hermes startup, register all tools
lazy: register tool schemas but defer subprocess spawn until first call
on_demand: invisible until explicitly loaded via /mcp load or mcp_load_server
Lever 2 — mcp_tool_budget (global):
Caps the number of MCP tool schemas in the LLM prompt.
LRU eviction drops least-used servers' tools when budget exceeded.
Meta-tools (mcp_list_servers, mcp_load_server) always survive eviction.
Default: 0 (unlimited, backward compatible).
Lever 3 — /mcp slash commands:
/mcp list → show all servers, status, tool counts, strategy
/mcp enable <name> → activate a lazy/on_demand server now
/mcp disable <name> → mark an on_demand server inactive for this session
/mcp load <name> → same as enable
Lever 4 — meta-tools (always available):
mcp_list_servers — returns all configured servers with status/strategy
mcp_load_server — activates a lazy or on_demand server mid-session
Bug fixes discovered during audit:
- _activate_lazy_server removed from _lazy_servers before connecting,
leaving failed connections in limbo (not retryable, not connected)
- /mcp disable called _clear_session_loaded_servers() which cleared ALL
on_demand servers, not just the named one
- Lazy server stub tools had no toolset alias registered, making them
invisible to the platform resolver
- Meta-tools registered into toolset 'mcp' which doesn't exist in any
platform composite — tools were invisible to the LLM
Refs: NousResearch#66473 (umbrella), NousResearch#63626 (lazy MCP), NousResearch#6839 (tool schema deferral),
NousResearch#45955 (per-session scoping)1 parent d59b79f commit a4c0640
6 files changed
Lines changed: 588 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8790 | 8790 | | |
8791 | 8791 | | |
8792 | 8792 | | |
| 8793 | + | |
| 8794 | + | |
8793 | 8795 | | |
8794 | 8796 | | |
8795 | 8797 | | |
| |||
10876 | 10878 | | |
10877 | 10879 | | |
10878 | 10880 | | |
| 10881 | + | |
| 10882 | + | |
| 10883 | + | |
| 10884 | + | |
| 10885 | + | |
| 10886 | + | |
| 10887 | + | |
| 10888 | + | |
| 10889 | + | |
| 10890 | + | |
| 10891 | + | |
| 10892 | + | |
| 10893 | + | |
| 10894 | + | |
| 10895 | + | |
| 10896 | + | |
| 10897 | + | |
| 10898 | + | |
| 10899 | + | |
| 10900 | + | |
| 10901 | + | |
| 10902 | + | |
| 10903 | + | |
| 10904 | + | |
| 10905 | + | |
| 10906 | + | |
| 10907 | + | |
| 10908 | + | |
| 10909 | + | |
| 10910 | + | |
| 10911 | + | |
| 10912 | + | |
| 10913 | + | |
| 10914 | + | |
| 10915 | + | |
| 10916 | + | |
| 10917 | + | |
| 10918 | + | |
| 10919 | + | |
| 10920 | + | |
| 10921 | + | |
| 10922 | + | |
| 10923 | + | |
| 10924 | + | |
| 10925 | + | |
| 10926 | + | |
| 10927 | + | |
| 10928 | + | |
| 10929 | + | |
| 10930 | + | |
| 10931 | + | |
| 10932 | + | |
| 10933 | + | |
| 10934 | + | |
| 10935 | + | |
| 10936 | + | |
| 10937 | + | |
| 10938 | + | |
| 10939 | + | |
| 10940 | + | |
| 10941 | + | |
| 10942 | + | |
| 10943 | + | |
| 10944 | + | |
| 10945 | + | |
| 10946 | + | |
| 10947 | + | |
| 10948 | + | |
| 10949 | + | |
| 10950 | + | |
| 10951 | + | |
| 10952 | + | |
| 10953 | + | |
| 10954 | + | |
| 10955 | + | |
| 10956 | + | |
| 10957 | + | |
| 10958 | + | |
| 10959 | + | |
| 10960 | + | |
| 10961 | + | |
| 10962 | + | |
| 10963 | + | |
| 10964 | + | |
| 10965 | + | |
| 10966 | + | |
| 10967 | + | |
| 10968 | + | |
| 10969 | + | |
| 10970 | + | |
| 10971 | + | |
| 10972 | + | |
| 10973 | + | |
| 10974 | + | |
| 10975 | + | |
| 10976 | + | |
| 10977 | + | |
| 10978 | + | |
| 10979 | + | |
| 10980 | + | |
| 10981 | + | |
| 10982 | + | |
10879 | 10983 | | |
10880 | 10984 | | |
10881 | 10985 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1381 | 1381 | | |
1382 | 1382 | | |
1383 | 1383 | | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
1384 | 1390 | | |
1385 | 1391 | | |
1386 | 1392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
41 | 70 | | |
42 | 71 | | |
43 | 72 | | |
| |||
450 | 479 | | |
451 | 480 | | |
452 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
453 | 514 | | |
454 | 515 | | |
455 | 516 | | |
| |||
1289 | 1350 | | |
1290 | 1351 | | |
1291 | 1352 | | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
1292 | 1356 | | |
1293 | 1357 | | |
1294 | 1358 | | |
| |||
0 commit comments