@@ -28,6 +28,7 @@ type AddCmd struct {
28
28
Runtime string
29
29
Source string
30
30
Format internalcmd.OutputFormat
31
+ AllowDeprecated bool
31
32
cfgLoader config.Loader
32
33
packagePrinter output.Printer [config.ServerEntry ]
33
34
registryBuilder registry.Builder
@@ -92,9 +93,24 @@ func NewAddCmd(baseCmd *internalcmd.BaseCmd, opt ...cmdopts.CmdOption) (*cobra.C
92
93
fmt .Sprintf ("Specify the output format (one of: %s)" , allowed .String ()),
93
94
)
94
95
96
+ cobraCommand .Flags ().BoolVar (
97
+ & c .AllowDeprecated ,
98
+ "allow-deprecated" ,
99
+ false ,
100
+ "Optional, allows server installations marked as deprecated to be added" ,
101
+ )
102
+
95
103
return cobraCommand , nil
96
104
}
97
105
106
+ // serverEntryOptions contains configuration for parsing a server entry
107
+ type serverEntryOptions struct {
108
+ Runtime runtime.Runtime
109
+ Tools []string
110
+ SupportedRuntimes []runtime.Runtime
111
+ AllowDeprecated bool
112
+ }
113
+
98
114
// run is configured (via NewAddCmd) to be called by the Cobra framework when the command is executed.
99
115
// It may return an error (or nil, when there is no error).
100
116
func (c * AddCmd ) run (cmd * cobra.Command , args []string ) error {
@@ -138,9 +154,15 @@ func (c *AddCmd) run(cmd *cobra.Command, args []string) error {
138
154
)
139
155
}
140
156
141
- entry , err := parseServerEntry (pkg , runtime .Runtime (c .Runtime ), c .Tools , c .MCPDSupportedRuntimes ())
157
+ opts := serverEntryOptions {
158
+ Runtime : runtime .Runtime (c .Runtime ),
159
+ Tools : c .Tools ,
160
+ SupportedRuntimes : c .MCPDSupportedRuntimes (),
161
+ AllowDeprecated : c .AllowDeprecated ,
162
+ }
163
+ entry , err := parseServerEntry (pkg , opts )
142
164
if err != nil {
143
- return handler .HandleError (fmt . Errorf ( "error parsing server entry: %w" , err ) )
165
+ return handler .HandleError (err )
144
166
}
145
167
146
168
cfg , err := c .cfgLoader .Load (flags .ConfigFile )
@@ -208,39 +230,49 @@ func selectRuntime(
208
230
return "" , fmt .Errorf ("no supported runtimes found" )
209
231
}
210
232
211
- func parseServerEntry (
212
- pkg packages.Server ,
213
- requestedRuntime runtime.Runtime ,
214
- requestedTools []string ,
215
- supportedRuntimes []runtime.Runtime ,
216
- ) (config.ServerEntry , error ) {
217
- requestedTools , err := filter .MatchRequestedSlice (requestedTools , pkg .Tools .Names ())
233
+ func parseServerEntry (pkg packages.Server , opts serverEntryOptions ) (config.ServerEntry , error ) {
234
+ requestedTools , err := filter .MatchRequestedSlice (opts .Tools , pkg .Tools .Names ())
218
235
if err != nil {
219
236
return config.ServerEntry {}, fmt .Errorf ("error matching requested tools: %w" , err )
220
237
}
221
238
222
- selectedRuntime , runtimeErr := selectRuntime (pkg .Installations , requestedRuntime , supportedRuntimes )
223
- if runtimeErr != nil {
224
- return config.ServerEntry {}, fmt .Errorf ("error selecting runtime from available installations: %w" , runtimeErr )
239
+ selectedRuntime , err := selectRuntime (pkg .Installations , opts .Runtime , opts .SupportedRuntimes )
240
+ if err != nil {
241
+ return config.ServerEntry {}, fmt .Errorf ("error selecting runtime from available installations: %w" , err )
242
+ }
243
+
244
+ installation , ok := pkg .Installations [selectedRuntime ]
245
+ if ! ok {
246
+ return config.ServerEntry {}, fmt .Errorf (
247
+ "installation not found for runtime '%s'" ,
248
+ selectedRuntime ,
249
+ )
225
250
}
226
251
227
- v := "latest"
228
- if installation , ok := pkg .Installations [selectedRuntime ]; ok && installation .Version != "" {
229
- v = installation .Version
252
+ if installation .Deprecated && ! opts .AllowDeprecated {
253
+ return config.ServerEntry {}, fmt .Errorf (
254
+ "server '%s' with runtime '%s' is deprecated, use --allow-deprecated flag to proceed" ,
255
+ pkg .ID ,
256
+ selectedRuntime ,
257
+ )
230
258
}
231
259
232
- runtimeSpecificName := pkg .Installations [selectedRuntime ].Package
233
- if runtimeSpecificName == "" {
260
+ if installation .Package == "" {
234
261
return config.ServerEntry {}, fmt .Errorf (
235
262
"installation package name is missing for runtime '%s'" ,
236
263
selectedRuntime ,
237
264
)
238
265
}
239
- runtimePackageVersion := fmt .Sprintf ("%s::%s@%s" , selectedRuntime , runtimeSpecificName , v )
240
266
241
- envs := packages .FilterArguments (pkg .Arguments , packages .EnvVar , packages .Required )
242
- args := packages .FilterArguments (pkg .Arguments , packages .ValueArgument , packages .Required )
243
- boolArgs := packages .FilterArguments (pkg .Arguments , packages .BoolArgument , packages .Required )
267
+ version := "latest"
268
+ if installation .Version != "" {
269
+ version = installation .Version
270
+ }
271
+
272
+ runtimePackageVersion := fmt .Sprintf ("%s::%s@%s" , selectedRuntime , installation .Package , version )
273
+ envs := pkg .Arguments .FilterBy (packages .Required , packages .EnvVar )
274
+ args := pkg .Arguments .FilterBy (packages .Required , packages .ValueAcceptingArgument )
275
+ boolArgs := pkg .Arguments .FilterBy (packages .Required , packages .BoolArgument )
244
276
245
277
return config.ServerEntry {
246
278
Name : pkg .ID ,
0 commit comments