@@ -1497,14 +1497,15 @@ using ModelContextProtocol.Server;
14971497using System .ComponentModel ;
14981498using System .Net .Http .Json ;
14991499using System .Text .Json ;
1500+ using System .Globalization ;
15001501
15011502namespace QuickstartWeatherServer .Tools ;
15021503
15031504[McpServerToolType ]
15041505public static class WeatherTools
15051506{
15061507 [McpServerTool ,
1507- Description (@"
1508+ Description (@"
15081509 Get weather alerts for a US state.
15091510 Args:
15101511 State: Two-letter US state code (e.g. CA, NY)
@@ -1521,39 +1522,41 @@ public static class WeatherTools
15211522 return " No active alerts for this state." ;
15221523 }
15231524
1524- return string .Join (" \n --\n " , alerts .Select (alert =>
1525- {
1526- JsonElement properties = alert .GetProperty (" properties" );
1527- return $"""
1525+ return string .Join (" \n --\n " ,
1526+ alerts .Select (alert =>
1527+ {
1528+ JsonElement properties = alert .GetProperty (" properties" );
1529+ return $"""
15281530 Event: {properties .GetProperty (" event" ).GetString ()}
15291531 Area: {properties .GetProperty (" areaDesc" ).GetString ()}
15301532 Severity: {properties .GetProperty (" severity" ).GetString ()}
15311533 Description: {properties .GetProperty (" description" ).GetString ()}
15321534 Instruction: {properties .GetProperty (" instruction" ).GetString ()}
15331535 """ ;
1534- }));
1536+ }));
15351537 }
15361538
15371539 [McpServerTool ,
15381540 Description (@"
1539- Get weather forecast for a location.
1540-
1541- Args:
1542- Latitude: Latitude of the location.
1543- Longitude: Longitude of the location.
1541+ Get weather forecast for a location.
1542+ Args:
1543+ Latitude: Latitude of the location.
1544+ Longitude: Longitude of the location.
15441545 " )]
15451546 public static async Task <string > GetForecast (
15461547 HttpClient client ,
15471548 [Description (" Latitude of the location." )] double latitude ,
15481549 [Description (" Longitude of the location." )] double longitude )
15491550 {
1550- var jsonElement = await client .GetFromJsonAsync <JsonElement >($" /points/{latitude },{longitude }" );
1551+ var pointUrl = string .Format (CultureInfo .InvariantCulture , " points/{0},{1}" , latitude , longitude );
1552+ var jsonElement = await client .GetFromJsonAsync <JsonElement >(pointUrl );
15511553 var forecastUrl = jsonElement .GetProperty (" properties" ).GetProperty (" forecast" ).GetString ();
15521554
15531555 jsonElement = await client .GetFromJsonAsync <JsonElement >(forecastUrl );
15541556 var periods = jsonElement .GetProperty (" properties" ).GetProperty (" periods" ).EnumerateArray ();
15551557
1556- return string .Join (" \n ---\n " , periods .Select (period => $"""
1558+ return string .Join (" \n ---\n " ,
1559+ periods .Select (period => $"""
15571560 {period .GetProperty (" name" ).GetString ()}
15581561 Temperature: {period .GetProperty (" temperature" ).GetInt32 ()}°F
15591562 Wind: {period .GetProperty (" windSpeed" ).GetString ()} {period .GetProperty (" windDirection" ).GetString ()}
0 commit comments