MCPcopy Create free account
hub / github.com/f/mcptools / Load

Function Load

pkg/alias/alias.go:38–65  ·  view source on GitHub ↗

Load loads server aliases from the configuration file.

()

Source from the content-addressed store, hash-verified

36
37// Load loads server aliases from the configuration file.
38func Load() (Aliases, error) {
39 configPath, err := GetConfigPath()
40 if err != nil {
41 return nil, err
42 }
43
44 aliases := make(Aliases)
45
46 var statErr error
47 if _, statErr = os.Stat(configPath); os.IsNotExist(statErr) {
48 return aliases, nil
49 }
50
51 configFile, err := os.ReadFile(configPath) // #nosec G304 - configPath is generated internally by GetConfigPath
52 if err != nil {
53 return nil, fmt.Errorf("failed to read alias config file: %w", err)
54 }
55
56 if len(configFile) == 0 {
57 return aliases, nil
58 }
59
60 if unmarshalErr := json.Unmarshal(configFile, &aliases); unmarshalErr != nil {
61 return nil, fmt.Errorf("failed to parse alias config file: %w", unmarshalErr)
62 }
63
64 return aliases, nil
65}
66
67// Save saves server aliases to the configuration file.
68func Save(aliases Aliases) error {

Callers 5

aliasAddCmdFunction · 0.92
aliasListCmdFunction · 0.92
aliasRemoveCmdFunction · 0.92
TestAliasCommandsFunction · 0.92
GetServerCommandFunction · 0.85

Calls 1

GetConfigPathFunction · 0.85

Tested by 1

TestAliasCommandsFunction · 0.74