library: Magpie Image Recognition in Discover beside Magpie Image and Web Search (matrix0487 on Discord, #4653)
matrix0487 asked on Discord (#feedback) for all three of magpie's own MCP servers, image recognition, image generation and search, in the Library's Discover. Image generation and search were there; image recognition was an address to copy in Settings only (#4653). - `magpie mcp vision` (browsermcp.RunVision) relays stdio to the gateway's /mcp/magpie/vision, as `mcp search` does. analyze_image's relative image path is made one in the agent's folder on the way (imageFrom), since the gateway can't know where the agent runs; an absolute path, ~, a URL or a drive goes as written. - library: magpie-vision is a featured, opt-in server (no agents until picked), any binary's `mcp vision` is one server (serverKey), and it gets the 120s tool timeout (selfTimeout). - Settings › Models › Images: the Image recognition row has Give agents Magpie Image Recognition… / Turn on the Library, none with recognition off or in gateway mode. The three links are one helper, libWay, used by Image generation and Web search too (no budget raised: core 1,533,011 of 1,533,105). - Never a dead tool: Discover lists all three whatever is set up, and one that can't answer yet says why (gateway.OwnUnready, set by /api/library/market/servers as `unready`): a "Not set up yet" badge on its card with the reason as its title, and the reason in its sheet (nothing set up, or turned off in Settings / Plugins). It can still be added; its tools already answer with the same reason until then. - Strings in en, zh, zh-TW, ja, de; docs/subsystems/library.md. Run, all on mote (macOS 27) through mote-run, at this head's tree (rebased on21882a68d): - gofmt -l internal/: clean. go vet darwin; GOOS=linux -tags nogui; GOOS=windows: browsermcp, cli, library, gateway, gui, imagemcp ok. - go test -timeout 45m: internal/library, browsermcp, cli, imagemcp ok; internal/gateway ok (whole package, 556s, before the rebase; OwnMCP, OwnUnready, VisionMCP, SearchMCP after it). internal/gui: three reds, none from this change, each red on origin/main21882a68dtoo: TestSettingsSaveKeepsWhatItDoesNotSend (BusyLoad, from8d8df0639, filed #4739), TestMainWindowCorners/macOS_26_SDK (#3949), TestColdTurnsTaken (#4510). Budget tests ok. - New: TestMagpieImageRecognitionIsOptIn, TestVisionBridgePassesLines, TestImageFromLeavesTheRest, TestOwnUnreadyWhileNotListed. - New GUI test vision-mcp-library.test.cjs: chromium + webkit, en, zh, zh-TW, ja, de, 1100 and 420px (link opens the sheet with its hint and unready line; Library off → Turn on the Library; one added opens Discover with all three, only the unready one badged, inside its card; gateway mode and recognition off show no link; no horizontal overflow, no page errors): 206/206 with search-mcp-library and images-library-way. One84870f17(old code), chromium: every link and Discover case red. - i18n-keys, gui-de, gui-zh-tw ok; gui-ja's one red is #4580, the same on origin/main21882a68d. - Broken by hand: serverKey without "vision" → TestMagpieImageRecognitionIsOptIn red; imageFrom not joining the folder → both browsermcp tests red. - Real use, sandbox HOME on mote, nogui build, `magpie serve` on 127.0.0.1:3591: `magpie mcp vision` initialize / tools/list answered; analyze_image of shots/a.png says "magpie has no model that sees images…"; missing/b.png names /…/work/missing/b.png (relative path resolved); an extra argument exits 1; gateway down answers id 9 with "magpie isn't running, so Magpie Image Recognition can't be reached". Not tried: analyze_image against a real seeing model through the relay (the sandbox had no provider; the gateway path is the one /mcp/magpie/vision already serves); a real agent adding it from Discover; WSL (unchanged, the MCP router serves it there); the whole GUI suite, queued after mote's running one. Reported-by: matrix0487 (Discord) Closes #4653
This commit is contained in:
@@ -62,8 +62,10 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
- Every other agent (Cursor, Copilot and Goose, whose lists are allow-lists only, Zed, Kimi, Pi, Grok, Devin, Antigravity, Alma, dsh, omp, ZCode, Command Code, Cline, WorkBuddy, CodeBuddy, Droid, Claude Desktop, MiMo Code, DevEco Code, a plugin's agent) gets the server whole. `AgentView.ToolsOff` is false for it, and the open list of tools names those given the server as unable to turn off single tools. A project's file and Copy config… carry no tools turned off either.
|
||||
magpie records what it added (`Applied.ToolsOff` per server for a list in an entry, `Applied.ToolRules` for Claude Code's rules and OpenCode's keys) and takes back only that (`offList`): a name, rule or key the user had already is theirs and stays when the tool is turned on again, and an OpenCode key the user set to `true` is never written over. A list or `permissions.deny` that isn't a list of names is a problem, never taken as empty, and the file is left as it is. The key, and Claude Code's `permissions` or OpenCode's `tools`, goes when magpie's were the last in it. The editor's save sends no tools, so `SaveServer` keeps those turned off.
|
||||
- With the MCP router on (`MCPHub`), an agent that takes a Streamable HTTP server is given magpie's one `magpie` entry in place of the Library servers ticked for it, and each server's own entry again when it is turned off. One that can't, or has an entry called magpie of its own, or whose library has a server called magpie, keeps each server's own entry, and the page says why ([MCP router](mcp-router.md)).
|
||||
- magpie's own MCP servers (`magpie-image`, `magpie-browser`, `magpie-web-search`, and any `mcp …` run by a program named magpie) run this computer's magpie (#1439). `InstallServer` gives it magpie by full path (`update.Program`: the AppImage, not its mount; Homebrew's opt link, not the Cellar), and that path is right only on this computer. When the library is read, and after every change, `heal` points such a server whose program isn't on this computer (another system's path, a magpie moved out of Downloads, a bare `magpie`) at this magpie, so the agents and `CheckServers` get it; a magpie program that is here (another build) and a server run by any other program stay as they are. A carried library (`Collect`, for a backup or a WebDAV or S3 sync) names it as plain `magpie`, so two computers carry the same bundle and a sync doesn't write one's path over the other's; `Put` then reads it as that computer's magpie. [`self_here.go`](../../internal/library/self_here.go)
|
||||
- magpie's own MCP servers (`magpie-image`, `magpie-browser`, `magpie-web-search`, `magpie-vision`, and any `mcp …` run by a program named magpie) run this computer's magpie (#1439). `InstallServer` gives it magpie by full path (`update.Program`: the AppImage, not its mount; Homebrew's opt link, not the Cellar), and that path is right only on this computer. When the library is read, and after every change, `heal` points such a server whose program isn't on this computer (another system's path, a magpie moved out of Downloads, a bare `magpie`) at this magpie, so the agents and `CheckServers` get it; a magpie program that is here (another build) and a server run by any other program stay as they are. A carried library (`Collect`, for a backup or a WebDAV or S3 sync) names it as plain `magpie`, so two computers carry the same bundle and a sync doesn't write one's path over the other's; `Put` then reads it as that computer's magpie. [`self_here.go`](../../internal/library/self_here.go)
|
||||
- Magpie Web Search (`magpie-web-search`, `searchServer` in [`market.go`](../../internal/library/market.go)) is the featured, opt-in server for magpie's web search: `magpie mcp search` (`RunSearch` in [`browsermcp.go`](../../internal/browsermcp/browsermcp.go)) passes each stdio message to the gateway's `/mcp/magpie/web-search`, as `magpie mcp browser` does to its own path, with no browser session. Its sheet says each search goes where Settings › Models › Web search sends it. That page's MCP server row (`#searchMcpRow`) keeps the address to copy, and under its words Give agents Magpie Web Search… opens the sheet in the Library (`magpie.call("library", "server", "magpie-web-search")`), Turn on the Library when the Library is off, and nothing in gateway mode, as Settings › Images does for Magpie Image (lutra_fs on Discord: the search was in Settings and not in the Library; `search-mcp-library.test.cjs`). Each agent is given a 120-second tool timeout for it (`selfTimeout`). An agent in WSL is not given it directly, as with Magpie Browser; the MCP router serves it there.
|
||||
- Magpie Image Recognition (`magpie-vision`, `visionServer` in [`market.go`](../../internal/library/market.go)) is the featured, opt-in server for image recognition, beside Magpie Image and Magpie Web Search (matrix0487 on Discord: Discover had two of magpie's three): `magpie mcp vision` (`RunVision` in [`browsermcp.go`](../../internal/browsermcp/browsermcp.go)) passes each stdio message to the gateway's `/mcp/magpie/vision`, and makes `analyze_image`'s relative `image` path one in the agent's own folder on the way (`imageFrom`), since the gateway can't know where the agent runs; an absolute path, `~`, a URL or a drive goes as written. Its sheet says each image goes to Settings › Models › Images › Image recognition's model. That row has Give agents Magpie Image Recognition… (`libWay` in app.js, shared with Images' and Web search's links), Turn on the Library with the Library off, and nothing with recognition off or in gateway mode (`vision-mcp-library.test.cjs`). It gets the same 120-second tool timeout and the same WSL rule as Magpie Web Search.
|
||||
- Discover's featured list is the same with nothing set up: one of magpie's own whose model or search isn't there yet, or which Settings turned off, carries `unready` (`gateway.OwnUnready`, set by the GUI's `/api/library/market/servers`), shown as a Not set up yet badge on its card and the full reason in its sheet. It can still be added, since it answers once that is set up, and until then its tools answer with the same reason, so no agent is given a tool that fails without a word.
|
||||
- A carried library (`Collect`) has every file of each skill, its templates and other binaries included, up to `maxCarried` (16 MiB) a file and `maxCarriedAll` (32 MiB) in all, chosen smallest first across the skills (`readSkills`), so every skill's text goes before any big file. The total keeps a sealed backup under the 64 MiB a sync reads: the files are base64 twice in it. What is left out is named in `Left`, and `Put` keeps this computer's copy of such a file in the skill it puts (`keepLeft`). [`carry.go`](../../internal/library/carry.go)
|
||||
- A skill can be turned off on this computer alone (`OffHere`, `SkillHere`; the row's power button, `magpie library skill off-here <name>` and `on-here`; hanslin1666 on Discord). No agent here gets it, whatever its `Agents` say (`gives`, which every reader of `Agents` for giving goes through: `syncSkills`, `desktop_skills.go`, `skill_changed.go`, `skill_edits.go`, `behind`, `Targets`). `Agents` stays what a sync carries, and the page leaves its chips as they are, faded. `Collect` never carries `OffHere`, so turning it off changes no part a sync uploads, and `Put` keeps this computer's `OffHere` for a skill it puts, so a sync from a computer that has it on, or gives it to more agents, never turns it on here. A library.json from before has no `offHere` and every skill stays on. Not covered: a project's skills; a library skill kept in `~/.agents/skills`, which agents read in place, until it is handed over (below); and a skill another computer removes, which takes the flag with it. [`skills.go`](../../internal/library/skills.go), [`carry.go`](../../internal/library/carry.go)
|
||||
- An MCP server can be kept to this computer (`Server.Local`; the editor's "This computer only" switch, `magpie library mcp add --local`, `magpie library mcp local <name> on|off`; huhuy72219405 on X). `Collect` never carries it (`carriedServers`), so a sync or a backup file never takes it to another computer, and turning a shared server local takes it out of what is carried: the other computers drop it at their next sync. `Put` (sync, join, Restore, Undo, a backup file) keeps every local server here, with its agents, and clears `Local` on what comes in (`putServers`). Another computer's server by the name of a local one doesn't take its place: it goes to `Library.Away`, given to no agent, not in the router, not checked, and carried on as it came, so a push from here never takes it from the computers that have it. `settleAway` runs on every change: while the name is local here the away copy stays; once no server of that name is left here (removed or renamed) it comes in as a sync would bring it; once a shared server has the name (local turned off) this computer's is the one carried. The router serves local servers like any other, since it runs on this computer. A carried subagent names its servers, a local one too; a computer without that server leaves it out of the agents' files, as any server the library hasn't. The TUI keeps the flag on edit and marks the row. (`TestLocalServerNotCarried`, `TestPutKeepsLocalServer`, `TestPutSameNameAsLocal`, `TestRestoreKeepsLocalServer`, `TestLocalServerThroughSync`, `mcp-local-server.test.cjs`) [`mcp_local.go`](../../internal/library/mcp_local.go), [`carry.go`](../../internal/library/carry.go)
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
// passed on the same way, with no session: the Library's Magpie Web
|
||||
// Search, which an agent is given as a command as it is Magpie Browser
|
||||
// (lutra_fs on Discord: the search was an address in Settings alone).
|
||||
// `magpie mcp vision` is image recognition's (gateway.VisionMCPPath), the
|
||||
// Library's Magpie Image Recognition (matrix0487 on Discord, #4653).
|
||||
package browsermcp
|
||||
|
||||
import (
|
||||
@@ -20,6 +22,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -44,6 +47,15 @@ func RunSearch(args []string) error {
|
||||
return serveSearch(os.Stdin, os.Stdout, gatewayBase())
|
||||
}
|
||||
|
||||
// RunVision serves the image recognition MCP server on stdin and stdout
|
||||
// until stdin ends.
|
||||
func RunVision(args []string) error {
|
||||
if len(args) > 0 {
|
||||
return fmt.Errorf("magpie mcp vision takes no arguments")
|
||||
}
|
||||
return serveVision(os.Stdin, os.Stdout, gatewayBase())
|
||||
}
|
||||
|
||||
func gatewayBase() string {
|
||||
base := strings.TrimRight(os.Getenv("MAGPIE_GATEWAY"), "/")
|
||||
if base == "" {
|
||||
@@ -73,9 +85,49 @@ func serveSearch(in io.Reader, out io.Writer, base string) error {
|
||||
return relay(in, &bridge{base: base, path: gateway.SearchMCPPath, title: "Magpie Web Search", client: &http.Client{Timeout: 5 * time.Minute}, out: out})
|
||||
}
|
||||
|
||||
// serveVision passes each line to the gateway's image recognition server.
|
||||
// A message may hold an image as a data URL, up to what the gateway takes
|
||||
// (32 MiB), and a look by a slow model takes minutes.
|
||||
func serveVision(in io.Reader, out io.Writer, base string) error {
|
||||
wd, _ := os.Getwd()
|
||||
return relay(in, &bridge{base: base, path: gateway.VisionMCPPath, title: "Magpie Image Recognition", client: &http.Client{Timeout: 5 * time.Minute}, out: out,
|
||||
most: 32 << 20, fix: func(b []byte) []byte { return imageFrom(b, wd) }})
|
||||
}
|
||||
|
||||
// imageFrom is the message b with analyze_image's image, when it is a path
|
||||
// relative to the agent's folder, made absolute against wd: the gateway,
|
||||
// which reads the file, doesn't know the agent's folder, and this process
|
||||
// was started in it. Any other message, or image, goes as it came.
|
||||
func imageFrom(b []byte, wd string) []byte {
|
||||
var m map[string]json.RawMessage
|
||||
if wd == "" || json.Unmarshal(b, &m) != nil || string(m["method"]) != `"tools/call"` {
|
||||
return b
|
||||
}
|
||||
var p map[string]json.RawMessage
|
||||
var a map[string]json.RawMessage
|
||||
var name, image string
|
||||
if json.Unmarshal(m["params"], &p) != nil || json.Unmarshal(p["name"], &name) != nil || name != "analyze_image" ||
|
||||
json.Unmarshal(p["arguments"], &a) != nil || json.Unmarshal(a["image"], &image) != nil {
|
||||
return b
|
||||
}
|
||||
image = strings.TrimSpace(image)
|
||||
low := strings.ToLower(image)
|
||||
if image == "" || filepath.IsAbs(image) || strings.HasPrefix(image, "~") || strings.Contains(low[:min(len(low), 12)], ":") {
|
||||
return b // absolute, the home's, or a URL (data:, http:, file:) or a drive (C:)
|
||||
}
|
||||
a["image"], _ = json.Marshal(filepath.Join(wd, image))
|
||||
p["arguments"], _ = json.Marshal(a)
|
||||
m["params"], _ = json.Marshal(p)
|
||||
out, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return b
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func relay(in io.Reader, s *bridge) error {
|
||||
sc := bufio.NewScanner(in)
|
||||
sc.Buffer(make([]byte, 64<<10), 16<<20)
|
||||
sc.Buffer(make([]byte, 64<<10), max(s.most, 16<<20))
|
||||
var wg sync.WaitGroup
|
||||
for sc.Scan() {
|
||||
line := bytes.TrimSpace(sc.Bytes())
|
||||
@@ -87,6 +139,9 @@ func relay(in io.Reader, s *bridge) error {
|
||||
continue
|
||||
}
|
||||
body := append([]byte(nil), line...)
|
||||
if s.fix != nil {
|
||||
body = s.fix(body)
|
||||
}
|
||||
wg.Add(1)
|
||||
// calls run side by side, as an agent may send the next before the
|
||||
// last is answered (a ping during a long wait)
|
||||
@@ -101,12 +156,15 @@ func relay(in io.Reader, s *bridge) error {
|
||||
|
||||
// bridge passes one stdio session's messages to the gateway's server at
|
||||
// path, title naming it when the gateway can't be reached; a session ""
|
||||
// sends no session header.
|
||||
// sends no session header. most is the longest line it reads (16 MiB when
|
||||
// 0), and fix, when set, makes each message what the gateway is sent.
|
||||
type bridge struct {
|
||||
base, path, title, session string
|
||||
client *http.Client
|
||||
mu sync.Mutex
|
||||
out io.Writer
|
||||
most int
|
||||
fix func([]byte) []byte
|
||||
}
|
||||
|
||||
func (s *bridge) write(b []byte) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -116,3 +118,103 @@ func TestSearchBridgePassesLines(t *testing.T) {
|
||||
t.Fatalf("gateway gone: %q", out.String())
|
||||
}
|
||||
}
|
||||
|
||||
// magpie mcp vision relays each line to the gateway's image recognition
|
||||
// server, a relative image path made the agent's folder's on the way
|
||||
// (the gateway can't know where the agent runs), and says so by id when
|
||||
// the gateway can't be reached (matrix0487 on Discord).
|
||||
func TestVisionBridgePassesLines(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
var paths, images []string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("Authorization") != "Bearer "+gateway.Token {
|
||||
http.Error(w, "wrong", 400)
|
||||
return
|
||||
}
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
var m struct {
|
||||
ID json.RawMessage
|
||||
Method string
|
||||
Params struct {
|
||||
Arguments struct{ Image string }
|
||||
}
|
||||
}
|
||||
json.Unmarshal(b, &m)
|
||||
mu.Lock()
|
||||
paths = append(paths, r.URL.Path)
|
||||
images = append(images, m.Params.Arguments.Image)
|
||||
mu.Unlock()
|
||||
if len(m.ID) == 0 {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{"jsonrpc": "2.0", "id": m.ID, "result": map[string]any{"method": m.Method}})
|
||||
}))
|
||||
defer srv.Close()
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in := strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"initialize"}` + "\n" +
|
||||
`{"jsonrpc":"2.0","method":"notifications/initialized"}` + "\n" +
|
||||
`{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"analyze_image","arguments":{"image":"shots/a.png","prompt":"what"}}}` + "\n")
|
||||
var out bytes.Buffer
|
||||
if err := serveVision(in, &out, srv.URL); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if lines := strings.Split(strings.TrimSpace(out.String()), "\n"); len(lines) != 2 || !strings.Contains(out.String(), `"id":2`) {
|
||||
t.Fatalf("out: %q", out.String())
|
||||
}
|
||||
if len(paths) != 3 || paths[0] != gateway.VisionMCPPath || paths[2] != gateway.VisionMCPPath || images[2] != filepath.Join(wd, "shots", "a.png") {
|
||||
t.Fatalf("paths %q, images %q", paths, images)
|
||||
}
|
||||
|
||||
out.Reset()
|
||||
srv.Close()
|
||||
if err := serveVision(strings.NewReader(`{"jsonrpc":"2.0","id":7,"method":"tools/list"}`+"\n"), &out, srv.URL); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(out.String(), `"id":7`) || !strings.Contains(out.String(), "Magpie Image Recognition can't be reached") {
|
||||
t.Fatalf("gateway gone: %q", out.String())
|
||||
}
|
||||
if err := RunVision([]string{"extra"}); err == nil {
|
||||
t.Fatal("an argument was taken")
|
||||
}
|
||||
}
|
||||
|
||||
// Only analyze_image's relative path is made the folder's: an absolute
|
||||
// path, the home's, a URL, a drive, another tool and another method go as
|
||||
// written, byte for byte.
|
||||
func TestImageFromLeavesTheRest(t *testing.T) {
|
||||
wd := filepath.Join(string(filepath.Separator)+"work", "proj")
|
||||
call := func(name, image string) string {
|
||||
return `{"jsonrpc":"2.0","id":"x-1","method":"tools/call","params":{"name":"` + name + `","arguments":{"image":"` + image + `"}}}`
|
||||
}
|
||||
abs := filepath.Join(wd, "abs.png")
|
||||
absJSON, _ := json.Marshal(abs)
|
||||
for _, line := range []string{
|
||||
`{"jsonrpc":"2.0","id":"x-1","method":"tools/call","params":{"name":"analyze_image","arguments":{"image":` + string(absJSON) + `}}}`,
|
||||
call("analyze_image", "~/a.png"),
|
||||
call("analyze_image", "https://example.com/a.png"),
|
||||
call("analyze_image", "data:image/png;base64,aGVsbG8="),
|
||||
call("analyze_image", "file:///a.png"),
|
||||
call("analyze_image", "C:/shots/a.png"),
|
||||
call("generate_image", "a.png"),
|
||||
`{"jsonrpc":"2.0","id":3,"method":"tools/list","params":{"image":"a.png"}}`,
|
||||
`not json`,
|
||||
} {
|
||||
if got := string(imageFrom([]byte(line), wd)); got != line {
|
||||
t.Errorf("%s\n became %s", line, got)
|
||||
}
|
||||
}
|
||||
got := imageFrom([]byte(call("analyze_image", "a.png")), wd)
|
||||
var m struct {
|
||||
ID string
|
||||
Params struct {
|
||||
Arguments struct{ Image string }
|
||||
}
|
||||
}
|
||||
if err := json.Unmarshal(got, &m); err != nil || m.ID != "x-1" || m.Params.Arguments.Image != filepath.Join(wd, "a.png") {
|
||||
t.Fatalf("relative: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,6 +339,9 @@ func run(args []string) error {
|
||||
if len(args) > 1 && args[1] == "search" {
|
||||
return browsermcp.RunSearch(args[2:])
|
||||
}
|
||||
if len(args) > 1 && args[1] == "vision" {
|
||||
return browsermcp.RunVision(args[2:])
|
||||
}
|
||||
return imagemcp.Run(args[1:])
|
||||
case "claude-mcp-helper": // internal: stdio MCP subprocess spawned by Claude Code
|
||||
return claudebridge.RunMCP(args[1:])
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/gwtool"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// OwnMCPPath lists the MCP servers magpie serves itself (web search,
|
||||
@@ -57,3 +59,38 @@ func ownMCP() []OwnMCP {
|
||||
func (s *Server) ownMCPList(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, 200, map[string]any{"servers": ownMCP()})
|
||||
}
|
||||
|
||||
// OwnUnready is why magpie's own server name (Magpie Web Search, Magpie
|
||||
// Image Recognition, Magpie Image) can't answer yet, in English for the
|
||||
// Library's Discover to say on its row: "" while ownMCP lists it, and for
|
||||
// any other name. Its tools answer all the same, with how to set it up
|
||||
// (matrix0487 on Discord: all three in Discover, never a dead tool).
|
||||
func OwnUnready(name string) string {
|
||||
switch name {
|
||||
case "magpie-web-search":
|
||||
switch {
|
||||
case canSearch():
|
||||
return ""
|
||||
case !searchServed():
|
||||
return "Web search is off in Plugins › Built-in: its tools say so until it is turned on"
|
||||
}
|
||||
return "Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so"
|
||||
case "magpie-vision":
|
||||
if _, ok := seer(); ok {
|
||||
return ""
|
||||
}
|
||||
if provider.HeldSettings().Vision == "off" {
|
||||
return "Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there"
|
||||
}
|
||||
return "No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then"
|
||||
case imageServerName:
|
||||
if _, ok := drawer(); ok {
|
||||
return ""
|
||||
}
|
||||
if settings.Load().ImageGen == "off" {
|
||||
return "Image generation is off in Settings → Models → Images: its tools say so until a model is picked there"
|
||||
}
|
||||
return "No model that draws images is set up yet: it draws once a provider with an image model is added, and says so until then"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package gateway
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/gwtool"
|
||||
@@ -129,3 +130,43 @@ func TestOwnMCPListsPluginToolsWhileOn(t *testing.T) {
|
||||
t.Fatalf("plugins/tools on: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Each of magpie's own servers the Library's Discover lists says why it
|
||||
// can't answer yet exactly while ownMCP leaves it out, and tells nothing
|
||||
// set up from turned off in Settings (matrix0487 on Discord: all three in
|
||||
// Discover, never a dead tool).
|
||||
func TestOwnUnreadyWhileNotListed(t *testing.T) {
|
||||
fresh(t)
|
||||
toolsAre(t, 0)
|
||||
for _, n := range []string{"magpie-web-search", "magpie-vision", imageServerName} {
|
||||
if why := OwnUnready(n); !strings.Contains(why, "yet") {
|
||||
t.Errorf("%s with nothing set up: %q", n, why)
|
||||
}
|
||||
}
|
||||
if why := OwnUnready("magpie-browser"); why != "" {
|
||||
t.Errorf("magpie-browser: %q", why)
|
||||
}
|
||||
s, _ := eyed(t)
|
||||
if got := ownMCPNames(t, s); got["magpie-vision"] == "" || OwnUnready("magpie-vision") != "" {
|
||||
t.Fatalf("a model sees: listed %v, unready %q", got, OwnUnready("magpie-vision"))
|
||||
}
|
||||
noVision(t)
|
||||
if why := OwnUnready("magpie-vision"); !strings.Contains(why, "off in Settings") {
|
||||
t.Fatalf("vision off: %q", why)
|
||||
}
|
||||
st := settings.Load()
|
||||
st.ImageGen = "off"
|
||||
if err := settings.Save(st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if why := OwnUnready(imageServerName); !strings.Contains(why, "off in Settings") {
|
||||
t.Fatalf("image generation off: %q", why)
|
||||
}
|
||||
stop := gwtool.Gate() // plugins/search off
|
||||
defer stop()
|
||||
searchOn()
|
||||
defer func() { searchOn = gwtool.Serve(gwtool.WebSearch) }()
|
||||
if why := OwnUnready("magpie-web-search"); !strings.Contains(why, "Plugins") {
|
||||
t.Fatalf("plugins/search off: %q", why)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4677,7 +4677,7 @@ input[type="checkbox"]:disabled { opacity: .45; }
|
||||
/* a disabled model's pattern, as typed (#1867): an id or a glob */
|
||||
.disabled-model .name { font-family: var(--code); font-size: 12px; overflow-wrap: anywhere; }
|
||||
/* Settings › Images: the way to the Magpie Image tool, under its words (#2091) */
|
||||
.image-gen-how .link, .search-mcp-how .link { padding-left: 0; padding-right: 0; white-space: normal; text-align: start; }
|
||||
.lib-way .link { padding-left: 0; padding-right: 0; white-space: normal; text-align: start; }
|
||||
/* Settings › Proxy's Test result (#2076): under the row's text */
|
||||
.row.pref .sub.proxy-check { margin-top: 3px; white-space: normal; overflow-wrap: anywhere; }
|
||||
.proxy-check[hidden] { display: none; }
|
||||
|
||||
+32
-28
@@ -21426,6 +21426,7 @@ function renderImages(s, keep) {
|
||||
// a custom provider's model nothing says takes images isn't offered: say
|
||||
// where it is marked, by the editor's own words (nexnull on Discord)
|
||||
const notMarked = s.visionNotMarked || [];
|
||||
if (v !== "off") who.append(...libWay("magpie-vision", t("Give agents Magpie Image Recognition…"), "vision-mcp-lib"));
|
||||
if (notMarked.length && v !== "off") who.append(el("div", "sub vision-not-marked", t("Models of {providers} aren’t listed until marked in their provider’s {names} › {images}",
|
||||
{ providers: notMarked.join(", "), names: t("Names & levels"), images: t("Accepts images") })));
|
||||
b.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "vision", label: "model", value: v, options: [
|
||||
@@ -21453,6 +21454,35 @@ function renderImages(s, keep) {
|
||||
mcpRow("imageMcpRow", "/mcp/magpie/image", t("Image generation MCP server"), t("Agents can add image generation as an MCP server (Streamable HTTP) with generate_image, generate_video and generation_result tools, which draw with the Image generation model. An image comes back in the answer and at a URL kept for an hour, a video at a URL; nothing is saved in the agent's project. From another computer, send a gateway key as Authorization: Bearer <key>."));
|
||||
}
|
||||
|
||||
// libWay: a row's way to give agents magpie's own server name in the
|
||||
// Library, or to turn it on; none in gateway mode (#2091, matrix0487)
|
||||
function libWay(name, label, cls) {
|
||||
if (gatewayMode) return [];
|
||||
const libOff = featuresOff.has("library");
|
||||
const go = el("button", "link " + cls, libOff ? t("Turn on the Library") : label);
|
||||
go.type = "button";
|
||||
go.onclick = async () => {
|
||||
if (!libOff) {
|
||||
if (await show("library") !== false) magpie.call("library", "server", name);
|
||||
return;
|
||||
}
|
||||
go.disabled = true;
|
||||
try {
|
||||
const next = await api("plugins/builtin", { id: "library", on: true });
|
||||
if (state.settings) state.settings.builtins = next;
|
||||
applyFeatures(next);
|
||||
status(t("The Library is on"), "ok", 1500);
|
||||
renderSettings();
|
||||
} catch (err) {
|
||||
go.disabled = false;
|
||||
status(t(err.message), "err");
|
||||
}
|
||||
};
|
||||
const line = el("div", "sub lib-way");
|
||||
line.append(go);
|
||||
return [line];
|
||||
}
|
||||
|
||||
// renderImageGen: the model magpie's generate_image tool draws with — the
|
||||
// one magpie picks, one named, or none — and where agents are given the tool.
|
||||
function renderImageGen(s, keep, box) {
|
||||
@@ -21469,10 +21499,7 @@ function renderImageGen(s, keep, box) {
|
||||
const r = el("div", "row pref");
|
||||
r.id = "imageGenRow";
|
||||
const who = el("div", "who");
|
||||
// An agent draws once it has the Magpie Image tool, which the Library
|
||||
// gives it. The Library can be switched off (Essentials leaves it off)
|
||||
// and gateway mode has none, so the row says how to get there from
|
||||
// where the reader is, and takes them (#2091, nailuoGG)
|
||||
// the Library gives agents the tool, and can be off (#2091, nailuoGG)
|
||||
const libOff = featuresOff.has("library");
|
||||
const sub = el("div", "sub wraps",
|
||||
v === "off" ? t("Agents given Magpie Image can't generate images or videos: the tool says it is off")
|
||||
@@ -21480,30 +21507,7 @@ function renderImageGen(s, keep, box) {
|
||||
: libOff ? t("The model Magpie Image draws with. Agents get the Magpie Image tool from the Library, which is turned off in Plugins › Built-in; images are saved in their project")
|
||||
: t("The model Magpie Image draws with. Agents get the Magpie Image tool from the Library; images are saved in their project"));
|
||||
who.append(el("div", "name", t("Image generation")), sub);
|
||||
if (v !== "off" && !gatewayMode) {
|
||||
const go = el("button", "link image-gen-tool", libOff ? t("Turn on the Library") : t("Give agents Magpie Image…"));
|
||||
go.type = "button";
|
||||
go.onclick = async () => {
|
||||
if (!libOff) {
|
||||
if (await show("library") !== false) magpie.call("library", "server", "magpie-image");
|
||||
return;
|
||||
}
|
||||
go.disabled = true;
|
||||
try {
|
||||
const next = await api("plugins/builtin", { id: "library", on: true });
|
||||
if (state.settings) state.settings.builtins = next;
|
||||
applyFeatures(next);
|
||||
status(t("The Library is on"), "ok", 1500);
|
||||
renderSettings();
|
||||
} catch (err) {
|
||||
go.disabled = false;
|
||||
status(t(err.message), "err");
|
||||
}
|
||||
};
|
||||
const line = el("div", "sub image-gen-how");
|
||||
line.append(go);
|
||||
who.append(line);
|
||||
}
|
||||
if (v !== "off") who.append(...libWay("magpie-image", t("Give agents Magpie Image…"), "image-gen-tool"));
|
||||
// ChatGPT's images backend picks the model itself, so its one entry says
|
||||
// so where it draws, picked or automatic (#1865)
|
||||
const draws = v === "off" || gone ? "" : v ? shown : s.imageGenAuto;
|
||||
|
||||
@@ -999,6 +999,14 @@ const I18N = {
|
||||
"Give agents Magpie Image…": "把 Magpie Image 添加给 Agent…",
|
||||
"Give agents Magpie Web Search…": "把 Magpie Web Search 添加给 Agent…",
|
||||
"Search the web with the search set in Magpie (Settings → Models → Web search), and read a page by its URL.": "用 Magpie 中设置的搜索(设置 → 模型 → 网页搜索)搜索网页,并按 URL 读取网页。",
|
||||
"Give agents Magpie Image Recognition…": "把 Magpie Image Recognition 添加给 Agent…",
|
||||
"Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.": "用 Magpie 中设置的识图模型(设置 → 模型 → 图像)读取图片(文件、URL 或截图),供看不到图片的模型使用。",
|
||||
"Web search is off in Plugins › Built-in: its tools say so until it is turned on": "联网搜索已在 插件 › 内置 中关闭:重新开启前,它的工具会提示这一点",
|
||||
"Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "还没有可用的搜索:在 设置 → 模型 → 联网搜索 添加搜索 API,或添加能搜索的供应商。在此之前,它的工具会提示这一点",
|
||||
"Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "识图已在 设置 → 模型 → 图像 中关闭:在那里选好模型前,它的工具会提示这一点",
|
||||
"No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then": "还没有能识图的模型:添加带识图模型的供应商后即可识图,在此之前它会提示这一点",
|
||||
"Image generation is off in Settings → Models → Images: its tools say so until a model is picked there": "生图已在 设置 → 模型 → 图像 中关闭:在那里选好模型前,它的工具会提示这一点",
|
||||
"No model that draws images is set up yet: it draws once a provider with an image model is added, and says so until then": "还没有能生图的模型:添加带生图模型的供应商后即可生图,在此之前它会提示这一点",
|
||||
"The Library is on": "资源库已启用",
|
||||
"Agents given Magpie Image can't generate images or videos: the tool says it is off": "已装 Magpie Image 的 Agent 无法生成图片或视频,工具会提示已关闭",
|
||||
"no model that draws": "没有能生图的模型",
|
||||
@@ -5337,6 +5345,14 @@ const I18N = {
|
||||
"Give agents Magpie Image…": "把 Magpie Image 新增給 Agent…",
|
||||
"Give agents Magpie Web Search…": "把 Magpie Web Search 新增給 Agent…",
|
||||
"Search the web with the search set in Magpie (Settings → Models → Web search), and read a page by its URL.": "用 Magpie 中設定的搜尋(設定 → 模型 → 網頁搜尋)搜尋網頁,並依 URL 讀取網頁。",
|
||||
"Give agents Magpie Image Recognition…": "把 Magpie Image Recognition 新增給 Agent…",
|
||||
"Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.": "用 Magpie 中設定的識圖模型(設定 → 模型 → 影像)讀取圖片(檔案、URL 或截圖),供看不到圖片的模型使用。",
|
||||
"Web search is off in Plugins › Built-in: its tools say so until it is turned on": "聯網搜尋已在 外掛 › 內建 中關閉:重新開啟前,它的工具會提示這一點",
|
||||
"Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "還沒有可用的搜尋:在 設定 → 模型 → 聯網搜尋 新增搜尋 API,或新增能搜尋的供應商。在此之前,它的工具會提示這一點",
|
||||
"Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "識圖已在 設定 → 模型 → 影像 中關閉:在那裡選好模型前,它的工具會提示這一點",
|
||||
"No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then": "還沒有能識圖的模型:新增帶識圖模型的供應商後即可識圖,在此之前它會提示這一點",
|
||||
"Image generation is off in Settings → Models → Images: its tools say so until a model is picked there": "生圖已在 設定 → 模型 → 影像 中關閉:在那裡選好模型前,它的工具會提示這一點",
|
||||
"No model that draws images is set up yet: it draws once a provider with an image model is added, and says so until then": "還沒有能生圖的模型:新增帶生圖模型的供應商後即可生圖,在此之前它會提示這一點",
|
||||
"The Library is on": "資源庫已啟用",
|
||||
"Agents given Magpie Image can't generate images or videos: the tool says it is off": "已裝 Magpie Image 的 Agent 無法生成圖片或影片,工具會提示已關閉",
|
||||
"no model that draws": "沒有能生圖的模型",
|
||||
@@ -9646,6 +9662,14 @@ const I18N = {
|
||||
"Give agents Magpie Image…": "エージェントに Magpie Image を付与…",
|
||||
"Give agents Magpie Web Search…": "エージェントに Magpie Web Search を付与…",
|
||||
"Search the web with the search set in Magpie (Settings → Models → Web search), and read a page by its URL.": "Magpie で設定した検索(設定 → モデル → Web 検索)で Web を検索し、URL でページを読み込みます。",
|
||||
"Give agents Magpie Image Recognition…": "エージェントに Magpie Image Recognition を付与…",
|
||||
"Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.": "Magpie で設定した画像認識モデル(設定 → モデル → 画像)で画像(ファイル、URL、スクリーンショット)を読み取ります。画像を見られないモデル向けです。",
|
||||
"Web search is off in Plugins › Built-in: its tools say so until it is turned on": "ウェブ検索は プラグイン › 内蔵 でオフになっています:オンにするまで、ツールはそのことを伝えます",
|
||||
"Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "まだ検索できるものがありません:設定 → モデル → ウェブ検索 で検索 API を追加するか、検索できるプロバイダを追加してください。それまではツールがそのことを伝えます",
|
||||
"Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "画像認識は 設定 → モデル → 画像 でオフになっています:そこでモデルを選ぶまで、ツールはそのことを伝えます",
|
||||
"No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then": "画像を認識できるモデルがまだありません:対応するプロバイダを追加すると画像を読み取れます。それまではそのことを伝えます",
|
||||
"Image generation is off in Settings → Models → Images: its tools say so until a model is picked there": "画像生成は 設定 → モデル → 画像 でオフになっています:そこでモデルを選ぶまで、ツールはそのことを伝えます",
|
||||
"No model that draws images is set up yet: it draws once a provider with an image model is added, and says so until then": "画像を生成できるモデルがまだありません:画像モデルのあるプロバイダを追加すると生成できます。それまではそのことを伝えます",
|
||||
"The Library is on": "ライブラリをオンにしました",
|
||||
"Agents given Magpie Image can't generate images or videos: the tool says it is off": "Magpie Image を付与されたエージェントは画像や動画を生成できません:ツールがオフであることを伝えます",
|
||||
"no model that draws": "画像を生成できるモデルがありません",
|
||||
@@ -13970,6 +13994,14 @@ const I18N = {
|
||||
"Give agents Magpie Image…": "Agenten Magpie Image geben…",
|
||||
"Give agents Magpie Web Search…": "Agenten Magpie Web Search geben…",
|
||||
"Search the web with the search set in Magpie (Settings → Models → Web search), and read a page by its URL.": "Das Web mit der in Magpie eingestellten Suche durchsuchen (Einstellungen → Modelle → Websuche) und eine Seite über ihre URL lesen.",
|
||||
"Give agents Magpie Image Recognition…": "Agenten Magpie Image Recognition geben…",
|
||||
"Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.": "Ein Bild (eine Datei, eine URL, einen Screenshot) mit dem in Magpie eingestellten Bilderkennungsmodell lesen (Einstellungen → Modelle → Bilder), für ein Modell, das keine Bilder sieht.",
|
||||
"Web search is off in Plugins › Built-in: its tools say so until it is turned on": "Die Websuche ist unter Erweiterungen › Eingebaut ausgeschaltet: Ihre Tools sagen das, bis sie eingeschaltet wird",
|
||||
"Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "Noch sucht nichts: Füge unter Einstellungen → Modelle → Websuche eine Such-API hinzu oder einen Anbieter, der suchen kann. Bis dahin sagen ihre Tools das",
|
||||
"Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "Die Bilderkennung ist unter Einstellungen → Modelle → Bilder ausgeschaltet: Ihr Tool sagt das, bis dort ein Modell gewählt ist",
|
||||
"No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then": "Noch ist kein Modell eingerichtet, das Bilder sieht: Es liest Bilder, sobald ein Anbieter mit einem solchen hinzugefügt ist, und sagt das bis dahin",
|
||||
"Image generation is off in Settings → Models → Images: its tools say so until a model is picked there": "Die Bilderzeugung ist unter Einstellungen → Modelle → Bilder ausgeschaltet: Ihre Tools sagen das, bis dort ein Modell gewählt ist",
|
||||
"No model that draws images is set up yet: it draws once a provider with an image model is added, and says so until then": "Noch ist kein Modell eingerichtet, das Bilder erzeugt: Es erzeugt Bilder, sobald ein Anbieter mit einem Bildmodell hinzugefügt ist, und sagt das bis dahin",
|
||||
"The Library is on": "Die Bibliothek ist an",
|
||||
"Agents given Magpie Image can't generate images or videos: the tool says it is off": "Agenten mit Magpie Image können keine Bilder oder Videos erzeugen: das Tool meldet, dass es ausgeschaltet ist",
|
||||
"no model that draws": "kein Modell zur Bilderzeugung",
|
||||
|
||||
@@ -5851,6 +5851,7 @@ magpie.plugin("library", (ctx) => {
|
||||
const meta = el("div", "mk-meta");
|
||||
if (x.publisher) meta.append(el("span", "mk-pub", x.publisher));
|
||||
meta.append(el("span", "mk-badge", runsLabel(x)));
|
||||
if (x.unready) { const u = el("span", "mk-badge mk-unready", t("Not set up yet")); u.title = t(x.unready); meta.append(u); }
|
||||
if (needsKey(x)) { const k = el("span", "mk-badge mk-needs"); k.append(svg(GLYPH.key, 11, 1.5)); k.title = t("Needs {what} to add", { what: x.inputs.filter((i) => i.required).map((i) => t(i.label)).join(", ") }); meta.append(k); }
|
||||
who.append(meta);
|
||||
top.append(logo(x.icon, x.title || x.name), who);
|
||||
@@ -5897,7 +5898,12 @@ magpie.plugin("library", (ctx) => {
|
||||
ed.append(browserSetup());
|
||||
} else if (x.name === "magpie-web-search") {
|
||||
ed.append(el("p", "mk-hint", t("Pick the agents that may search with it: each search goes where Settings → Models → Web search sends it, and costs what that charges.")));
|
||||
} else if (x.name === "magpie-vision") {
|
||||
ed.append(el("p", "mk-hint", t("Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.")));
|
||||
} else if (x.optIn) ed.append(el("p", "mk-hint", t("Pick the agents that may generate images: each image costs what the model set in Settings → Images charges.")));
|
||||
// one of magpie's own that can't answer yet says why, and is added all
|
||||
// the same: it answers once that is set up, its tools saying how
|
||||
if (x.unready) ed.append(el("p", "mk-hint mk-unready", t(x.unready)));
|
||||
const firsts = [];
|
||||
for (const i of x.inputs || []) {
|
||||
const f = field2("", i.placeholder || (i.where === "env" ? i.key : ""), (v) => { values[i.key] = v.trim(); });
|
||||
@@ -6107,7 +6113,8 @@ magpie.plugin("library", (ctx) => {
|
||||
open: () => (loading = load()),
|
||||
relang: () => load(),
|
||||
// one of the market's servers up close, from another page (Settings ›
|
||||
// Images' Magpie Image, #2091, and Settings › Models' Magpie Web Search): its sheet over the MCP servers tab, to
|
||||
// Images' Magpie Image, #2091, Magpie Image Recognition, and Settings ›
|
||||
// Models' Magpie Web Search): its sheet over the MCP servers tab, to
|
||||
// pick the agents that get it; one already in the library is on that
|
||||
// tab's list, which opens with nothing over it
|
||||
server: async (name) => {
|
||||
|
||||
@@ -131,6 +131,8 @@ magpie.strings({
|
||||
"It will be removed from the library and the agents it was given to.": "这将从资源库及使用它的 Agent 中移除它。",
|
||||
"Pick the agents that may generate images: each image costs what the model set in Settings → Images charges.": "选择可以生图的 Agent:每张图按 设置 → 图像 里所选模型的价格计费。",
|
||||
"Pick the agents that may search with it: each search goes where Settings → Models → Web search sends it, and costs what that charges.": "选择可以用它搜索的 Agent:每次搜索都交给 设置 → 模型 → 网页搜索 所设的搜索,按其价格计费。",
|
||||
"Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.": "选择可以用它识图的 Agent:每张图都交给 设置 → 模型 → 图像 里所设的识图模型,按该模型的价格计费。",
|
||||
"Not set up yet": "尚未设置",
|
||||
"Pick the agents that may use your browser: they act in your tabs, signed in as you are.": "选择可以使用你浏览器的 Agent:它们会在你的标签页里,以你的登录身份操作。",
|
||||
"Set up the extension…": "安装扩展…",
|
||||
"Show the extension folder": "打开扩展文件夹",
|
||||
@@ -880,6 +882,8 @@ magpie.strings({
|
||||
"It will be removed from the library and the agents it was given to.": "這將從資源庫及使用它的 Agent 中移除它。",
|
||||
"Pick the agents that may generate images: each image costs what the model set in Settings → Images charges.": "選擇可以生圖的 Agent:每張圖按 設定 → 影像 裡所選模型的價格計費。",
|
||||
"Pick the agents that may search with it: each search goes where Settings → Models → Web search sends it, and costs what that charges.": "選擇可以用它搜尋的 Agent:每次搜尋都交給 設定 → 模型 → 網頁搜尋 所設的搜尋,按其價格計費。",
|
||||
"Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.": "選擇可以用它識圖的 Agent:每張圖都交給 設定 → 模型 → 影像 裡所設的識圖模型,按該模型的價格計費。",
|
||||
"Not set up yet": "尚未設定",
|
||||
"Pick the agents that may use your browser: they act in your tabs, signed in as you are.": "選擇可以使用你瀏覽器的 Agent:它們會在你的分頁裡,以你的登入身分操作。",
|
||||
"Set up the extension…": "安裝擴充功能…",
|
||||
"Show the extension folder": "打開擴充功能資料夾",
|
||||
@@ -1624,6 +1628,8 @@ magpie.strings({
|
||||
"Copies updated": "コピーを更新しました",
|
||||
"Pick the agents that may generate images: each image costs what the model set in Settings → Images charges.": "画像を生成できるエージェントを選んでください:画像 1 枚ごとに、設定 → 画像 で選んだモデルの料金がかかります。",
|
||||
"Pick the agents that may search with it: each search goes where Settings → Models → Web search sends it, and costs what that charges.": "これで検索できるエージェントを選んでください:検索はそれぞれ 設定 → モデル → Web 検索 の送り先に送られ、その料金がかかります。",
|
||||
"Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.": "これで画像を読み取れるエージェントを選んでください:画像はそれぞれ 設定 → モデル → 画像 で設定した画像認識モデルに送られ、そのモデルの料金がかかります。",
|
||||
"Not set up yet": "未設定",
|
||||
"Pick the agents that may use your browser: they act in your tabs, signed in as you are.": "ブラウザを使えるエージェントを選んでください:あなたのタブで、あなたのサインインのまま操作します。",
|
||||
"Set up the extension…": "拡張機能を設定…",
|
||||
"Show the extension folder": "拡張機能のフォルダを表示",
|
||||
@@ -2371,6 +2377,8 @@ magpie.strings({
|
||||
"Copies updated": "Kopien aktualisiert",
|
||||
"Pick the agents that may generate images: each image costs what the model set in Settings → Images charges.": "Agenten wählen, die Bilder erzeugen dürfen: jedes Bild kostet, was das unter Einstellungen → Bilder festgelegte Modell berechnet.",
|
||||
"Pick the agents that may search with it: each search goes where Settings → Models → Web search sends it, and costs what that charges.": "Agenten wählen, die damit suchen dürfen: Jede Suche geht dorthin, wohin Einstellungen → Modelle → Websuche sie schickt, und kostet, was das kostet.",
|
||||
"Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.": "Agenten wählen, die damit Bilder lesen dürfen: Jedes Bild geht an das unter Einstellungen → Modelle → Bilder eingestellte Bilderkennungsmodell und kostet, was dieses Modell berechnet.",
|
||||
"Not set up yet": "Noch nicht eingerichtet",
|
||||
"Pick the agents that may use your browser: they act in your tabs, signed in as you are.": "Agenten wählen, die deinen Browser nutzen dürfen: Sie handeln in deinen Tabs, so angemeldet wie du.",
|
||||
"Set up the extension…": "Erweiterung einrichten…",
|
||||
"Show the extension folder": "Ordner der Erweiterung zeigen",
|
||||
|
||||
@@ -539,6 +539,8 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
.mk-badge { flex: none; display: inline-flex; align-items: center; gap: 3px; height: 17px; padding: 0 6px; border-radius: 5px; background: var(--pill); color: var(--fg-2); font-size: 10.5px; font-family: var(--code-font, var(--code)); }
|
||||
:where(html[data-fonts]) .mk-badge { font-style: var(--code-style, inherit); font-weight: var(--code-weight, inherit); font-stretch: var(--code-stretch, 100%); }
|
||||
.mk-badge.mk-needs { width: 17px; padding: 0; justify-content: center; }
|
||||
/* one of magpie's own whose model or search isn't set up (matrix0487): the badge gives way before the row runs wide */
|
||||
.mk-badge.mk-unready { flex: 0 1 auto; min-width: 0; display: block; line-height: 17px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||
.mk-official { flex: none; display: inline-grid; place-items: center; width: 13px; height: 13px; border-radius: 50%; background: var(--fg); color: var(--card); }
|
||||
.mk-desc { margin: 0; min-height: 2.9em; font-size: 12px; line-height: 1.45; color: var(--fg-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.mk-desc.wait { background: linear-gradient(90deg, var(--pill) 25%, var(--pill-hover) 45%, var(--pill) 65%); background-size: 240% 100%; animation: skeleton-shift 1.4s ease-in-out infinite; border-radius: 5px; min-height: 0; height: 8px; margin: 6px 20% 10px 0; }
|
||||
|
||||
@@ -186,31 +186,7 @@ function renderSearch(s, keep) {
|
||||
// As Images' Magpie Image (#2091), the row says how to get there from
|
||||
// where the reader is: gateway mode has no Library, and the Library can
|
||||
// be turned off
|
||||
if (!gatewayMode) {
|
||||
const libOff = featuresOff.has("library");
|
||||
const go = el("button", "link search-mcp-lib", libOff ? t("Turn on the Library") : t("Give agents Magpie Web Search…"));
|
||||
go.type = "button";
|
||||
go.onclick = async () => {
|
||||
if (!libOff) {
|
||||
if (await show("library") !== false) magpie.call("library", "server", "magpie-web-search");
|
||||
return;
|
||||
}
|
||||
go.disabled = true;
|
||||
try {
|
||||
const next = await api("plugins/builtin", { id: "library", on: true });
|
||||
if (state.settings) state.settings.builtins = next;
|
||||
applyFeatures(next);
|
||||
status(t("The Library is on"), "ok", 1500);
|
||||
renderSettings();
|
||||
} catch (err) {
|
||||
go.disabled = false;
|
||||
status(t(err.message), "err");
|
||||
}
|
||||
};
|
||||
const line = el("div", "sub search-mcp-how");
|
||||
line.append(go);
|
||||
mcp.querySelector(".who").append(line);
|
||||
}
|
||||
mcp.querySelector(".who").append(...libWay("magpie-web-search", t("Give agents Magpie Web Search…"), "search-mcp-lib"));
|
||||
}
|
||||
|
||||
// searchArrange: the search APIs are asked in the order they are listed,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
"github.com/yetone/magpie/internal/mcpauth"
|
||||
)
|
||||
@@ -161,6 +162,10 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
|
||||
// once asked for, which skills.sh gives one at a time
|
||||
mux.HandleFunc("GET /api/library/market/servers", func(rw http.ResponseWriter, r *http.Request) {
|
||||
list, err := library.MarketServers(r.URL.Query().Get("q"))
|
||||
for i := range list {
|
||||
// magpie's own that can't answer yet says why on its row
|
||||
list[i].Unready = gateway.OwnUnready(list[i].ID)
|
||||
}
|
||||
m := marketOf(list, err)
|
||||
m.Custom = library.CustomAt(r.URL.Query().Get("q"), list)
|
||||
writeJSON(rw, m)
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// matrix0487 on Discord: of magpie's three own MCP servers, image
|
||||
// recognition, image generation and search, the Library's Discover had
|
||||
// Magpie Image and Magpie Web Search but not image recognition. It now has
|
||||
// Magpie Image Recognition beside them, given only to the agents picked
|
||||
// for it, and Settings' Image recognition row says the way there as the
|
||||
// Library is: Give agents Magpie Image Recognition… opens its sheet, which
|
||||
// says where each image goes; with the Library off, Turn on the Library
|
||||
// switches it on; with recognition off, or in gateway mode, there is none.
|
||||
// One that can't answer yet says why on its Discover card and sheet, so
|
||||
// no tool is added dead without a word. Every language, Chromium and
|
||||
// WebKit, at 1100 and 420 wide, nothing running off to the side; no
|
||||
// backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { strings } = require("./strings.cjs");
|
||||
const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const { I18N } = strings();
|
||||
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
const tr = (lang, s) => (lang === "en" ? s : I18N[lang]?.[s] ?? s);
|
||||
const HOME = "/Users/tester";
|
||||
const HINT = "Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges.";
|
||||
const UNREADY = "No model that sees images is set up yet: it reads images once a provider with one is added, and says so until then";
|
||||
const ABOUT = "Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.";
|
||||
const SEARCH = "Search the web with the search set in Magpie (Settings → Models → Web search), and read a page by its URL.";
|
||||
|
||||
function fixture(lang, { libOn, have = false, gateway = false, unready = "", vision = "" }) {
|
||||
const st = { libOn };
|
||||
const posts = [];
|
||||
const builtins = () => [{ id: "library", name: "Library", sub: "Instructions, MCP servers and skills for every agent", on: st.libOn, chosen: st.libOn, source: "preset", state: st.libOn ? "active" : "off", inUse: 0 }];
|
||||
const settings = () => ({
|
||||
theme: "light", lang, tray: "panel", currency: "usd", textSize: 100, redactWords: [],
|
||||
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3999", port: 3999,
|
||||
proxyNow: "none", proxySource: "none", vision, imageGen: "", lanURLs: [], visionAuto: "probe/eye",
|
||||
visionModels: [], imageGenModels: [], workbuddyCheckins: [],
|
||||
searcher: "", searchChoices: [],
|
||||
searchVendors: [{ id: "tavily", name: "Tavily", keysURL: "https://app.tavily.com/home" }],
|
||||
searchAPIs: [{ vendor: "tavily", name: "Tavily", key: "tvly…abcd", ready: true }],
|
||||
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
|
||||
builtins: builtins(),
|
||||
...(gateway ? { web: true, gatewayMode: "on", gatewayOn: true } : {}),
|
||||
});
|
||||
const lib = () => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [{ id: "pi", name: "Pi", icon: "generic", mcp: `${HOME}/.pi/mcp.json`, skills: `${HOME}/.pi/skills` }],
|
||||
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], problems: [],
|
||||
servers: have ? [{ name: "magpie-vision", transport: "stdio", command: "/Applications/magpie.app/Contents/MacOS/magpie", args: ["mcp", "vision"], agents: ["pi"] }] : [],
|
||||
});
|
||||
const route = async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") {
|
||||
return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", textSize: 100, featuresOff: st.libOn ? [] : ["library"], ...(gateway ? { web: true, gateway: true } : {}) })};` });
|
||||
}
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settings(), fx: settings().fx });
|
||||
if (url.pathname === "/api/settings") return json(settings());
|
||||
if (url.pathname === "/api/plugins/builtin" && req.method() === "POST") {
|
||||
const b = req.postDataJSON();
|
||||
posts.push(b);
|
||||
if (b.id === "library") st.libOn = b.on;
|
||||
return json(builtins());
|
||||
}
|
||||
if (url.pathname === "/api/library") return json(lib());
|
||||
if (url.pathname === "/api/library/market/servers") {
|
||||
return json({ items: [
|
||||
{ id: "magpie-image", name: "magpie-image", title: "Magpie Image", publisher: "Magpie", description: "Generate and edit images with the image model set in Magpie.", transport: "stdio", runs: "magpie", featured: true, optIn: true, have: "" },
|
||||
{ id: "magpie-web-search", name: "magpie-web-search", title: "Magpie Web Search", publisher: "Magpie", description: SEARCH, transport: "stdio", runs: "magpie", featured: true, optIn: true, have: "" },
|
||||
{ id: "magpie-vision", name: "magpie-vision", title: "Magpie Image Recognition", publisher: "Magpie", description: ABOUT, transport: "stdio", runs: "magpie", featured: true, optIn: true, have: have ? "magpie-vision" : "", ...(unready ? { unready } : {}) },
|
||||
] });
|
||||
}
|
||||
if (url.pathname === "/api/library/market/skills") return json({ items: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], gateway: { running: true } });
|
||||
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
const body = await fs.readFile(file).catch(() => null);
|
||||
await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" }));
|
||||
};
|
||||
return { route, posts };
|
||||
}
|
||||
|
||||
const row = (page) => page.locator("#imagesList > .row").first();
|
||||
const wide = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": Image recognition's MCP server is in the Library, and its row says the way there", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const shots = [];
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
for (const [name, buf] of shots) await fs.writeFile(path.join(process.env.ARTIFACT_DIR, `${engine}-vision-mcp-library-${name}.png`), buf);
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
const open = async (lang, width, opts) => {
|
||||
const f = fixture(lang, opts);
|
||||
const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.errors = [];
|
||||
page.on("pageerror", (e) => page.errors.push(e.message));
|
||||
await page.route("**/*", f.route);
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=settings&tab=models");
|
||||
await settingsDrawn(page);
|
||||
await row(page).waitFor();
|
||||
return { page, posts: f.posts };
|
||||
};
|
||||
for (const lang of LANGS) {
|
||||
const w = (s) => tr(lang, s);
|
||||
for (const width of [1100, 420]) {
|
||||
await t.test(`${lang} at ${width}px: Give agents Magpie Image Recognition… opens its sheet in the Library`, async () => {
|
||||
const { page } = await open(lang, width, { libOn: true, unready: UNREADY });
|
||||
const go = row(page).locator(".who button.vision-mcp-lib");
|
||||
assert.equal((await go.textContent()).trim(), w("Give agents Magpie Image Recognition…"));
|
||||
assert.equal(await wide(page), 0);
|
||||
shots.push([`${lang}-${width}-row`, await row(page).screenshot()]);
|
||||
await go.click();
|
||||
const sheet = page.locator("#modal .mk-sheet");
|
||||
await sheet.waitFor();
|
||||
assert.equal(await page.locator("#view-library").isVisible(), true);
|
||||
assert.equal((await sheet.locator(".mk-name.big").textContent()).trim(), "Magpie Image Recognition");
|
||||
assert.equal((await sheet.locator(".mk-about").textContent()).trim(), w(ABOUT));
|
||||
assert.equal((await sheet.locator(".mk-hint").first().textContent()).trim(), w(HINT));
|
||||
// nothing sees yet: the sheet says so, and still adds it
|
||||
assert.equal((await sheet.locator(".mk-hint.mk-unready").textContent()).trim(), w(UNREADY));
|
||||
// opt in: no agent is ticked until it is picked
|
||||
assert.equal(await page.locator('#view-library .mk[data-market="mcp"]').count(), 1);
|
||||
assert.equal(await wide(page), 0);
|
||||
shots.push([`${lang}-${width}-sheet`, await page.screenshot()]);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
await t.test(`${lang} at ${width}px: with the Library off, Turn on the Library brings it back`, async () => {
|
||||
const { page, posts } = await open(lang, width, { libOn: false });
|
||||
const go = row(page).locator(".who button.vision-mcp-lib");
|
||||
assert.equal((await go.textContent()).trim(), w("Turn on the Library"));
|
||||
assert.equal(await wide(page), 0);
|
||||
await go.click();
|
||||
await page.waitForFunction((s) => document.querySelector("#imagesList button.vision-mcp-lib")?.textContent.trim() === s, w("Give agents Magpie Image Recognition…"));
|
||||
assert.deepEqual(posts, [{ id: "library", on: true }]);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
}
|
||||
for (const width of [1100, 420]) await t.test(`${lang} at ${width}px: one already in the library opens Discover, all three of magpie's own there, the one not set up saying so`, async () => {
|
||||
const { page } = await open(lang, width, { libOn: true, have: true, unready: UNREADY });
|
||||
await row(page).locator("button.vision-mcp-lib").click();
|
||||
const card = (id) => page.locator(`#view-library .mk[data-market="mcp"] .mk-card[data-id="${id}"]`);
|
||||
await card("magpie-vision").waitFor();
|
||||
assert.equal(await page.locator("#modal .mk-sheet").count(), 0);
|
||||
for (const id of ["magpie-image", "magpie-web-search"]) {
|
||||
assert.equal(await card(id).count(), 1, id);
|
||||
assert.equal(await card(id).locator(".mk-unready").count(), 0, id);
|
||||
}
|
||||
const badge = card("magpie-vision").locator(".mk-badge.mk-unready");
|
||||
assert.equal((await badge.textContent()).trim(), w("Not set up yet"));
|
||||
assert.equal(await badge.getAttribute("title"), w(UNREADY));
|
||||
// the badge gives way inside its card
|
||||
const [c, b] = await Promise.all([card("magpie-vision").boundingBox(), badge.boundingBox()]);
|
||||
assert(b.x + b.width <= c.x + c.width + 0.5, `badge ${JSON.stringify(b)} past card ${JSON.stringify(c)}`);
|
||||
assert.equal(await wide(page), 0);
|
||||
shots.push([`${lang}-${width}-discover`, await page.screenshot()]);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
await t.test(`${lang}: gateway mode, with no Library, offers no way to one`, async () => {
|
||||
const { page } = await open(lang, 1100, { libOn: true, gateway: true });
|
||||
assert.equal(await row(page).locator("button.vision-mcp-lib").count(), 0);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
await t.test(`${lang}: with image recognition off there is nothing to give`, async () => {
|
||||
const { page } = await open(lang, 1100, { libOn: true, vision: "off" });
|
||||
assert.equal(await row(page).locator("button.vision-mcp-lib").count(), 0);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func callLongest() time.Duration {
|
||||
// Run serves MCP on stdin/stdout until stdin closes.
|
||||
func Run(args []string) error {
|
||||
if len(args) > 0 && args[0] != "image" {
|
||||
return fmt.Errorf("unknown MCP server %q (there are: image, browser, search)", args[0])
|
||||
return fmt.Errorf("unknown MCP server %q (there are: image, browser, search, vision)", args[0])
|
||||
}
|
||||
if len(args) > 1 {
|
||||
w, err := options(args[1:])
|
||||
|
||||
@@ -61,8 +61,12 @@ type MarketServer struct {
|
||||
SignIn bool `json:"signIn,omitempty"`
|
||||
Featured bool `json:"featured,omitempty"`
|
||||
// OptIn is one no agent is given unless it is picked for it
|
||||
OptIn bool `json:"optIn,omitempty"`
|
||||
Inputs []Input `json:"inputs"`
|
||||
OptIn bool `json:"optIn,omitempty"`
|
||||
// Unready is why one of magpie's own can't answer yet (nothing it
|
||||
// needs is set up, or Settings turned it off), from the GUI, which
|
||||
// knows: its tools still answer, with the same words
|
||||
Unready string `json:"unready,omitempty"`
|
||||
Inputs []Input `json:"inputs"`
|
||||
// Have is the library's server that is this one
|
||||
Have string `json:"have,omitempty"`
|
||||
// Match is one found at the address searched for: its repository, page,
|
||||
@@ -94,6 +98,7 @@ var featured = []MarketServer{
|
||||
selfServer(),
|
||||
browserServer(),
|
||||
searchServer(),
|
||||
visionServer(),
|
||||
remoteServer("context7", "Context7", "Upstash", gh("upstash"), "https://mcp.context7.com/mcp",
|
||||
"Up-to-date documentation and code examples for any library, straight into the prompt.", false,
|
||||
Input{Key: "CONTEXT7_API_KEY", Where: "header", Label: "API key", Description: "Optional — raises the rate limit. From context7.com/dashboard", Secret: true, format: "{}"}),
|
||||
@@ -209,6 +214,26 @@ func searchServer() MarketServer {
|
||||
return m
|
||||
}
|
||||
|
||||
// visionServerName is the name Magpie Image Recognition's server is
|
||||
// written under, the name the gateway's own image recognition server goes
|
||||
// by (ownMCP).
|
||||
const visionServerName = "magpie-vision"
|
||||
|
||||
// visionServer is Magpie Image Recognition: magpie's image recognition
|
||||
// (Settings › Models › Images › Image recognition) as an analyze_image
|
||||
// tool, through `magpie mcp vision`, which passes each call to the
|
||||
// gateway's VisionMCPPath. Settings named it by its address only, and the
|
||||
// Library had image generation and search but not it (matrix0487 on
|
||||
// Discord, #4653). A look costs what the model that sees charges, and
|
||||
// most agents' models see for themselves, so it is given only to the
|
||||
// agents picked for it.
|
||||
func visionServer() MarketServer {
|
||||
m := localServer(visionServerName, "Magpie Image Recognition", "Magpie", "https://usemagpie.ai/favicon.png", "https://usemagpie.ai",
|
||||
"Read an image (a file, a URL, a screenshot) with the image recognition model set in Magpie (Settings → Models → Images), for a model that can't see.", magpieCommand, []string{"mcp", "vision"})
|
||||
m.OptIn = true
|
||||
return m
|
||||
}
|
||||
|
||||
// selfCommand is the server's command and env for this magpie: its binary
|
||||
// by full path, and the gateway's address when it isn't the default one.
|
||||
func selfCommand(s *Server) {
|
||||
@@ -319,7 +344,7 @@ func serverKey(s *Server) string {
|
||||
if s.Remote() {
|
||||
return strings.TrimSuffix(strings.ToLower(s.URL), "/")
|
||||
}
|
||||
if len(s.Args) == 2 && s.Args[0] == "mcp" && (s.Args[1] == "image" || s.Args[1] == "browser" || s.Args[1] == "search") {
|
||||
if len(s.Args) == 2 && s.Args[0] == "mcp" && (s.Args[1] == "image" || s.Args[1] == "browser" || s.Args[1] == "search" || s.Args[1] == "vision") {
|
||||
return "magpie mcp " + s.Args[1] // magpie's own, wherever its binary is
|
||||
}
|
||||
for _, a := range s.Args {
|
||||
|
||||
@@ -429,3 +429,47 @@ func TestMagpieWebSearchIsOptIn(t *testing.T) {
|
||||
t.Fatalf("keys %q and %q", serverKey(&other), serverKey(s))
|
||||
}
|
||||
}
|
||||
|
||||
// Magpie Image Recognition is in Discover beside Magpie Image and Magpie
|
||||
// Web Search, added for no agent until the user picks them, with time to
|
||||
// look (matrix0487 on Discord); any binary's `mcp vision` is the same
|
||||
// server.
|
||||
func TestMagpieImageRecognitionIsOptIn(t *testing.T) {
|
||||
sandbox(t)
|
||||
list, err := MarketServers("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{selfServerName, searchServerName, visionServerName} {
|
||||
if !slices.ContainsFunc(list, func(m MarketServer) bool { return m.ID == id && m.OptIn }) {
|
||||
t.Fatalf("%s not in Discover: %+v", id, list)
|
||||
}
|
||||
}
|
||||
ok(t)(InstallServer(visionServerName, nil, nil))
|
||||
list, err = MarketServers("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
i := slices.IndexFunc(list, func(m MarketServer) bool { return m.ID == visionServerName })
|
||||
if i < 0 || list[i].Have != visionServerName || list[i].Title != "Magpie Image Recognition" {
|
||||
t.Fatalf("market: %+v", list)
|
||||
}
|
||||
l, err := load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := l.server(visionServerName)
|
||||
if s == nil || len(s.Agents) != 0 || !filepath.IsAbs(s.Command) || strings.Join(s.Args, " ") != "mcp vision" {
|
||||
t.Fatalf("added as %+v", s)
|
||||
}
|
||||
if v, ok := valueOf((&mcpFile{Format: fmtCodex}).encode(s), "tool_timeout_sec"); !ok || v != 120 {
|
||||
t.Fatalf("Codex's entry: tool_timeout_sec = %v %v", v, ok)
|
||||
}
|
||||
other := Server{Name: "eyes", Transport: "stdio", Command: "/opt/other/magpie", Args: []string{"mcp", "vision"}}
|
||||
if serverKey(&other) != serverKey(s) {
|
||||
t.Fatalf("keys %q and %q", serverKey(&other), serverKey(s))
|
||||
}
|
||||
if search := (Server{Name: "web", Transport: "stdio", Command: s.Command, Args: []string{"mcp", "search"}}); serverKey(&search) == serverKey(s) {
|
||||
t.Fatal("vision and search share a key")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,13 +372,14 @@ func (o ordered) MarshalYAML() (any, error) {
|
||||
|
||||
// selfTimeout is the seconds an agent waits for a tool of s: what
|
||||
// magpie-image's video tool needs, at least two minutes for
|
||||
// magpie-browser's and magpie-web-search's, else def.
|
||||
// magpie-browser's, magpie-web-search's and magpie-vision's, else def.
|
||||
func selfTimeout(s *Server, def int) int {
|
||||
if s.Name == selfServerName && s.Command != "" {
|
||||
return int(imagemcp.ToolTimeout().Seconds())
|
||||
}
|
||||
if s.Name == searchServerName && s.Command != "" {
|
||||
// a search a searcher model answers, or a slow page, takes a while
|
||||
if (s.Name == searchServerName || s.Name == visionServerName) && s.Command != "" {
|
||||
// a search a searcher model answers, a slow page, or a look at a
|
||||
// big image takes a while
|
||||
return max(def, 120)
|
||||
}
|
||||
if s.Name == browserServerName && s.Command != "" {
|
||||
|
||||
Reference in New Issue
Block a user