Skip to content

feat(tools): let MCP_TOOLS register a subset of tool groups - #2

Open
wromansky wants to merge 1 commit into
wger-project:masterfrom
wromansky:feat/selectable-tool-groups
Open

feat(tools): let MCP_TOOLS register a subset of tool groups#2
wromansky wants to merge 1 commit into
wger-project:masterfrom
wromansky:feat/selectable-tool-groups

Conversation

@wromansky

Copy link
Copy Markdown

Why

All 81 tools are registered unconditionally today. That is a lot of schema for one agent to carry, and it is awkward for two kinds of deployment:

  • Agents driven by small local models. Tool-selection accuracy falls off as the surface grows, and every schema is spent from a modest context window. This is the common shape for self-hosters running a local model beside their own wger.
  • Single-purpose agents. A food-logging assistant has no business holding 24 routine-authoring tools.

The handoff notes list several open items, but not this one — it surfaced while wiring the server up to a self-hosted instance for exactly that small-local-model case.

What

MCP_TOOLS takes a comma-separated list of group names, using the same CSV convention as ALLOWED_HOSTS. Empty keeps today's behaviour, so the change is backwards compatible.

MCP_TOOLS=nutrition,off,profile     # a food-logging agent

Valid names are the module names: profile, routines, workout_logs, body_weight, measurements, equipment, nutrition, exercises, analytics, off.

Three details worth a look during review:

  • _REGISTRARS becomes a name-keyed dict and TOOL_GROUPS is derived from it, so the documented list cannot drift from the code.
  • Registration iterates that dict rather than the env var. Tool order stays stable however the variable is written, and a repeated name is harmless rather than a duplicate registration.
  • An unknown group name raises at startup, naming both the typo and the valid groups. Silently registering nothing seemed like the failure most likely to cost a self-hoster an evening.

Tests

8 new tests in tests/test_tool_selection.py: the default surface, a subset, duplicates, env ordering, the unknown-name error, CSV parsing, and that every name in TOOL_GROUPS is independently valid — so the documented list stays honest as groups are added.

Full suite passes (79) and ruff check is clean. MCP_TOOLS was added to the conftest cleared-vars list so a stray value in the environment cannot skew other tests.

Docs

README.md gains a short section under Tools, and .env.example a commented block next to the other optional settings.

All 81 tools are registered unconditionally today. That is a lot of schema
for one agent to carry, and it is a problem for two kinds of deployment:

- Agents driven by small local models. Tool-selection accuracy falls off as
  the surface grows, and every schema is spent from a modest context window.
- Single-purpose agents. A food-logging assistant has no business holding 24
  routine-authoring tools.

MCP_TOOLS takes a comma-separated list of group names, following the same CSV
convention as ALLOWED_HOSTS. Empty keeps the current behaviour, so this is
backwards compatible.

    MCP_TOOLS=nutrition,off,profile

_REGISTRARS becomes a name-keyed dict and TOOL_GROUPS is derived from it, so
the documented list cannot drift from the code. Registration iterates that
dict rather than the env var, which keeps tool order stable however the
variable is written and makes a repeated name harmless instead of a duplicate
registration.

An unknown group name raises at startup, naming both the typo and the valid
groups. Silently registering nothing is the failure mode most likely to cost
a self-hoster an evening.

Adds 8 tests covering the default, a subset, duplicates, env ordering, the
unknown-name error, CSV parsing, and that every name in TOOL_GROUPS is
independently valid.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant