1+ using ModelContextProtocol ;
12using ModelContextProtocol . Server ;
23using System . ComponentModel ;
34using System . Net . Http . Json ;
67namespace QuickstartWeatherServer . Tools ;
78
89[ McpServerToolType ]
9- public static class WeatherTools
10+ public sealed class WeatherTools
1011{
1112 [ McpServerTool , Description ( "Get weather alerts for a US state." ) ]
1213 public static async Task < string > GetAlerts (
1314 HttpClient client ,
1415 [ Description ( "The US state to get alerts for." ) ] string state )
1516 {
16- var jsonElement = await client . GetFromJsonAsync < JsonElement > ( $ "/alerts/active/area/{ state } ") ;
17+ using var jsonDocument = await client . ReadJsonDocument ( $ "/alerts/active/area/{ state } ") ;
18+ var jsonElement = jsonDocument . RootElement ;
1719 var alerts = jsonElement . GetProperty ( "features" ) . EnumerateArray ( ) ;
1820
1921 if ( ! alerts . Any ( ) )
@@ -40,7 +42,8 @@ public static async Task<string> GetForecast(
4042 [ Description ( "Latitude of the location." ) ] double latitude ,
4143 [ Description ( "Longitude of the location." ) ] double longitude )
4244 {
43- var jsonElement = await client . GetFromJsonAsync < JsonElement > ( $ "/points/{ latitude } ,{ longitude } ") ;
45+ using var jsonDocument = await client . ReadJsonDocument ( $ "/points/{ latitude } ,{ longitude } ") ;
46+ var jsonElement = jsonDocument . RootElement ;
4447 var periods = jsonElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
4548
4649 return string . Join ( "\n ---\n " , periods . Select ( period => $ """
0 commit comments