You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `serve` subcommand **starts a toolbox server** without any
primitives. It WILL NOT run with config file. In the future, users could
use `serve` with a backend storage.
To stop or shutdown the server, user can just terminate the port. The
terminate signal will shutdown the server.
This new addition **WILL NOT** be a breaking change to existing users.
Users can still run toolbox as is.
**CLI command:**
```
toolbox serve
```
**Flags associated with the serve subcommand:**
| flag | description | default value |
| --- | --- | --- |
| address | Address of the interface the server will listen on. |
127.0.0.1 |
| port | Port the server will listen on. | 5000 |
| stdio | Listens via MCP STDIO instead of acting as a remote HTTP
server. | false |
| ui | Launches the Toolbox UI web server. | false |
| allowed-origins | Specifies a list of origins permitted to access this
server. | `*` |
| allowed-hosts | Specifies a list of hosts permitted to access this
server. | `*` |
**This PR does the following:**
* Add a new `serve` subcommand. Including unit tests for the subcommand
* Rename the `cmd/internal/persistent_flags.go` to
`cmd/internal/flags.go`, and refactored some flag definitions into
dedicated functions. This change allows us to scope flags to specific
subcommands as needed, rather than forcing all subcommands to inherit
them globally via `PersistentFlags`.
---------
Co-authored-by: Averi Kitsch <akitsch@google.com>
persistentFlags.StringVar(&opts.ToolsFile, "tools-file", "", "File path specifying the tool configuration. Cannot be used with --tools-files, or --tools-folder.")
32
-
persistentFlags.StringSliceVar(&opts.ToolsFiles, "tools-files", []string{}, "Multiple file paths specifying tool configurations. Files will be merged. Cannot be used with --tools-file, or --tools-folder.")
33
-
persistentFlags.StringVar(&opts.ToolsFolder, "tools-folder", "", "Directory path containing YAML tool configuration files. All .yaml and .yml files in the directory will be loaded and merged. Cannot be used with --tools-file, or --tools-files.")
persistentFlags.Var(&opts.Cfg.LoggingFormat, "logging-format", "Specify logging format to use. Allowed: 'standard' or 'JSON'.")
36
33
persistentFlags.BoolVar(&opts.Cfg.TelemetryGCP, "telemetry-gcp", false, "Enable exporting directly to Google Cloud Monitoring.")
37
34
persistentFlags.StringVar(&opts.Cfg.TelemetryOTLP, "telemetry-otlp", "", "Enable exporting using OpenTelemetry Protocol (OTLP) to the specified endpoint (e.g. 'http://127.0.0.1:4318')")
38
35
persistentFlags.StringVar(&opts.Cfg.TelemetryServiceName, "telemetry-service-name", "toolbox", "Sets the value of the service.name resource attribute for telemetry data.")
36
+
persistentFlags.StringSliceVar(&opts.Cfg.UserAgentMetadata, "user-agent-metadata", []string{}, "Appends additional metadata to the User-Agent.")
37
+
}
38
+
39
+
// ConfigFileFlags defines flags related to the configuration file.
40
+
// It should be applied to any command that requires configuration loading.
flags.StringVar(&opts.ToolsFile, "tools-file", "", "File path specifying the tool configuration. Cannot be used with --tools-files, or --tools-folder.")
43
+
flags.StringSliceVar(&opts.ToolsFiles, "tools-files", []string{}, "Multiple file paths specifying tool configurations. Files will be merged. Cannot be used with --tools-file, or --tools-folder.")
44
+
flags.StringVar(&opts.ToolsFolder, "tools-folder", "", "Directory path containing YAML tool configuration files. All .yaml and .yml files in the directory will be loaded and merged. Cannot be used with --tools-file, or --tools-files.")
39
45
// Fetch prebuilt tools sources to customize the help description
40
46
prebuiltHelp:=fmt.Sprintf(
41
47
"Use a prebuilt tool configuration by source type. Allowed: '%s'. Can be specified multiple times.",
flags.StringVarP(&opts.Cfg.Address, "address", "a", "127.0.0.1", "Address of the interface the server will listen on.")
56
+
flags.IntVarP(&opts.Cfg.Port, "port", "p", 5000, "Port the server will listen on.")
57
+
flags.BoolVar(&opts.Cfg.Stdio, "stdio", false, "Listens via MCP STDIO instead of acting as a remote HTTP server.")
58
+
flags.BoolVar(&opts.Cfg.UI, "ui", false, "Launches the Toolbox UI web server.")
59
+
60
+
flags.StringSliceVar(&opts.Cfg.AllowedOrigins, "allowed-origins", []string{"*"}, "Specifies a list of origins permitted to access this server. Defaults to '*'.")
61
+
flags.StringSliceVar(&opts.Cfg.AllowedHosts, "allowed-hosts", []string{"*"}, "Specifies a list of hosts permitted to access this server. Defaults to '*'.")
// setup flags that are common across all commands
112
113
internal.PersistentFlags(cmd, opts)
113
-
114
114
flags:=cmd.Flags()
115
-
116
-
flags.StringVarP(&opts.Cfg.Address, "address", "a", "127.0.0.1", "Address of the interface the server will listen on.")
117
-
flags.IntVarP(&opts.Cfg.Port, "port", "p", 5000, "Port the server will listen on.")
118
-
115
+
internal.ConfigFileFlags(flags, opts)
116
+
internal.ServeFlags(flags, opts)
119
117
flags.StringVar(&opts.ToolsFile, "tools_file", "", "File path specifying the tool configuration. Cannot be used with --tools-files, or --tools-folder.")
120
118
// deprecate tools_file
121
119
_=flags.MarkDeprecated("tools_file", "please use --tools-file instead")
122
-
flags.BoolVar(&opts.Cfg.Stdio, "stdio", false, "Listens via MCP STDIO instead of acting as a remote HTTP server.")
123
120
flags.BoolVar(&opts.Cfg.DisableReload, "disable-reload", false, "Disables dynamic reloading of tools file.")
124
-
flags.BoolVar(&opts.Cfg.UI, "ui", false, "Launches the Toolbox UI web server.")
125
-
// TODO: Insecure by default. Might consider updating this for v1.0.0
126
-
flags.StringSliceVar(&opts.Cfg.AllowedOrigins, "allowed-origins", []string{"*"}, "Specifies a list of origins permitted to access this server. Defaults to '*'.")
127
-
flags.StringSliceVar(&opts.Cfg.AllowedHosts, "allowed-hosts", []string{"*"}, "Specifies a list of hosts permitted to access this server. Defaults to '*'.")
128
121
flags.IntVar(&opts.Cfg.PollInterval, "poll-interval", 0, "Specifies the polling frequency (seconds) for configuration file updates.")
129
-
130
122
// wrap RunE command so that we have access to original Command object
0 commit comments