library: a market server starts the way its registry entry says (fwxkogaia on X)
Serena from Library → MCP's market showed "已退出 (2)": magpie ran `uvx serena-agent`, which prints its help and exits 2. The registry has uvx run it as `uvx -p 3.13 serena-agent start-mcp-server --project-from-cwd --context desktop-app`: its runtimeArguments, which the shipped crawl (market_servers.json) had dropped and magpie never read. The class, fixed in launchLine (market_launch.go): - runtimeArguments are read: the runner's own options (uvx -p/--from/ --with/--prerelease, npx --package, docker's mounts, -e and --entrypoint) go before the package, the program's words after it, then packageArguments. A required option with no value magpie can fill keeps the package from being offered. - An executable not named after its package is reached with `uvx --from <pkg> <bin>` / `npx -y --package <pkg> <bin>`. The crawl now keeps each package's executables (`bins`: npm's `bin`, the wheel's console scripts); a package with none, or several with none standing out (pickBin), isn't offered. `python -m mod` among runtimeArguments runs that module from the package. - One package that can't be started no longer hides another of the same server (npm, then pypi, then oci). - serverKey/packageOf skip uvx's option values, so Serena's key stays "uvx serena-agent" and an installed one is still found. Audit of the 500 shipped entries (old line → new): 101 change. Among them firebase (`npx -y firebase-tools mcp`), basic-memory, docling, ouroboros, pm-claude-skills, llm-sandbox, polymarket-paper-trader, visualtorch, canvas-mcp, alfanous (python -m), uniswap, pyscrappy, llmtrim, reddit-research-mcp, word-mcp-live, omega, tinysearch, haiku-rag, orcareplay, terravision, watch-skill, PyMemoryEditor, edgartools/mirobody/new-term-radar/backlot (--with/--python), docker robin/funasr/MARM (mounts). No longer offered (no line that starts): aihawk and mcp-sap-docs (not on PyPI/npm), mcp-video, unifi-mcp-server, antigravity-link-extension (no executable), token-savior, flyto-core (several, none for MCP), maintenant and apollo (a docker mount to fill in). Users who installed one already: heal() gives a uvx/npx server whose command and arguments are exactly the line magpie offered before the line the registry says (healMarketLines), so the next start of magpie rewrites library.json and every agent given it. A line the user edited is left as it is. Run (mote, via mote-run): go test ./internal/library ./internal/gui; go vet darwin, GOOS=linux -tags nogui, GOOS=windows; gofmt. TestRegistryLaunchLines uses the registry's own entries (Serena, docling, olcli, alfanous, visualtorch, basic-memory, firebase, MARM, ...); TestPopularSerenaStarts reads the shipped crawl; TestInstalledMarketLineHealed seeds `uvx serena-agent` given to Codex, syncs, and checks config.toml and library.json. No network in tests. Real starts on mote in a sandbox HOME (MCP initialize): `uvx serena-agent` exits 2 with usage; the new Serena line answers initialize (serverInfo Serena). Also answer: polymarket pm-trader-mcp, basic-memory, llmtrim, pm-claude-skills, visualtorch-mcp. canvas and reddit start but need their keys. Broken by hand: ignoring runtimeArguments and the bins check turns 14 of TestRegistryLaunchLines' cases and TestPopularSerenaStarts red; dropping healMarketLines from heal turns TestInstalledMarketLineHealed red. Not tried / still wrong upstream: omega and tinysearch now run their real executable but their registry entries omit the `[server]` extra (omega also needs `serve`), so they still don't serve MCP; that is their registry entries. Docker lines weren't started. No GUI asset changed, so no GUI files were run. The full suite runs after the tag.
This commit is contained in:
File diff suppressed because one or more lines are too long
+17
-57
@@ -413,12 +413,18 @@ func serverKey(s *Server) string {
|
||||
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" || s.Args[1] == "memory") {
|
||||
return "magpie mcp " + s.Args[1] // magpie's own, wherever its binary is
|
||||
}
|
||||
for _, a := range s.Args {
|
||||
uv := progName(s.Command) == "uvx"
|
||||
for i := 0; i < len(s.Args); i++ {
|
||||
a := s.Args[i]
|
||||
if uv && a != "--from" && uvOpts[a] { // uvx -p 3.13: the value is not the package
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if a == "" || strings.HasPrefix(a, "-") || a == "run" {
|
||||
continue
|
||||
}
|
||||
if i := strings.LastIndex(a, "@"); i > 0 { // @scope/pkg@latest → @scope/pkg
|
||||
a = a[:i]
|
||||
if j := strings.LastIndex(a, "@"); j > 0 { // @scope/pkg@latest → @scope/pkg
|
||||
a = a[:j]
|
||||
}
|
||||
return s.Command + " " + a
|
||||
}
|
||||
@@ -451,21 +457,7 @@ type registryServer struct {
|
||||
URL string `json:"url"`
|
||||
Headers []registryVar `json:"headers"`
|
||||
} `json:"remotes"`
|
||||
Packages []struct {
|
||||
RegistryType string `json:"registryType"`
|
||||
Identifier string `json:"identifier"`
|
||||
Transport struct{ Type string } `json:"transport"`
|
||||
Env []registryVar `json:"environmentVariables"`
|
||||
Arguments []struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
Default string `json:"default"`
|
||||
ValueHint string `json:"valueHint"`
|
||||
Description string `json:"description"`
|
||||
IsRequired bool `json:"isRequired"`
|
||||
} `json:"packageArguments"`
|
||||
} `json:"packages"`
|
||||
Packages []registryPackage `json:"packages"`
|
||||
}
|
||||
|
||||
type registryVar struct {
|
||||
@@ -689,55 +681,23 @@ func fromRegistry(r *registryServer) (MarketServer, bool) {
|
||||
}
|
||||
}
|
||||
for _, want := range []string{"npm", "pypi", "oci"} {
|
||||
for _, p := range r.Packages {
|
||||
for i, p := range r.Packages {
|
||||
if p.RegistryType != want || p.Identifier == "" || (p.Transport.Type != "" && p.Transport.Type != "stdio") {
|
||||
continue
|
||||
}
|
||||
s.Transport, m.Transport = "stdio", "stdio"
|
||||
switch want {
|
||||
case "npm":
|
||||
s.Command, s.Args = "npx", []string{"-y", p.Identifier}
|
||||
case "pypi":
|
||||
s.Command, s.Args = "uvx", []string{p.Identifier}
|
||||
case "oci":
|
||||
s.Command, s.Args = "docker", []string{"run", "-i", "--rm"}
|
||||
cmd, args, inputs, ok := launchLine(&r.Packages[i])
|
||||
if !ok { // not a line magpie can start; another package may be
|
||||
continue
|
||||
}
|
||||
m.Runs = s.Command
|
||||
s.Transport, m.Transport = "stdio", "stdio"
|
||||
s.Command, s.Args, m.Runs = cmd, args, cmd
|
||||
for _, e := range p.Env {
|
||||
if !e.IsRequired && !e.IsSecret {
|
||||
continue
|
||||
}
|
||||
m.Inputs = append(m.Inputs, Input{Key: e.Name, Where: "env", Label: e.Name, Description: e.Description, Secret: e.IsSecret, Required: e.IsRequired})
|
||||
if want == "oci" {
|
||||
s.Args = append(s.Args, "-e", e.Name)
|
||||
}
|
||||
}
|
||||
if want == "oci" {
|
||||
s.Args = append(s.Args, p.Identifier)
|
||||
}
|
||||
for i, a := range p.Arguments {
|
||||
v := a.Value
|
||||
if v == "" {
|
||||
v = a.Default
|
||||
}
|
||||
if placeholderRe.MatchString(v) {
|
||||
v = ""
|
||||
}
|
||||
switch {
|
||||
case v != "" && a.Type == "named":
|
||||
s.Args = append(s.Args, a.Name, v)
|
||||
case v != "":
|
||||
s.Args = append(s.Args, v)
|
||||
case a.IsRequired && a.Type != "named":
|
||||
label := a.ValueHint
|
||||
if label == "" {
|
||||
label = fmt.Sprintf("Argument %d", i+1)
|
||||
}
|
||||
m.Inputs = append(m.Inputs, Input{Key: fmt.Sprintf("arg%d", i), Where: "arg", Label: label, Description: a.Description, Required: true})
|
||||
case a.IsRequired:
|
||||
return MarketServer{}, false // a named argument magpie can't fill
|
||||
}
|
||||
}
|
||||
m.Inputs = append(m.Inputs, inputs...)
|
||||
return m, true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,12 +115,18 @@ func packageOf(s *Server) string {
|
||||
if s.Command == "docker" {
|
||||
return s.Args[len(s.Args)-1]
|
||||
}
|
||||
for _, a := range s.Args {
|
||||
uv := progName(s.Command) == "uvx"
|
||||
for i := 0; i < len(s.Args); i++ {
|
||||
a := s.Args[i]
|
||||
if uv && a != "--from" && uvOpts[a] { // uvx -p 3.13: the value is not the package
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if a == "" || strings.HasPrefix(a, "-") || a == "run" {
|
||||
continue
|
||||
}
|
||||
if i := strings.LastIndex(a, "@"); i > 0 {
|
||||
a = a[:i]
|
||||
if j := strings.LastIndex(a, "@"); j > 0 {
|
||||
a = a[:j]
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
package library
|
||||
|
||||
// How a registry entry's package is started. The registry says a package's
|
||||
// runtime (npx, uvx, docker), the runtime's own arguments
|
||||
// (runtimeArguments) and the program's (packageArguments). Publishers
|
||||
// don't all read the schema the same way: Serena puts its program's
|
||||
// start-mcp-server among uvx's arguments, Docling names its executable
|
||||
// there behind --from, Visualtorch puts --from among the program's. And a
|
||||
// package's executable can be named otherwise than the package
|
||||
// (alfanous3-mcp runs alfanous-mcp), which uvx doesn't guess
|
||||
// (fwxkogaia on X: Serena installed from the market exited 2).
|
||||
//
|
||||
// So the arguments are read as a line the runtime will parse: the
|
||||
// runtime's own options before the package, the rest after it, and the
|
||||
// executable checked against the ones the package has, where the market's
|
||||
// crawl knows them (Bins).
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type registryArg struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
Default string `json:"default"`
|
||||
ValueHint string `json:"valueHint"`
|
||||
Description string `json:"description"`
|
||||
IsRequired bool `json:"isRequired"`
|
||||
}
|
||||
|
||||
type registryPackage struct {
|
||||
RegistryType string `json:"registryType"`
|
||||
Identifier string `json:"identifier"`
|
||||
RuntimeHint string `json:"runtimeHint"`
|
||||
Transport struct{ Type string } `json:"transport"`
|
||||
Env []registryVar `json:"environmentVariables"`
|
||||
RuntimeArgs []registryArg `json:"runtimeArguments"`
|
||||
Arguments []registryArg `json:"packageArguments"`
|
||||
// Bins are the executables the package's latest version has, as
|
||||
// the market's crawl found them (npm's bin, a wheel's
|
||||
// console_scripts); nil where it isn't known, as for anything the
|
||||
// registry is searched for.
|
||||
Bins []string `json:"bins"`
|
||||
}
|
||||
|
||||
// tokens is an argument as it's written on the line: nothing for one with
|
||||
// no value (or a placeholder for one), need true when that one is required.
|
||||
func (a registryArg) tokens() (out []string, need bool) {
|
||||
v := a.Value
|
||||
if v == "" {
|
||||
v = a.Default
|
||||
}
|
||||
if placeholderRe.MatchString(v) {
|
||||
v = ""
|
||||
}
|
||||
switch {
|
||||
case v != "" && a.Type == "named":
|
||||
return []string{a.Name, v}, false
|
||||
case v != "":
|
||||
return []string{v}, false
|
||||
}
|
||||
return nil, a.IsRequired
|
||||
}
|
||||
|
||||
// uvx's and npx's own options, with the ones that take a value.
|
||||
var (
|
||||
uvOpts = map[string]bool{"--from": true, "--with": true, "-w": true, "--with-editable": true,
|
||||
"--with-requirements": true, "-p": true, "--python": true, "--prerelease": true, "--index": true,
|
||||
"--index-url": true, "-i": true, "--extra-index-url": true, "--default-index": true,
|
||||
"--resolution": true, "--constraints": true, "-c": true, "--overrides": true,
|
||||
"--isolated": false, "--refresh": false, "--offline": false, "-q": false, "--quiet": false,
|
||||
"-n": false, "--no-cache": false, "--no-config": false}
|
||||
npxOpts = map[string]bool{"-p": true, "--package": true, "-y": false, "--yes": false}
|
||||
)
|
||||
|
||||
// runtimeOption says a runtime argument is one of the runtime's own
|
||||
// options, not the program's.
|
||||
func runtimeOption(opts map[string]bool, a registryArg, toks []string) bool {
|
||||
if len(toks) == 0 {
|
||||
return false
|
||||
}
|
||||
if a.Type == "named" {
|
||||
_, ok := opts[a.Name]
|
||||
return ok
|
||||
}
|
||||
_, ok := opts[toks[0]]
|
||||
return ok
|
||||
}
|
||||
|
||||
// launchLine is the command and arguments that start package p, and the
|
||||
// inputs it leaves to the user (arguments the program needs that the
|
||||
// registry gives no value for). ok is false for a package that can't be
|
||||
// started as written: a required named argument with no value, or a
|
||||
// package the crawl found has no executable to run.
|
||||
func launchLine(p *registryPackage) (cmd string, args []string, inputs []Input, ok bool) {
|
||||
var rt, opts, prog []string
|
||||
for _, a := range p.RuntimeArgs {
|
||||
t, need := a.tokens()
|
||||
if need {
|
||||
return "", nil, nil, false
|
||||
}
|
||||
switch p.RegistryType {
|
||||
case "pypi":
|
||||
if runtimeOption(uvOpts, a, t) {
|
||||
opts = append(opts, t...)
|
||||
} else {
|
||||
prog = append(prog, t...)
|
||||
}
|
||||
case "npm":
|
||||
if runtimeOption(npxOpts, a, t) {
|
||||
opts = append(opts, t...)
|
||||
} else {
|
||||
prog = append(prog, t...)
|
||||
}
|
||||
default: // docker run's options, all of them before the image
|
||||
opts = append(opts, t...)
|
||||
}
|
||||
rt = append(rt, t...)
|
||||
}
|
||||
var pa []string
|
||||
for i, a := range p.Arguments {
|
||||
t, need := a.tokens()
|
||||
switch {
|
||||
case t != nil:
|
||||
pa = append(pa, t...)
|
||||
case need && a.Type == "named":
|
||||
return "", nil, nil, false // a named argument magpie can't fill
|
||||
case need:
|
||||
label := a.ValueHint
|
||||
if label == "" {
|
||||
label = fmt.Sprintf("Argument %d", i+1)
|
||||
}
|
||||
inputs = append(inputs, Input{Key: fmt.Sprintf("arg%d", i), Where: "arg", Label: label, Description: a.Description, Required: true})
|
||||
}
|
||||
}
|
||||
switch p.RegistryType {
|
||||
case "npm":
|
||||
cmd, args, ok = npxLine(p, rt, opts, prog, pa)
|
||||
case "pypi":
|
||||
cmd, args, ok = uvxLine(p, rt, opts, prog, pa)
|
||||
case "oci":
|
||||
cmd, args, ok = "docker", []string{"run", "-i", "--rm"}, true
|
||||
for _, e := range p.Env {
|
||||
if e.IsRequired || e.IsSecret {
|
||||
args = append(args, "-e", e.Name)
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(opts); i++ {
|
||||
if o := opts[i]; o == "-i" || o == "--rm" || o == "--interactive" {
|
||||
continue
|
||||
}
|
||||
args = append(args, opts[i])
|
||||
}
|
||||
args = append(append(args, p.Identifier), pa...)
|
||||
}
|
||||
return cmd, args, inputs, ok
|
||||
}
|
||||
|
||||
// npxLine is `npx -y [--package pkg] <command> args…`.
|
||||
func npxLine(p *registryPackage, rt, opts, prog, pa []string) (string, []string, bool) {
|
||||
var line []string
|
||||
if slices.Contains(rt, p.Identifier) { // the publisher wrote npx's whole line
|
||||
line = append(slices.Clone(rt), pa...)
|
||||
} else {
|
||||
line = append(append(append(append([]string{}, opts...), p.Identifier), prog...), pa...)
|
||||
}
|
||||
pkg, i := "", 0
|
||||
scan:
|
||||
for ; i < len(line); i++ {
|
||||
switch a := line[i]; {
|
||||
case a == "-y" || a == "--yes":
|
||||
case (a == "-p" || a == "--package") && i+1 < len(line):
|
||||
pkg = line[i+1]
|
||||
i++
|
||||
case strings.HasPrefix(a, "--package="):
|
||||
pkg = strings.TrimPrefix(a, "--package=")
|
||||
default:
|
||||
break scan
|
||||
}
|
||||
}
|
||||
if i == len(line) {
|
||||
return "", nil, false
|
||||
}
|
||||
exe, rest := line[i], line[i+1:]
|
||||
if pkg == "" && exe == p.Identifier && p.Bins != nil {
|
||||
// npx runs the bin named after the package, or its only one
|
||||
if len(p.Bins) == 0 {
|
||||
return "", nil, false
|
||||
}
|
||||
if !slices.Contains(p.Bins, lastPart(p.Identifier)) && len(p.Bins) != 1 {
|
||||
b := pickBin(p.Bins, p.Identifier)
|
||||
if b == "" {
|
||||
return "", nil, false
|
||||
}
|
||||
pkg, exe = p.Identifier, b
|
||||
}
|
||||
}
|
||||
out := []string{"-y"}
|
||||
if pkg != "" && exe != lastPart(pkg) {
|
||||
out = append(out, "--package", pkg)
|
||||
} else if pkg != "" {
|
||||
exe = pkg
|
||||
}
|
||||
return "npx", append(append(out, exe), rest...), true
|
||||
}
|
||||
|
||||
// uvxLine is `uvx [options] [--from spec] <executable> args…`.
|
||||
func uvxLine(p *registryPackage, rt, opts, prog, pa []string) (string, []string, bool) {
|
||||
if i := slices.Index(rt, "-m"); i >= 0 && i+1 < len(rt) { // python -m module
|
||||
return "uvx", append([]string{"--from", p.Identifier, "python", "-m", rt[i+1]}, pa...), true
|
||||
}
|
||||
if len(pa) > 0 && pa[0] == "--with" { // uvx's option put among the program's
|
||||
opts, pa = append(slices.Clone(opts), pa[:min(2, len(pa))]...), pa[min(2, len(pa)):]
|
||||
}
|
||||
var line []string
|
||||
from := hasOpt(opts, "--from")
|
||||
switch {
|
||||
case len(pa) > 0 && pa[0] == "--from": // the whole line put among the program's
|
||||
line = append(append(slices.Clone(opts), prog...), pa...)
|
||||
case from && len(prog) == 0: // --from names the package; its executable is the package's name
|
||||
line = append(append(slices.Clone(opts), p.Identifier), pa...)
|
||||
case from || slices.Contains(prog, p.Identifier): // the executable is among them
|
||||
line = append(append(slices.Clone(opts), prog...), pa...)
|
||||
default:
|
||||
line = append(append(append(slices.Clone(opts), p.Identifier), prog...), pa...)
|
||||
}
|
||||
var head []string
|
||||
spec, i := "", 0
|
||||
for ; i < len(line); i++ {
|
||||
a := line[i]
|
||||
takes, isOpt := uvOpts[a]
|
||||
if !isOpt {
|
||||
break
|
||||
}
|
||||
if takes && i+1 < len(line) {
|
||||
if a == "--from" {
|
||||
spec = line[i+1]
|
||||
} else {
|
||||
head = append(head, a, line[i+1])
|
||||
}
|
||||
i++
|
||||
continue
|
||||
}
|
||||
head = append(head, a)
|
||||
}
|
||||
if i == len(line) {
|
||||
return "", nil, false
|
||||
}
|
||||
exe, rest := line[i], line[i+1:]
|
||||
if p.Bins != nil && !slices.Contains(p.Bins, exe) {
|
||||
b := pickBin(p.Bins, p.Identifier)
|
||||
if b == "" {
|
||||
return "", nil, false
|
||||
}
|
||||
if spec == "" {
|
||||
spec = exe
|
||||
}
|
||||
exe = b
|
||||
}
|
||||
if spec != "" && spec != exe {
|
||||
head = append(head, "--from", spec)
|
||||
}
|
||||
return "uvx", append(append(head, exe), rest...), true
|
||||
}
|
||||
|
||||
func hasOpt(line []string, o string) bool {
|
||||
for i := 0; i < len(line); i++ {
|
||||
if line[i] == o {
|
||||
return true
|
||||
}
|
||||
if uvOpts[line[i]] {
|
||||
i++
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// pickBin is the executable that serves a package with several, none
|
||||
// named after it: the only one, or the one named for MCP, or (for a scoped
|
||||
// npm package like @llmtrim/cli) the one named for its scope. "" when none
|
||||
// stands out.
|
||||
func pickBin(bins []string, id string) string {
|
||||
if len(bins) == 1 {
|
||||
return bins[0]
|
||||
}
|
||||
one := func(f func(string) bool) string {
|
||||
var got []string
|
||||
for _, b := range bins {
|
||||
if f(b) {
|
||||
got = append(got, b)
|
||||
}
|
||||
}
|
||||
if len(got) == 1 {
|
||||
return got[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
for _, f := range []func(string) bool{
|
||||
func(b string) bool {
|
||||
return strings.HasSuffix(b, "-mcp") || strings.HasSuffix(b, "_mcp") || strings.HasSuffix(b, "-mcp-server")
|
||||
},
|
||||
func(b string) bool { return strings.Contains(strings.ToLower(b), "mcp") },
|
||||
func(b string) bool {
|
||||
scope, _, ok := strings.Cut(strings.TrimPrefix(id, "@"), "/")
|
||||
return ok && strings.HasPrefix(id, "@") && b == scope
|
||||
},
|
||||
} {
|
||||
if b := one(f); b != "" {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// oldLine is the line magpie offered package p with before
|
||||
// runtimeArguments and the package's executables were read: the runtime,
|
||||
// the package, and its packageArguments as they came.
|
||||
func oldLine(p *registryPackage) (string, []string) {
|
||||
var cmd string
|
||||
var args []string
|
||||
switch p.RegistryType {
|
||||
case "npm":
|
||||
cmd, args = "npx", []string{"-y", p.Identifier}
|
||||
case "pypi":
|
||||
cmd, args = "uvx", []string{p.Identifier}
|
||||
default:
|
||||
return "", nil
|
||||
}
|
||||
for _, a := range p.Arguments {
|
||||
t, _ := a.tokens()
|
||||
args = append(args, t...)
|
||||
}
|
||||
return cmd, args
|
||||
}
|
||||
|
||||
func lineKey(cmd string, args []string) string {
|
||||
return cmd + "\x00" + strings.Join(args, "\x00")
|
||||
}
|
||||
|
||||
// marketFixes are the popular servers whose line is not the one magpie
|
||||
// offered before, by that old line: a library that has one installed from
|
||||
// the market unchanged (Serena's `uvx serena-agent`, which exits 2) is
|
||||
// given the line that starts it.
|
||||
var marketFixes = sync.OnceValue(func() map[string]*Server {
|
||||
var snap []registryServer
|
||||
if json.Unmarshal(serversSnapshot, &snap) != nil {
|
||||
return nil
|
||||
}
|
||||
fixes := map[string]*Server{}
|
||||
for i := range snap {
|
||||
m, ok := fromRegistry(&snap[i])
|
||||
if !ok || m.server.Remote() {
|
||||
continue
|
||||
}
|
||||
kind := map[string]string{"npx": "npm", "uvx": "pypi"}[m.server.Command]
|
||||
for j := range snap[i].Packages {
|
||||
p := &snap[i].Packages[j]
|
||||
if p.RegistryType != kind || p.Identifier == "" || (p.Transport.Type != "" && p.Transport.Type != "stdio") {
|
||||
continue // not the package fromRegistry took
|
||||
}
|
||||
if cmd, args := oldLine(p); lineKey(cmd, args) != lineKey(m.server.Command, m.server.Args) {
|
||||
s := m.server
|
||||
fixes[lineKey(cmd, args)] = &s
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return fixes
|
||||
})
|
||||
|
||||
// healMarketLines gives each server installed from the market with a line
|
||||
// that never started the line that does, keeping all else of it.
|
||||
func (l *Library) healMarketLines() {
|
||||
fixes := marketFixes()
|
||||
if len(fixes) == 0 {
|
||||
return
|
||||
}
|
||||
for _, s := range l.MCP {
|
||||
if s == nil || s.Remote() || (s.Command != "uvx" && s.Command != "npx") {
|
||||
continue
|
||||
}
|
||||
if f := fixes[lineKey(s.Command, s.Args)]; f != nil {
|
||||
s.Args = slices.Clone(f.Args)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
toml "github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
// fwxkogaia on X: Serena installed from the market showed "已退出 (2)".
|
||||
// magpie ran `uvx serena-agent`, which prints its help and exits 2: the
|
||||
// registry has uvx run it with start-mcp-server, among its
|
||||
// runtimeArguments. Each entry is the registry's own, as it lists it; a
|
||||
// package's executables (bins) are the market crawl's.
|
||||
func TestRegistryLaunchLines(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, entry string
|
||||
want string // command and arguments; "" when it isn't offered
|
||||
}{
|
||||
{"Serena: start-mcp-server among uvx's arguments, -p kept uvx's",
|
||||
`{"name": "io.github.oraios/serena", "packages": [{"registryType": "pypi", "identifier": "serena-agent", "runtimeHint": "uvx", "transport": {"type": "stdio"}, "runtimeArguments": [{"description": "Select the python version", "type": "named", "name": "-p", "value": "3.13"}, {"type": "positional", "value": "start-mcp-server"}, {"type": "positional", "value": "--project-from-cwd"}, {"description": "The name of a markdown file representing Serena's execution context", "default": "desktop-app", "type": "named", "name": "--context"}]}]}`,
|
||||
"uvx -p 3.13 serena-agent start-mcp-server --project-from-cwd --context desktop-app"},
|
||||
{"Docling: --from and the executable among uvx's",
|
||||
`{"name": "io.github.docling-project/docling-mcp", "packages": [{"registryType": "pypi", "identifier": "docling-mcp", "runtimeHint": "uvx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "named", "name": "--from", "value": "docling-mcp==3.5.0"}, {"type": "positional", "value": "docling-mcp-server"}, {"type": "named", "name": "--transport", "value": "stdio"}]}]}`,
|
||||
"uvx --from docling-mcp==3.5.0 docling-mcp-server --transport stdio"},
|
||||
{"terravision: --from with no executable, the program's own after",
|
||||
`{"name": "io.github.patrickchugh/terravision", "packages": [{"registryType": "pypi", "identifier": "terravision", "runtimeHint": "uvx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "named", "name": "--from", "value": "terravision[mcp]"}], "packageArguments": [{"type": "positional", "value": "mcp"}], "bins": ["terravision"]}]}`,
|
||||
"uvx --from terravision[mcp] terravision mcp"},
|
||||
{"visualtorch: --from among the program's arguments",
|
||||
`{"name": "io.github.willyfh/visualtorch", "packages": [{"registryType": "pypi", "identifier": "visualtorch", "runtimeHint": "uvx", "transport": {"type": "stdio"}, "packageArguments": [{"type": "positional", "value": "--from"}, {"type": "positional", "value": "visualtorch[mcp]"}, {"type": "positional", "value": "visualtorch-mcp"}], "bins": ["visualtorch-mcp"]}]}`,
|
||||
"uvx --from visualtorch[mcp] visualtorch-mcp"},
|
||||
{"basic-memory: the whole line among uvx's, the package in it",
|
||||
`{"name": "io.github.basicmachines-co/basic-memory", "packages": [{"registryType": "pypi", "identifier": "basic-memory", "runtimeHint": "uvx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "named", "name": "--prerelease", "value": "allow"}, {"type": "positional", "value": "basic-memory"}, {"type": "positional", "value": "mcp"}]}]}`,
|
||||
"uvx --prerelease allow basic-memory mcp"},
|
||||
{"alfanous: python -m its module",
|
||||
`{"name": "io.github.Alfanous-team/alfanous", "packages": [{"registryType": "pypi", "identifier": "alfanous3-mcp", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "positional", "value": "-m"}, {"type": "positional", "value": "alfanous_mcp.mcp_server"}], "bins": ["alfanous-mcp"]}]}`,
|
||||
"uvx --from alfanous3-mcp python -m alfanous_mcp.mcp_server"},
|
||||
{"a PyPI package whose one executable has another name",
|
||||
`{"name": "io.github.vishalsachdev/canvas-mcp", "packages": [{"registryType": "pypi", "identifier": "canvas-mcp", "transport": {"type": "stdio"}, "bins": ["canvas-mcp-server"]}]}`,
|
||||
"uvx --from canvas-mcp canvas-mcp-server"},
|
||||
{"several executables, one for MCP",
|
||||
`{"name": "io.github.agent-next/polymarket-paper-trader", "packages": [{"registryType": "pypi", "identifier": "polymarket-paper-trader", "transport": {"type": "stdio"}, "bins": ["pm-trader", "pm-trader-mcp"]}]}`,
|
||||
"uvx --from polymarket-paper-trader pm-trader-mcp"},
|
||||
{"several executables, none standing out",
|
||||
`{"name": "io.github.flytohub/flyto-core", "packages": [{"registryType": "pypi", "identifier": "flyto-core", "transport": {"type": "stdio"}, "bins": ["flyto", "flyto-serve", "flyto-verification"]}]}`,
|
||||
""},
|
||||
{"a package PyPI doesn't have",
|
||||
`{"name": "io.github.feder-cr/aihawk", "packages": [{"registryType": "pypi", "identifier": "aihawk", "transport": {"type": "stdio"}, "bins": []}]}`,
|
||||
""},
|
||||
{"executables unknown (a search): as the registry says",
|
||||
`{"name": "io.github.x/y", "packages": [{"registryType": "pypi", "identifier": "y-mcp", "transport": {"type": "stdio"}}]}`,
|
||||
"uvx y-mcp"},
|
||||
{"Firebase: mcp among npx's arguments is the program's",
|
||||
`{"name": "io.github.firebase/firebase-mcp", "packages": [{"registryType": "npm", "identifier": "firebase-tools", "runtimeHint": "npx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "positional", "value": "mcp"}], "bins": ["firebase"]}]}`,
|
||||
"npx -y firebase-tools mcp"},
|
||||
{"olcli: --package among npx's, the executable among the program's",
|
||||
`{"name": "io.github.aloth/olcli", "packages": [{"registryType": "npm", "identifier": "@aloth/olcli", "runtimeHint": "npx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "positional", "value": "-y"}, {"type": "positional", "value": "--package"}], "packageArguments": [{"type": "positional", "value": "olcli-mcp"}]}]}`,
|
||||
"npx -y --package @aloth/olcli olcli-mcp"},
|
||||
{"pm-claude-skills: npx's whole line",
|
||||
`{"name": "io.github.mohitagw15856/pm-claude-skills", "packages": [{"registryType": "npm", "identifier": "pm-claude-skills", "runtimeHint": "npx", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "positional", "value": "-y"}, {"type": "positional", "value": "-p"}, {"type": "positional", "value": "pm-claude-skills"}, {"type": "positional", "value": "pm-claude-skills-mcp"}]}]}`,
|
||||
"npx -y --package pm-claude-skills pm-claude-skills-mcp"},
|
||||
{"an npm package with two executables, none its name",
|
||||
`{"name": "io.github.fkiene/llmtrim", "packages": [{"registryType": "npm", "identifier": "@llmtrim/cli", "transport": {"type": "stdio"}, "packageArguments": [{"type": "positional", "value": "mcp"}], "bins": ["llmtrim", "llmtrim-tray"]}]}`,
|
||||
"npx -y --package @llmtrim/cli llmtrim mcp"},
|
||||
{"an npm package's one executable: npx finds it",
|
||||
`{"name": "io.github.x/kaneo", "packages": [{"registryType": "npm", "identifier": "@kaneo/mcp", "transport": {"type": "stdio"}, "bins": ["kaneo-mcp"]}]}`,
|
||||
"npx -y @kaneo/mcp"},
|
||||
{"an npm package with no executable",
|
||||
`{"name": "io.github.enuno/unifi-mcp-server", "packages": [{"registryType": "npm", "identifier": "unifi-mcp-server", "transport": {"type": "stdio"}, "bins": []}]}`,
|
||||
""},
|
||||
{"MARM: docker's own, the entrypoint too, before the image",
|
||||
`{"name": "io.github.Lyellr88/marm-mcp-server", "packages": [{"registryType": "oci", "identifier": "lyellr88/marm-mcp-server:2.60.1", "runtimeHint": "docker", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "named", "name": "-i"}, {"type": "named", "name": "--rm"}, {"type": "named", "name": "--mount", "value": "type=volume,src=marm-data,dst=/home/marm/.marm"}, {"type": "named", "name": "-e", "value": "HOME=/home/marm"}, {"type": "named", "name": "--entrypoint", "value": "marm-mcp-stdio"}]}]}`,
|
||||
"docker run -i --rm --mount type=volume,src=marm-data,dst=/home/marm/.marm -e HOME=/home/marm --entrypoint marm-mcp-stdio lyellr88/marm-mcp-server:2.60.1"},
|
||||
{"a docker option magpie can't fill",
|
||||
`{"name": "io.github.kOlapsis/maintenant", "packages": [{"registryType": "oci", "identifier": "ghcr.io/kolapsis/maintenant:1.11.0", "transport": {"type": "stdio"}, "runtimeArguments": [{"type": "named", "name": "--volume", "value": "{data_volume}:/data", "isRequired": true}]}]}`,
|
||||
""},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m, ok := fromRegistry(registryEntry(t, c.entry))
|
||||
got := ""
|
||||
if ok {
|
||||
got = strings.Join(append([]string{m.server.Command}, m.server.Args...), " ")
|
||||
}
|
||||
if got != c.want {
|
||||
t.Errorf("runs %q, want %q", got, c.want)
|
||||
}
|
||||
if ok && m.Runs != m.server.Command {
|
||||
t.Errorf("Runs %q, command %q", m.Runs, m.server.Command)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The market's own Serena, from the crawl shipped with magpie, starts the
|
||||
// MCP server, and is the same server as the one it offered before.
|
||||
func TestPopularSerenaStarts(t *testing.T) {
|
||||
i := slices.IndexFunc(popularServers(), func(m MarketServer) bool { return m.ID == "io.github.oraios/serena" })
|
||||
if i < 0 {
|
||||
t.Fatal("the market has no Serena")
|
||||
}
|
||||
s := popularServers()[i].server
|
||||
if s.Command != "uvx" || !slices.Contains(s.Args, "start-mcp-server") || !slices.Contains(s.Args, "serena-agent") {
|
||||
t.Fatalf("Serena runs %s %q", s.Command, s.Args)
|
||||
}
|
||||
if k := serverKey(&s); k != "uvx serena-agent" {
|
||||
t.Errorf("key %q: an installed one wouldn't be found, nor keep its icon", k)
|
||||
}
|
||||
if p := packageOf(&s); p != "serena-agent" {
|
||||
t.Errorf("package %q", p)
|
||||
}
|
||||
}
|
||||
|
||||
// Serena installed before is given the line that starts it, in the library
|
||||
// and the agents. A server of the user's own with another line is left as
|
||||
// it is.
|
||||
func TestInstalledMarketLineHealed(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
seedLibrary(t,
|
||||
Server{Name: "serena", Transport: "stdio", Command: "uvx", Args: []string{"serena-agent"}, Env: map[string]string{"A": "b"}, Agents: []string{"codex"}},
|
||||
Server{Name: "mine", Transport: "stdio", Command: "uvx", Args: []string{"serena-agent", "start-mcp-server", "--context", "codex"}, Agents: []string{"codex"}},
|
||||
)
|
||||
ok(t)(Sync())
|
||||
want := []string{"-p", "3.13", "serena-agent", "start-mcp-server", "--project-from-cwd", "--context", "desktop-app"}
|
||||
var c struct {
|
||||
Servers map[string]struct {
|
||||
Command string `toml:"command"`
|
||||
Args []string `toml:"args"`
|
||||
Env map[string]string `toml:"env"`
|
||||
} `toml:"mcp_servers"`
|
||||
}
|
||||
if err := toml.Unmarshal([]byte(read(t, filepath.Join(h, ".codex", "config.toml"))), &c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := c.Servers["serena"]; got.Command != "uvx" || !slices.Equal(got.Args, want) || got.Env["A"] != "b" {
|
||||
t.Errorf("Codex starts serena as %+v", got)
|
||||
}
|
||||
if got := c.Servers["mine"]; !slices.Equal(got.Args, []string{"serena-agent", "start-mcp-server", "--context", "codex"}) {
|
||||
t.Errorf("the user's own line changed: %q", got.Args)
|
||||
}
|
||||
var l Library
|
||||
if err := json.Unmarshal([]byte(read(t, path())), &l); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range l.MCP {
|
||||
if s.Name == "serena" && !slices.Equal(s.Args, want) {
|
||||
t.Errorf("library.json keeps %q", s.Args)
|
||||
}
|
||||
}
|
||||
if res := ok(t)(Sync()); len(res.Changed) != 0 {
|
||||
t.Errorf("a second sync changed %v", res.Changed)
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -53,6 +53,7 @@ func runsHere(cmd string) bool {
|
||||
|
||||
// heal points magpie's own servers whose program isn't here at this magpie.
|
||||
func (l *Library) heal() {
|
||||
l.healMarketLines() // a market server's line that never started (market_launch.go)
|
||||
exe := ""
|
||||
for _, s := range l.MCP {
|
||||
if s == nil || !ownServer(s) || runsHere(s.Command) {
|
||||
|
||||
Reference in New Issue
Block a user