mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(mcp): turn off a global server for Pi from the project switch
A Pi project entry replaces the global one and is skipped without a command or url, so a switch-only entry left the server on in Pi and the project page could not turn it off there. Reporters want a server off in one project while every other project keeps loading it. For a project under mcp.projects, the switch now writes the global server's command, or its url without the query, with enabled: false to the project's .pi/mcp.json. A disabled server never starts, so args, env and headers stay out of a file that may be committed, and every sync rewrites the entry from the global server. A project's own config cannot see the global server, so pi there is still refused. The migration that dropped pi from switch-only entries is gone. Refs #305
This commit is contained in:
+17
-1
@@ -2,6 +2,7 @@ package mcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@@ -21,10 +22,25 @@ func renderDisabled(target string, s Server) (map[string]any, error) {
|
||||
// Codex fails its whole config load with "invalid transport". The project file is
|
||||
// usually committed, so one person's switch would break Codex for a teammate.
|
||||
return nil, fmt.Errorf("codex cannot turn off a global server from a project file: on a machine whose global config lacks the server, Codex stops loading its whole config; set enabled = false in ~/.codex/config.toml instead")
|
||||
case target == "pi" && s.global != nil:
|
||||
// Pi replaces a global entry with the project entry of the same name and skips one
|
||||
// without a command or url. A disabled server is never started, so its command or
|
||||
// url alone is enough; args, env, headers and the url's query, which may hold a key,
|
||||
// stay out of the project file, which may be committed. Validate already refuses a
|
||||
// url with credentials or a fragment.
|
||||
if s.global.Command != "" {
|
||||
return map[string]any{"command": s.global.Command, "enabled": false}, nil
|
||||
}
|
||||
u, err := url.Parse(s.global.URL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pi: invalid url of the global server: %w", err)
|
||||
}
|
||||
u.RawQuery = ""
|
||||
return map[string]any{"url": u.String(), "enabled": false}, nil
|
||||
case target == "pi":
|
||||
// Pi replaces a global entry with the project entry of the same name, and skips one
|
||||
// without a command or url, so a switch-only entry leaves the global server on.
|
||||
return nil, fmt.Errorf("pi cannot turn off a global server with a switch-only entry: a Pi project entry replaces the global one, so it needs the server's command or url; add the complete server with piOptions: {\"enabled\": false} instead")
|
||||
return nil, fmt.Errorf("pi cannot turn off a server the global config does not define for it: a Pi project entry replaces the global one, so it needs the server's command or url; add the complete server with piOptions: {\"enabled\": false} instead")
|
||||
}
|
||||
return nil, fmt.Errorf("%s cannot turn off a global server from a project file; disabled supports claude, opencode and kilocode", target)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user