Skip to content

Commit bde0a65

Browse files
authored
Add schema version field to run config (#1424)
Now that the run config is part of our API contract, we need to consider backwards and forwards compatibility issues. As part of this - add a schema version field to the document so that we can add migration logic if needed.
1 parent e970e85 commit bde0a65

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/runner/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ import (
2424
"github.com/stacklok/toolhive/pkg/transport/types"
2525
)
2626

27+
// CurrentSchemaVersion is the current version of the RunConfig schema
28+
// TODO: Set to "v1.0.0" when we clean up the middleware configuration.
29+
const CurrentSchemaVersion = "v0.1.0"
30+
2731
// RunConfig contains all the configuration needed to run an MCP server
2832
// It is serializable to JSON and YAML
33+
// NOTE: This format is importable and exportable, and as a result should be
34+
// considered part of ToolHive's API contract.
2935
type RunConfig struct {
36+
// SchemaVersion is the version of the RunConfig schema
37+
SchemaVersion string `json:"schema_version" yaml:"schema_version"`
38+
3039
// Image is the Docker image to run
3140
Image string `json:"image" yaml:"image"`
3241

@@ -136,6 +145,10 @@ type RunConfig struct {
136145

137146
// WriteJSON serializes the RunConfig to JSON and writes it to the provided writer
138147
func (c *RunConfig) WriteJSON(w io.Writer) error {
148+
// Ensure the schema version is set
149+
if c.SchemaVersion == "" {
150+
c.SchemaVersion = CurrentSchemaVersion
151+
}
139152
encoder := json.NewEncoder(w)
140153
encoder.SetIndent("", " ")
141154
return encoder.Encode(c)
@@ -167,6 +180,11 @@ func ReadJSON(r io.Reader) (*RunConfig, error) {
167180
config.Secrets = []string{}
168181
}
169182

183+
// Set the default schema version if not set
184+
if config.SchemaVersion == "" {
185+
config.SchemaVersion = CurrentSchemaVersion
186+
}
187+
170188
return &config, nil
171189
}
172190

pkg/runner/config_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ func (b *RunConfigBuilder) Build(
321321
return nil, fmt.Errorf("failed to set environment variables: %v", err)
322322
}
323323

324+
// Set schema version.
325+
b.config.SchemaVersion = CurrentSchemaVersion
326+
324327
return b.config, nil
325328
}
326329

0 commit comments

Comments
 (0)