@@ -15,6 +15,9 @@ const server = new McpServer(
15
15
}
16
16
) ;
17
17
18
+ const weatherConditions = [ "sunny" , "cloudy" , "rainy" , "stormy" , "snowy" ] as const ;
19
+ const windDirections = [ "N" , "NE" , "E" , "SE" , "S" , "SW" , "W" , "NW" ] as const ;
20
+
18
21
// Define a tool with structured output - Weather data
19
22
server . registerTool (
20
23
"get_weather" ,
@@ -29,11 +32,11 @@ server.registerTool(
29
32
celsius : z . number ( ) ,
30
33
fahrenheit : z . number ( )
31
34
} ) ,
32
- conditions : z . enum ( [ "sunny" , "cloudy" , "rainy" , "stormy" , "snowy" ] ) ,
35
+ conditions : z . enum ( weatherConditions ) ,
33
36
humidity : z . number ( ) . min ( 0 ) . max ( 100 ) ,
34
37
wind : z . object ( {
35
38
speed_kmh : z . number ( ) ,
36
- direction : z . string ( )
39
+ direction : z . enum ( windDirections )
37
40
} )
38
41
} ,
39
42
} ,
@@ -43,7 +46,8 @@ server.registerTool(
43
46
void country ;
44
47
// Simulate weather API call
45
48
const temp_c = Math . round ( ( Math . random ( ) * 35 - 5 ) * 10 ) / 10 ;
46
- const conditions = [ "sunny" , "cloudy" , "rainy" , "stormy" , "snowy" ] [ Math . floor ( Math . random ( ) * 5 ) ] as "sunny" | "cloudy" | "rainy" | "stormy" | "snowy" ;
49
+ const conditions =
50
+ weatherConditions [ Math . floor ( Math . random ( ) * weatherConditions . length ) ] ;
47
51
48
52
const structuredContent = {
49
53
temperature : {
@@ -54,7 +58,8 @@ server.registerTool(
54
58
humidity : Math . round ( Math . random ( ) * 100 ) ,
55
59
wind : {
56
60
speed_kmh : Math . round ( Math . random ( ) * 50 ) ,
57
- direction : [ "N" , "NE" , "E" , "SE" , "S" , "SW" , "W" , "NW" ] [ Math . floor ( Math . random ( ) * 8 ) ]
61
+ direction :
62
+ windDirections [ Math . floor ( Math . random ( ) * windDirections . length ) ]
58
63
}
59
64
} ;
60
65
@@ -77,4 +82,4 @@ async function main() {
77
82
main ( ) . catch ( ( error ) => {
78
83
console . error ( "Server error:" , error ) ;
79
84
process . exit ( 1 ) ;
80
- } ) ;
85
+ } ) ;
0 commit comments