@@ -17,11 +17,18 @@ import (
1717
1818type RemoveCmd struct {
1919 * cmd.BaseCmd
20+ ctxLoader context.Loader
2021}
2122
22- func NewRemoveCmd (baseCmd * cmd.BaseCmd , _ ... options.CmdOption ) (* cobra.Command , error ) {
23+ func NewRemoveCmd (baseCmd * cmd.BaseCmd , opt ... options.CmdOption ) (* cobra.Command , error ) {
24+ opts , err := options .NewOptions (opt ... )
25+ if err != nil {
26+ return nil , err
27+ }
28+
2329 c := & RemoveCmd {
24- BaseCmd : baseCmd ,
30+ BaseCmd : baseCmd ,
31+ ctxLoader : opts .ContextLoader ,
2532 }
2633
2734 // mcpd config args remove time -- --arg [--arg ...]
@@ -51,27 +58,27 @@ func (c *RemoveCmd) run(cmd *cobra.Command, args []string) error {
5158 argMap [key ] = struct {}{}
5259 }
5360
54- cfg , err := context . LoadExecutionContextConfig (flags .RuntimeFile )
61+ cfg , err := c . ctxLoader . Load (flags .RuntimeFile )
5562 if err != nil {
5663 return fmt .Errorf ("failed to load execution context config: %w" , err )
5764 }
5865
59- if serverCtx := cfg .Servers [serverName ]; serverCtx .Args != nil {
60- toRemove := slices .Collect (maps .Keys (argMap ))
61- filtered := config .RemoveMatchingFlags (serverCtx .Args , toRemove )
66+ serverCtx , ok := cfg .Get (serverName )
67+ if ! ok {
68+ return fmt .Errorf ("server '%s' not found in configuration" , serverName )
69+ }
6270
63- // Only modify the file if there are actual changes to be made.
64- if ! slices .Equal (slices .Clone (serverCtx .Args ), slices .Clone (filtered )) {
65- // Update the args, and the server.
66- serverCtx .Args = filtered
67- cfg .Servers [serverName ] = serverCtx
71+ toRemove := slices .Collect (maps .Keys (argMap ))
72+ filtered := config .RemoveMatchingFlags (serverCtx .Args , toRemove )
6873
69- if err := context .SaveExecutionContextConfig (flags .RuntimeFile , cfg ); err != nil {
70- return fmt .Errorf ("failed to save config: %w" , err )
71- }
72- }
74+ // Update the args, and the server.
75+ serverCtx .Args = filtered
76+ res , err := cfg .Upsert (serverCtx )
77+ if err != nil {
78+ return fmt .Errorf ("error removing arguments for server '%s': %w" , serverName , err )
7379 }
7480
75- fmt .Fprintf (cmd .OutOrStdout (), "✓ Args removed for server '%s': %v\n " , serverName , slices .Collect (maps .Keys (argMap )))
81+ fmt .Fprintf (cmd .OutOrStdout (), "✓ Arguments removed for server '%s' (operation: %s): %v\n " , serverName , string (res ), slices .Collect (maps .Keys (argMap )))
82+
7683 return nil
7784}
0 commit comments