ServerFromSchema constructs a Server from a registry schema, choosing the preferred installation method. Returns an error when the schema has no installations defined.
(schema ServerSchema)
| 274 | // preferred installation method. Returns an error when the schema has no |
| 275 | // installations defined. |
| 276 | func ServerFromSchema(schema ServerSchema) (Server, error) { |
| 277 | _, entry, ok := schema.PreferredInstallation() |
| 278 | if !ok { |
| 279 | return Server{}, fmt.Errorf("mcp: schema %s has no installation methods", schema.Name) |
| 280 | } |
| 281 | server := Server{Name: schema.Name, Command: entry.Command, Args: entry.Args, Env: entry.Env} |
| 282 | if entry.URL != "" { |
| 283 | server.URL = entry.URL |
| 284 | server.Type = "http" |
| 285 | } else { |
| 286 | server.Type = "stdio" |
| 287 | } |
| 288 | return server, nil |
| 289 | } |