Compare commits

..

1 Commits

Author SHA1 Message Date
Yuan Teoh
392490d668 feat: add new user-agent-extra flag 2026-01-13 11:44:51 -08:00
6 changed files with 21 additions and 91 deletions

View File

@@ -384,6 +384,7 @@ func NewCommand(opts ...Option) *Command {
// TODO: Insecure by default. Might consider updating this for v1.0.0
flags.StringSliceVar(&cmd.cfg.AllowedOrigins, "allowed-origins", []string{"*"}, "Specifies a list of origins permitted to access this server. Defaults to '*'.")
flags.StringSliceVar(&cmd.cfg.AllowedHosts, "allowed-hosts", []string{"*"}, "Specifies a list of hosts permitted to access this server. Defaults to '*'.")
flags.StringSliceVar(&cmd.cfg.UserAgentExtra, "user-agent-extra", []string{}, "Appends additional metadata to the User-Agent.")
// wrap RunE command so that we have access to original Command object
cmd.RunE = func(*cobra.Command, []string) error { return run(cmd) }

View File

@@ -70,6 +70,9 @@ func withDefaults(c server.ServerConfig) server.ServerConfig {
if c.AllowedHosts == nil {
c.AllowedHosts = []string{"*"}
}
if c.UserAgentExtra == nil {
c.UserAgentExtra = []string{}
}
return c
}
@@ -230,6 +233,13 @@ func TestServerConfigFlags(t *testing.T) {
AllowedHosts: []string{"http://foo.com", "http://bar.com"},
}),
},
{
desc: "user agent extra",
args: []string{"--user-agent-extra", "foo,bar"},
want: withDefaults(server.ServerConfig{
UserAgentExtra: []string{"foo", "bar"},
}),
},
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {

View File

@@ -27,6 +27,7 @@ description: >
| | `--ui` | Launches the Toolbox UI web server. | |
| | `--allowed-origins` | Specifies a list of origins permitted to access this server for CORs access. | `*` |
| | `--allowed-hosts` | Specifies a list of hosts permitted to access this server to prevent DNS rebinding attacks. | `*` |
| | `--user-agent-extra` | Appends additional metadata to the User-Agent. | |
| `-v` | `--version` | version for toolbox | |
## Examples

View File

@@ -64,12 +64,14 @@ type ServerConfig struct {
Stdio bool
// DisableReload indicates if the user has disabled dynamic reloading for Toolbox.
DisableReload bool
// UI indicates if Toolbox UI endpoints (/ui) are available
// UI indicates if Toolbox UI endpoints (/ui) are available.
UI bool
// Specifies a list of origins permitted to access this server.
AllowedOrigins []string
// Specifies a list of hosts permitted to access this server
// Specifies a list of hosts permitted to access this server.
AllowedHosts []string
// UserAgentExtra specifies additional metadata to append to the User-Agent string.
UserAgentExtra []string
}
type logFormat string

View File

@@ -64,7 +64,11 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
map[string]prompts.Promptset,
error,
) {
ctx = util.WithUserAgent(ctx, cfg.Version)
metadataStr := cfg.Version
if len(cfg.UserAgentExtra) > 0 {
metadataStr += "+" + strings.Join(cfg.UserAgentExtra, ".")
}
ctx = util.WithUserAgent(ctx, metadataStr)
instrumentation, err := util.InstrumentationFromContext(ctx)
if err != nil {
panic(err)

View File

@@ -31,18 +31,6 @@
"default": "tools.yaml",
"isRequired": false
},
{
"type": "named",
"name": "--tools-files",
"description": "Multiple file paths specifying tool configurations. Files will be merged. Cannot be used with -tools-file or -tools-folder.",
"isRequired": false
},
{
"type": "named",
"name": "--tools-folder",
"description": "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.",
"isRequired": false
},
{
"type": "named",
"name": "--address",
@@ -82,82 +70,6 @@
"warn",
"error"
]
},
{
"type": "named",
"name": "--logging-format",
"description": "Specify logging format to use.",
"default": "standard",
"choices": [
"standard",
"json"
]
},
{
"type": "named",
"name": "--disable-reload",
"description": "Disables dynamic reloading of tools file.",
"format": "boolean",
"isRequired": false
},
{
"type": "named",
"name": "--prebuilt",
"description": "Use a prebuilt tool configuration by source type.",
"isRequired": false
},
{
"type": "named",
"name": "--stdio",
"description": "Listens via MCP STDIO instead of acting as a remote HTTP server.",
"format": "boolean",
"isRequired": false
},
{
"type": "named",
"name": "--telemetry-gcp",
"description": "Enable exporting directly to Google Cloud Monitoring.",
"format": "boolean",
"isRequired": false
},
{
"type": "named",
"name": "--telemetry-otlp",
"description": "Enable exporting using OpenTelemetry Protocol (OTLP) to the specified endpoint (e.g. 'http://127.0.0.1:4318').",
"isRequired": false
},
{
"type": "named",
"name": "--telemetry-service-name",
"description": "Sets the value of the service.name resource attribute for telemetry data.",
"default": "toolbox",
"isRequired": false
},
{
"type": "named",
"name": "--ui",
"description": "Launches the Toolbox UI web server.",
"format": "boolean",
"isRequired": false
},
{
"type": "named",
"name": "--allowed-origins",
"description": "Specifies a list of origins permitted to access this server.",
"default": "*",
"isRequired": false
},
{
"type": "named",
"name": "--help",
"description": "Show help for toolbox",
"isRequired": false
},
{
"type": "named",
"name": "--version",
"description": "Show version for toolbox",
"isRequired": false
}
]
}