Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
668 changes: 112 additions & 556 deletions cmd/thv/app/otel.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/cli/thv_config_otel.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/cli/thv_config_otel_get-endpoint.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/cli/thv_config_otel_get-env-vars.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/cli/thv_config_otel_get-insecure.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions docs/cli/thv_config_otel_set-endpoint.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions docs/cli/thv_config_otel_set-env-vars.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions docs/cli/thv_config_otel_set-insecure.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions docs/cli/thv_config_otel_set-metrics-enabled.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions docs/cli/thv_config_otel_set-sampling-rate.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions docs/cli/thv_config_otel_set-tracing-enabled.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/cli/thv_config_otel_unset-insecure.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions pkg/config/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Package config provides configuration management for ToolHive, including a
// generic framework for easily adding new configuration fields.
//
// # Architecture
//
// The package uses a Provider pattern to abstract configuration storage:
// - DefaultProvider: Uses XDG config directories (~/.config/toolhive/config.yaml)
// - PathProvider: Uses a specific file path (useful for testing)
// - KubernetesProvider: No-op implementation for Kubernetes environments
//
// # Generic Config Field Framework
//
// The framework allows you to define config fields declaratively with minimal
// boilerplate. Fields are registered once with validation, getters, setters,
// and unseters.
//
// # Adding a New Config Field
//
// Step 1: Add your field to the Config struct:
//
// type Config struct {
// // ... existing fields ...
// MyNewField string `yaml:"my_new_field,omitempty"`
// }
//
// Step 2: Register the field using a helper constructor:
//
// func init() {
// // For simple string fields:
// config.RegisterStringField("my-field",
// func(cfg *Config) *string { return &cfg.MyNewField },
// validateMyField) // Optional validator
//
// // For boolean fields:
// config.RegisterBoolField("my-bool-field",
// func(cfg *Config) *bool { return &cfg.MyBoolField },
// nil) // nil = no validation
//
// // For float fields:
// config.RegisterFloatField("my-float-field",
// func(cfg *Config) *float64 { return &cfg.MyFloatField },
// 0.0, // zero value
// validateMyFloat)
//
// // For string slice fields (comma-separated):
// config.RegisterStringSliceField("my-list-field",
// func(cfg *Config) *[]string { return &cfg.MyListField },
// nil)
// }
//
// Step 3: Use the field through the generic framework:
//
// provider := config.NewDefaultProvider()
//
// // Set a value
// err := config.SetConfigField(provider, "my-field", "some-value")
//
// // Get a value
// value, isSet, err := config.GetConfigField(provider, "my-field")
//
// // Unset a value
// err := config.UnsetConfigField(provider, "my-field")
//
// # Advanced: Custom Field Registration
//
// For fields with complex logic, use RegisterConfigField directly:
//
// config.RegisterConfigField(config.ConfigFieldSpec{
// Name: "my-complex-field",
// SetValidator: func(_ Provider, value string) error {
// // Custom validation logic
// return nil
// },
// Setter: func(cfg *Config, value string) {
// // Custom setter logic
// },
// Getter: func(cfg *Config) string {
// // Custom getter logic
// return ""
// },
// Unsetter: func(cfg *Config) {
// // Custom unsetter logic
// },
// })
//
// # Validation Helpers
//
// The package provides common validation functions:
// - validateFilePath: Validates file exists and returns cleaned path
// - validateFileExists: Checks if file exists
// - validateJSONFile: Validates file is JSON format
// - validateURLScheme: Validates URL scheme (http/https)
// - makeAbsolutePath: Converts relative to absolute path
//
// Use these in your validator function for consistent error messages.
//
// # Built-in Fields
//
// The following fields are currently registered:
// - ca-cert: Path to a CA certificate file for TLS validation
// - registry-url: URL of the MCP server registry (HTTP/HTTPS)
// - registry-file: Path to a local JSON file containing the registry
// - otel-endpoint: OpenTelemetry OTLP endpoint
// - otel-sampling-rate: Trace sampling rate (0.0-1.0)
// - otel-env-vars: Environment variables for telemetry
// - otel-metrics-enabled: Enable metrics export
// - otel-tracing-enabled: Enable tracing export
// - otel-insecure: Use insecure connection
// - otel-enable-prometheus-metrics-path: Enable Prometheus endpoint
package config
Loading
Loading