Files
magpie/docs/subsystems
yetone 10f1e97883 search: a GLM Coding Plan searches its own models with the plan's web search MCP
young02036 on Discord asked for the GLM Coding Plan's Web Search MCP in
magpie's web search. The plan's key is given for that server, so magpie
now asks it with the provider's own key, with nothing to set up: a
Streamable HTTP session at <host>/api/mcp/web_search_prime/mcp
(open.bigmodel.cn or api.z.ai, docs.bigmodel.cn/cn/coding-plan/mcp/
search-mcp-server and docs.z.ai/devpack/mcp/search-mcp-server), the key
as a Bearer, initialize, one tools/call of webSearchPrime with
{"search_query"}, then the session's DELETE.

- provider.ZhipuCodingSearch: only a provider or key on the plan's
  /api/coding/paas/v4 (Zhipu's or Z.ai's host, or the zhipu/zai preset).
  A pay-as-you-go key isn't served by the server and never asks it.
  ZhipuSearches reads p.Keys itself, since KeysOn is counted per list and
  searchesOwn runs on every request. ZhipuSearchKeys lists the plan's
  keys, which are asked in turn.
- searchesOwn/ownSearch: the plan's own models search there first, as
  with Kimi Code and WorkBuddy, and fall to magpie's searcher and the
  search APIs when it fails. This happens only while Settings names no
  searcher (glmSearches): a searcher the user named still searches for
  every model, which is a value the user set.
- It is not offered as a searcher for other providers' models. A plan
  with the Responses base (/api/v1) already searches natively there
  (searchHosts, #660), and making it a no-model service would change the
  searcher those users have now.
- The reply's text is read as a list of results, a list in a JSON
  string, or a list under search_result/results/items/data. isError, or
  words with no results, is an error with the key masked. The query is
  masked as Settings > Privacy says (maskedQuery). Each ask is a request
  log row (logOwnSearch).
- No GUI change: the setting has no switch, the same as WorkBuddy's.
- docs/subsystems/gateway-routing.md has a section on it, and the
  searchesOwn lists there and in plugin-runtime.md name it.

Run (mote, at this tree):
- go test -count=1 ./internal/provider ./internal/settings
- go test -count=1 -run 'Search|GLM|Zhipu|Kimi|LoopGuard|Docs|Guard|WorkBuddy'
  ./internal/gateway: ok
- GOOS=linux and GOOS=windows go vet ./internal/gateway ./internal/provider:
  ok
- gofmt -l: clean

The tests use a fake server only and never reach the network:
- TestGLMCodingPlanSearchesForItsModels: Claude Code's literal WebSearch
  request to a plan's model. The fake gives an event-stream reply with
  a progress notification before the result, and a double-stringified
  result. Then a refusal, an unnamed versus a named searcher beside a
  search API, and a pay-as-you-go key.
- TestReadGLMSearch: each reply shape, and prose.
- TestZhipuCodingSearchAddress: hosts, presets, a plan key beside a
  pay-as-you-go one, a key that's off.

Broken by hand:
- With the old searchesOwn/ownSearch, TestGLMCodingPlanSearchesForItsModels
  is red: the model had no search, 400 "no search tool".
- With glmSearches ignoring a named searcher, the test is red at the
  named-searcher step: the MCP was asked and the named searcher wasn't.

Not tried:
- No real GLM Coding Plan key was available, so nothing was sent to the
  real open.bigmodel.cn or api.z.ai server. The docs give neither the
  tool's argument names nor its reply's shape. search_query and the
  result fields come from Zhipu's Web Search API and a third-party npm
  wrapper (web-search-zaimcp 0.1.2). If the real reply differs, a search
  falls to magpie's other searcher or the search APIs and says why.
- The plan's MCP quota, and how a spent quota is worded.
- A GUI hint in Settings > Web search.
2026-11-05 11:44:31 +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
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.