Skip to content

ui: load MCP and custom tools on demand instead of sending them all - #102

Draft
allozaur wants to merge 1 commit into
allozaur/feat/permission-rulesfrom
allozaur/feat/tools-on-demand
Draft

allozaur wants to merge 1 commit into
allozaur/feat/permission-rulesfrom
allozaur/feat/tools-on-demand

Conversation

@allozaur

Copy link
Copy Markdown
Owner

Overview

With many MCP tools enabled, Llama Chat no longer sends all their definitions in every request: the model sees a short list and loads the tools it needs, which keeps a local model's context for the conversation.

Additional information

Layer 4 of the planned stack, on #101 (permission rules). It sits below #61 with the other core layers; inserting them into the stack and restacking #61 and above is still to do. Not tried against a real MCP server with many tools yet.

What changed
  • In on-demand mode, built-in and llama-server tools still go in full. MCP and custom tools go as a short list in the description of a tool_search tool: one line per tool (name: first sentence), or one line per server once the list passes 5% of the context.
  • tool_search takes words (create issue) or select:name1,name2, returns the full schemas, and loads the tools; they are appended to the next request.
  • A call to a listed tool that was not loaded loads it and runs it, so a small model that skips the search still works. A tool nobody listed still gets Unknown tool.
  • Loaded tools stay loaded for the conversation, so the tool list only grows and llama-server can keep reusing its prompt cache.
  • Settings › Tools › Tool loading: Automatic (the default: on demand once the definitions would take a tenth of the context, sized at 4 characters per token against n_ctx), On demand, All up front.
  • Loading asks for no permission; the loaded tool asks when it is called.
  • Llama Harness gets one more hook, resolveTool, which finds a tool the model called that is not in the list.
Testing
  • ui/lib/harness: npm run check, npm test (29 tests, 2 new for resolveTool), npm run prepack.
  • ui/apps/chat: npm run check, lint on the changed files, and the 897 unit tests pass, including tool-catalog.test.ts (ranking, select:, the short list per server, loading once, tools loaded earlier) and a flow test where the model calls a listed MCP tool directly and it is sent from the next request on.

Requirements

@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from 7d358f4 to 4bd97e2 Compare November 20, 2026 17:37
@github-actions github-actions Bot added documentation Improvements or additions to documentation server/ui labels Nov 20, 2026
allozaur added a commit that referenced this pull request Nov 20, 2026
@allozaur
allozaur added this pull request to stack #110 November 21, 2026 13:48
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from 4bd97e2 to 7e36807 Compare November 21, 2026 14:38
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from 7e36807 to 3368cf0 Compare November 24, 2026 06:24
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch 2 times, most recently from 3e393d9 to cc45689 Compare November 24, 2026 08:28
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from cc45689 to a2654bb Compare November 24, 2026 09:40
@allozaur
allozaur removed this pull request from stack #110 November 24, 2026 09:41
@allozaur
allozaur added this pull request to stack #114 November 24, 2026 09:41
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from a2654bb to cb6fa4f Compare November 24, 2026 12:18
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from cb6fa4f to 48d1a07 Compare November 24, 2026 13:57
@allozaur
allozaur removed this pull request from stack #114 November 24, 2026 13:58
@allozaur
allozaur added this pull request to stack #126 November 24, 2026 13:58
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from 48d1a07 to da26f0b Compare November 24, 2026 14:10
@allozaur
allozaur removed this pull request from stack #126 November 24, 2026 14:10
@allozaur
allozaur added this pull request to stack #127 November 24, 2026 14:10
@allozaur
allozaur removed this pull request from stack #127 November 24, 2026 14:45
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from da26f0b to 732519c Compare November 24, 2026 14:45
@allozaur
allozaur added this pull request to stack #129 November 24, 2026 14:46
With many tools enabled, their definitions take a large part of a local
model's context and blur its choice. In on-demand mode the built-in and
llama-server tools still go in full, and the MCP and custom tools go as
a short list in the description of a tool_search tool: one line per
tool, or per server once the list passes 5% of the context. A search by
words, or select:name1,name2, returns the schemas, loads the tools and
appends them to the next request. A call to a listed tool that was not
loaded loads it and runs it, so a model that skips the search still
works. Loaded tools stay loaded for the conversation, so the tool list
only grows and llama-server can keep reusing its prompt cache.

Settings > Tools > Tool loading: Automatic (default: on demand once the
definitions would take a tenth of the context), On demand, or All up
front. Loading a tool asks for no permission; the tool asks when called.

Llama Harness gets one more hook for it, resolveTool, which finds a
tool the model called that is not in the list.

Assisted-by: Claude (Opus 5.5 Medium)
@allozaur
allozaur force-pushed the allozaur/feat/tools-on-demand branch from 732519c to 95f735f Compare November 24, 2026 16:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation server/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant