From 9bec4ea62112170c99202f86d4b6c1e28d5ab5cc Mon Sep 17 00:00:00 2001 From: Dominik Guhr Date: Wed, 9 Apr 2025 12:21:35 +0200 Subject: [PATCH 1/2] Fixes #248 - Add CultureInfo.InvariantCulture to string interpolation for langitude and longitude so the sample works everywhere. --- samples/QuickstartWeatherServer/Tools/WeatherTools.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/QuickstartWeatherServer/Tools/WeatherTools.cs b/samples/QuickstartWeatherServer/Tools/WeatherTools.cs index 55548952..06be6aa4 100644 --- a/samples/QuickstartWeatherServer/Tools/WeatherTools.cs +++ b/samples/QuickstartWeatherServer/Tools/WeatherTools.cs @@ -1,6 +1,7 @@ using ModelContextProtocol; using ModelContextProtocol.Server; using System.ComponentModel; +using System.Globalization; using System.Text.Json; namespace QuickstartWeatherServer.Tools; @@ -41,7 +42,8 @@ public static async Task GetForecast( [Description("Latitude of the location.")] double latitude, [Description("Longitude of the location.")] double longitude) { - using var jsonDocument = await client.ReadJsonDocumentAsync($"/points/{latitude},{longitude}"); + var pointUrl = string.Format(CultureInfo.InvariantCulture, "points/{0},{1}", latitude, longitude); + using var jsonDocument = await client.ReadJsonDocumentAsync(pointUrl); var forecastUrl = jsonDocument.RootElement.GetProperty("properties").GetProperty("forecast").GetString() ?? throw new Exception($"No forecast URL provided by {client.BaseAddress}points/{latitude},{longitude}"); From e9db42183cde12f4f0126ad77501b1b5edf4b3d0 Mon Sep 17 00:00:00 2001 From: Dominik Guhr Date: Wed, 9 Apr 2025 13:29:42 +0200 Subject: [PATCH 2/2] Update samples/QuickstartWeatherServer/Tools/WeatherTools.cs Co-authored-by: Stephen Toub --- samples/QuickstartWeatherServer/Tools/WeatherTools.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/QuickstartWeatherServer/Tools/WeatherTools.cs b/samples/QuickstartWeatherServer/Tools/WeatherTools.cs index 06be6aa4..563d178a 100644 --- a/samples/QuickstartWeatherServer/Tools/WeatherTools.cs +++ b/samples/QuickstartWeatherServer/Tools/WeatherTools.cs @@ -42,7 +42,7 @@ public static async Task GetForecast( [Description("Latitude of the location.")] double latitude, [Description("Longitude of the location.")] double longitude) { - var pointUrl = string.Format(CultureInfo.InvariantCulture, "points/{0},{1}", latitude, longitude); + var pointUrl = string.Create(CultureInfo.InvariantCulture, $"/points/{latitude},{longitude}"); using var jsonDocument = await client.ReadJsonDocumentAsync(pointUrl); var forecastUrl = jsonDocument.RootElement.GetProperty("properties").GetProperty("forecast").GetString() ?? throw new Exception($"No forecast URL provided by {client.BaseAddress}points/{latitude},{longitude}");