mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
Claude Code takes a whole server entry from one scope, so the lone switch used for OpenCode, Kilo Code and Pi would replace the server in .mcp.json instead of turning it off. In project mode a disabled entry for claude now adds the name to that project's disabledMcpServers list in ~/.claude.json, the list /mcp edits. It keys apart in the ledger from a user-scope server of the same name that a global config may own in the same file, and a name the person turned off themselves is never claimed or removed. A local scope server of the same name silently wins over what Skillshare writes, so project-mode plans now report it with the command to remove it. Checks against each Agent's documentation also showed gaps: - Detection missed Agents whose MCP file does not exist yet, such as a fresh Claude Code install, and listed every Agent in project mode. It now looks at the Agent's own folder and at project files. - Cline moved its settings to ~/.cline/data and honors CLINE_DIR, CLINE_DATA_DIR and CLINE_MCP_SETTINGS_PATH; the old VS Code path is kept only while it is the one in use. - Kilo Code ignores a project config that holds an environment reference, and Claude Code skips reserved names and reads its own credentials as empty for remote servers. These are refused up front, and the dashboard preview refuses them too. - An entry owned by a config that no longer exists could never be released; an explicit resolution may now take it over. - --disabled was accepted by commands that ignored it, and a relative XDG_CONFIG_HOME or Cline override was used as given. Refs #286
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package mcp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// keepBackups bounds the backups kept per Agent file; every write adds one.
|
|
const keepBackups = 20
|
|
|
|
// BackupInfo exposes metadata only, never the backed-up connection values.
|
|
type BackupInfo struct {
|
|
ID string `json:"id"`
|
|
Target string `json:"target"`
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
func (s *Service) Backups() ([]BackupInfo, error) {
|
|
result := []BackupInfo{}
|
|
owner, err := filepath.Abs(s.ConfigPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
records, err := s.backupRecords()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, record := range records {
|
|
if record.Owner == owner {
|
|
result = append(result, BackupInfo{ID: record.ID, Target: shownTarget(record.Target), Path: record.Path})
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// backupRecords returns backups newest first. Unreadable files are skipped so
|
|
// one damaged backup cannot hide the others.
|
|
func (s *Service) backupRecords() ([]backupRecord, error) {
|
|
dir := filepath.Join(s.StateDir, "mcp", "backups")
|
|
entries, err := os.ReadDir(dir)
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var records []backupRecord
|
|
// IDs start with a 19-digit nanosecond time, so name order is time order.
|
|
for i := len(entries) - 1; i >= 0; i-- {
|
|
name := entries[i].Name()
|
|
data, _, _, err := safeRead(filepath.Join(dir, name))
|
|
var record backupRecord
|
|
if err != nil || json.Unmarshal(data, &record) != nil || !backupID.MatchString(record.ID) || record.ID+".json" != name {
|
|
continue
|
|
}
|
|
records = append(records, record)
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
// backupSuffix ends every backup ID of one Agent file, so pruning can select
|
|
// them by name without decoding each backup.
|
|
func backupSuffix(path string) string { return digest([]byte(path))[:8] }
|
|
|
|
// pruneBackups keeps the newest backups of one Agent file. It is best effort:
|
|
// a backup that fails to delete only costs disk space.
|
|
func (s *Service) pruneBackups(path string) {
|
|
dir := filepath.Join(s.StateDir, "mcp", "backups")
|
|
entries, _ := os.ReadDir(dir)
|
|
suffix := "-" + backupSuffix(path) + ".json"
|
|
kept := 0
|
|
// IDs start with a 19-digit nanosecond time, so name order is time order.
|
|
for i := len(entries) - 1; i >= 0; i-- {
|
|
if name := entries[i].Name(); strings.HasSuffix(name, suffix) {
|
|
if kept++; kept > keepBackups {
|
|
_ = os.Remove(filepath.Join(dir, name))
|
|
}
|
|
}
|
|
}
|
|
}
|