Files
Klarkxy 95f37f46fa minimax 0.2.0: MiniMax web search and Matrix media tools (#671)
Adds MiniMax Code's account tools to the minimax plugin, as a Magpie-only `exports["./server"]` entry (magpie.mjs):
- `web_search`, MiniMax's own search, at /mavis/api/v1/mcp/web_search;
- the Matrix connector tools: image, video, speech, music, media understanding, image search and enhancement, and asset URLs, plus `list_tools`, `tool_schema` and `call_tool` limited to connector__matrix__*. The schemas are bundled in matrix-tools.json, and each call is routed through the account's live catalog.
- Tool requests reuse the chat sign-in's refresh logic per stored account key, and go through siteFetch: a cross-host redirect (Akamai's 307 to the other site) is an OtherSite hint and spends no refresh (#666).
- With no `account` named, a tool uses the site's first stored account. An explicitly named account never falls back to another one.
- No `web_fetch`: magpie's search MCP already serves one that refuses private addresses.
- Tool descriptions don't name magpie (tested).
- Version 0.2.0. The OpenCode entries still export only the two chat plugins.

Run at the reviewed head e776afc, on mote (macOS, sandbox HOME):
- `bun test` in packages/minimax: 123 pass, 0 fail, 12 files.
- `bun scripts/check.mjs`: ok (minimax ✓).
- Broken by hand: with `send` back on plain fetch, "tool redirects to another host stop before a 401 or token rotation" goes red (1 fail), and green again when restored.
- The first review's probe (307 to another host, 401 there) spent 3 refreshes over 3 calls at 2467992. The new test covers the same case: 0 refreshes and 0 requests reaching the other host.
- Checked against magpie's plugin host (internal/plugin/host.js): ./server is tried first, `directory` is magpie's config dir, and auth.set with a `minimax-code#…` id writes that key.

Not tried: a real MiniMax account (search, generation, billing), and a real mainland-China network against the Global site.
2026-11-03 19:43:11 +08:00

45 lines
2.7 KiB
JavaScript

// MiniMax's native search is separate from the Connector catalog.
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v)
const schema = (properties, required = []) => ({ type: "object", properties, required, additionalProperties: false })
const string = { type: "string", minLength: 1 }
const sites = ["minimax-code", "minimax-code-global"]
const freshness = ["noLimit", "day", "week", "month", "year"]
const searchTypes = ["search", "videos", "places", "news", "shopping"]
function args(value, allowed) {
if (!object(value)) throw new Error("arguments must be an object")
for (const key of Object.keys(value)) if (!allowed.includes(key)) throw new Error("unknown argument: " + key)
return value
}
function text(value, name) {
if (typeof value !== "string" || !value.trim()) throw new Error(name + " must be a non-empty string")
return value
}
export function createWebTools(request) {
return {
web_search: {
description: "Search the live web through MiniMax Code for facts, news, videos, places and shopping. Return the upstream sources and search metadata. Cite result URLs; use an available webpage-reading tool to read a source page.",
args: schema({
query: { ...string, description: "Search query" },
count: { type: "integer", minimum: 1, description: "Maximum results (server default 10)" },
freshness: { type: "string", enum: freshness },
search_type: { type: "string", enum: searchTypes },
site: { type: "string", enum: sites, default: "minimax-code" },
account: { ...string, description: "Full stored account key for the selected site, such as minimax-code#xxxxxx. Defaults to that site's first stored account." },
}, ["query"]),
async execute(value, ctx = {}) {
const { site = "minimax-code", account, ...input } = args(value, ["query", "count", "freshness", "search_type", "site", "account"])
text(input.query, "query")
if (!sites.includes(site)) throw new Error("unknown MiniMax Code site")
if (account !== undefined) text(account, "account")
if (input.count !== undefined && (!Number.isInteger(input.count) || input.count < 1)) throw new Error("count must be a positive integer")
if (input.freshness !== undefined && !freshness.includes(input.freshness)) throw new Error("invalid freshness")
if (input.search_type !== undefined && !searchTypes.includes(input.search_type)) throw new Error("invalid search_type")
ctx.abort?.throwIfAborted()
const { base_resp, ...payload } = await request(site, "/mavis/api/v1/mcp/web_search", input, { account, signal: ctx.abort, timeoutMs: 120000 })
return payload
},
},
}
}