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.
28 lines
1.7 KiB
JavaScript
28 lines
1.7 KiB
JavaScript
import "./nonet.mjs"
|
|
import { expect, test } from "bun:test"
|
|
import { createWebTools } from "./web-tools.mjs"
|
|
|
|
test("native search forwards filters and account scope to its separate endpoint", async () => {
|
|
const calls = []
|
|
const abort = new AbortController().signal
|
|
const tools = createWebTools(async (...call) => { calls.push(call); return { base_resp: { status_code: 0 }, organic: [{ title: "Source", url: "https://example.com" }] } })
|
|
expect(await tools.web_search.execute({ query: "MiniMax", count: 3, freshness: "week", search_type: "news", site: "minimax-code-global", account: "minimax-code-global#second" }, { abort })).toEqual({ organic: [{ title: "Source", url: "https://example.com" }] })
|
|
expect(calls[0]).toEqual(["minimax-code-global", "/mavis/api/v1/mcp/web_search", { query: "MiniMax", count: 3, freshness: "week", search_type: "news" }, { account: "minimax-code-global#second", signal: abort, timeoutMs: 120000 }])
|
|
})
|
|
|
|
test("invalid search arguments and cancellation are caught before network", async () => {
|
|
let calls = 0
|
|
const tool = createWebTools(async () => { calls++; return {} }).web_search
|
|
for (const value of [null, {}, { query: " " }, { query: "x", count: 0 }, { query: "x", count: 1.5 }, { query: "x", freshness: "today" }, { query: "x", search_type: "image" }, { query: "x", site: "bad" }, { query: "x", headers: {} }]) {
|
|
await expect(tool.execute(value)).rejects.toThrow()
|
|
}
|
|
const controller = new AbortController()
|
|
controller.abort()
|
|
await expect(tool.execute({ query: "x" }, { abort: controller.signal })).rejects.toThrow()
|
|
expect(calls).toBe(0)
|
|
})
|
|
|
|
test("native web tools export only search", () => {
|
|
expect(Object.keys(createWebTools())).toEqual(["web_search"])
|
|
})
|