@@ -1497,14 +1497,15 @@ using ModelContextProtocol.Server;
1497
1497
using System .ComponentModel ;
1498
1498
using System .Net .Http .Json ;
1499
1499
using System .Text .Json ;
1500
+ using System .Globalization ;
1500
1501
1501
1502
namespace QuickstartWeatherServer .Tools ;
1502
1503
1503
1504
[McpServerToolType ]
1504
1505
public static class WeatherTools
1505
1506
{
1506
1507
[McpServerTool ,
1507
- Description (@"
1508
+ Description (@"
1508
1509
Get weather alerts for a US state.
1509
1510
Args:
1510
1511
State: Two-letter US state code (e.g. CA, NY)
@@ -1521,39 +1522,41 @@ public static class WeatherTools
1521
1522
return " No active alerts for this state." ;
1522
1523
}
1523
1524
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 $"""
1528
1530
Event: {properties .GetProperty (" event" ).GetString ()}
1529
1531
Area: {properties .GetProperty (" areaDesc" ).GetString ()}
1530
1532
Severity: {properties .GetProperty (" severity" ).GetString ()}
1531
1533
Description: {properties .GetProperty (" description" ).GetString ()}
1532
1534
Instruction: {properties .GetProperty (" instruction" ).GetString ()}
1533
1535
""" ;
1534
- }));
1536
+ }));
1535
1537
}
1536
1538
1537
1539
[McpServerTool ,
1538
1540
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.
1544
1545
" )]
1545
1546
public static async Task <string > GetForecast (
1546
1547
HttpClient client ,
1547
1548
[Description (" Latitude of the location." )] double latitude ,
1548
1549
[Description (" Longitude of the location." )] double longitude )
1549
1550
{
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 );
1551
1553
var forecastUrl = jsonElement .GetProperty (" properties" ).GetProperty (" forecast" ).GetString ();
1552
1554
1553
1555
jsonElement = await client .GetFromJsonAsync <JsonElement >(forecastUrl );
1554
1556
var periods = jsonElement .GetProperty (" properties" ).GetProperty (" periods" ).EnumerateArray ();
1555
1557
1556
- return string .Join (" \n ---\n " , periods .Select (period => $"""
1558
+ return string .Join (" \n ---\n " ,
1559
+ periods .Select (period => $"""
1557
1560
{period .GetProperty (" name" ).GetString ()}
1558
1561
Temperature: {period .GetProperty (" temperature" ).GetInt32 ()}°F
1559
1562
Wind: {period .GetProperty (" windSpeed" ).GetString ()} {period .GetProperty (" windDirection" ).GetString ()}
0 commit comments