From 88beed0069462eb0fcf34569d539f6d70ef28473 Mon Sep 17 00:00:00 2001 From: olaservo Date: Sat, 1 Aug 2026 15:05:16 -0700 Subject: [PATCH] Publish forecast periods in the shared shape Forecast.Periods reused ForecastPeriod, the struct that decodes the NWS response, so its camelCase json tags leaked into the declared outputSchema: temperatureUnit and detailedForecast where the other four quickstarts publish temperature_unit and detailed_forecast. Splits out a Period output type, for the same reason Alert is already separate from AlertProperties: the shape NWS sends and the shape the tool publishes are different contracts and should not be one struct. Co-Authored-By: Claude Opus 5 --- weather-server-go/main.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/weather-server-go/main.go b/weather-server-go/main.go index f18c2b5..ade4f5b 100644 --- a/weather-server-go/main.go +++ b/weather-server-go/main.go @@ -76,11 +76,23 @@ type Alert struct { Instructions string `json:"instructions" jsonschema:"What people in the area should do"` } +// Period is one element of Forecast's periods. ForecastPeriod above is the +// shape NWS sends; this is the shape the tool publishes, kept separate for the +// same reason Alert is separate from AlertProperties. +type Period struct { + Name string `json:"name"` + Temperature int `json:"temperature"` + TemperatureUnit string `json:"temperature_unit"` + WindSpeed string `json:"wind_speed"` + WindDirection string `json:"wind_direction"` + DetailedForecast string `json:"detailed_forecast"` +} + // Forecast is get_forecast's structured output: the object case. type Forecast struct { - Latitude float64 `json:"latitude" jsonschema:"Latitude the forecast is for"` - Longitude float64 `json:"longitude" jsonschema:"Longitude the forecast is for"` - Periods []ForecastPeriod `json:"periods" jsonschema:"The forecast periods, soonest first"` + Latitude float64 `json:"latitude" jsonschema:"Latitude the forecast is for"` + Longitude float64 `json:"longitude" jsonschema:"Longitude the forecast is for"` + Periods []Period `json:"periods" jsonschema:"The forecast periods, soonest first"` } func makeNWSRequest[T any](ctx context.Context, url string) (*T, error) { @@ -161,10 +173,22 @@ func getForecast(ctx context.Context, req *mcp.CallToolRequest, input ForecastIn // Show next 5 periods periods = periods[:min(5, len(periods))] + published := make([]Period, 0, len(periods)) + for _, period := range periods { + published = append(published, Period{ + Name: period.Name, + Temperature: period.Temperature, + TemperatureUnit: period.TemperatureUnit, + WindSpeed: period.WindSpeed, + WindDirection: period.WindDirection, + DetailedForecast: period.DetailedForecast, + }) + } + forecast := Forecast{ Latitude: input.Latitude, Longitude: input.Longitude, - Periods: periods, + Periods: published, } var formatted []string