Files
magpie/docs/subsystems
yetone 9768b384e4 router: find_tools finds tools for a query in Chinese, and names every tool when none matches (Passings_z on X)
Passings_z asked on X (tweet 2123227759409586219) why, with the MCP
router's tools on demand, some tools never get used. An agent given
find_tools and call_tool that asks in Chinese found none of the tools
there were:

- hubWords split only at characters that aren't letters or digits, so
  帮我截个图 was one word, and hubWordIn looked for it whole in the
  description, which an English one never has.
- hubMatch.clears needs two thirds of the query's key words, so
  截图 screenshot failed on a tool named screenshot too: 截图 counted
  against it.
- With nothing matched, the reply named 8 tools a server, so a model
  had no way to the rest.

Now:
- hubWords also cuts where a spaceless script (Han, kana, Hangul) meets
  another (截图screenshot is 截图 and screenshot). A spaceless word is
  cut at characters that say nothing of a tool (hubStopRunes: 我 帮 个
  を …), each piece a key word (帮我截个图 is 截 and 图), found in a text
  when it is one character there or at least half of its two-character
  runs are (hubPhraseIn).
- Key words are matched against the tool's router name, its server's
  own name (a server named in Chinese) and its description.
- A key word with letters not in ASCII counts only for a tool whose
  name, server or description has such letters, so 截图 screenshot is
  screenshot to an English tool. An English query matches what it did.
- No match names every tool of each server when that fits in hubSayMax
  (2000 characters), else 8 a server and that find_tools with an empty
  query names every tool. A query not in ASCII when no tool has such
  letters is told the tools are named and described in English.

Siblings: hubNear (call_tool's close names) shares hubKeyWords and
hubMatchOf, so it takes the same words. The GUI's searches are
substring filters (includes), not this tokenizer; nothing to change.
find_tools' and call_tool's descriptions and the instructions, the text
that goes to the vendor, are unchanged.

docs/subsystems/mcp-router.md: Tools on demand says the new matching
and the no-match reply.

Tests (internal/gateway/hub_find_cjk_test.go):
- TestHubFindInChinese: 截图 screenshot, 截图screenshot, 帮我截个图,
  截取屏幕, 发消息到群聊, 截屏 (a server named 截屏工具) find their tool
  first, and not each other's.
- TestHubFindNotFoundNamesEveryTool: all 12 of a server named, the
  English hint, and past the budget the empty-query hint.
- TestHubFindEnglishAsBefore: 30 English queries match exactly what
  they matched at 14b6b9555.

Run:
- Old code (14b6b9555 with the new test file, on mica):
  TestHubFindInChinese FAIL ("截图 screenshot" matched [], "帮我截个图"
  matched [], 6 of 8), TestHubFindNotFoundNamesEveryTool FAIL (not
  every tool, no English hint, no empty-query hint),
  TestHubFindEnglishAsBefore PASS (as it should).
New code, at base 14b6b9555, on mica (mote's load was over 18):
  gofmt -l prints nothing; go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.
  HOME=<temp> go test -tags nogui -timeout 45m ./...: every package ok
  but agent, dirent, gateway and gui. Each red rerun on mica at the new
  code and at 14b6b9555:
  - internal/dirent watch tests: red at both (#7031).
  - TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes: red 3 of 3 at
    both (#7117).
  - gateway doneHold.serve "close of closed channel" panic
    (continuation_test.go:781): #6505, #6690; not seen on the rerun.
  - TestWSLAgentFolderIsALink (#7150) and TestGatewayModeListsNoOwnSessions
    (#7064): pass on the rerun at both.
  The new hub tests and every Hub/HubMCP/HubFind test pass.
- Rebased on origin/main 7d5db0f29 (cli plugin hosts, update hint; no
  file in common): go build, go vet ./... and
  go test ./internal/gateway -run 'Hub' run again there: build ok, vet ok, gateway Hub tests ok.
- Not tried: a real agent without its own tool search (e.g. OpenCode,
  Kimi) asking the router in Chinese end to end; the queries tested are
  my own phrasings against real servers' English descriptions plus
  invented Chinese ones, not the reporter's own tool list.
2026-11-19 10:54:42 +08:00
..
2026-11-10 03:25:44 +08:00

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab Memory
One skill, magpie-skills, listing the Library's skills in place of each agent's own Skill router
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.