Skip to content

Commit 62abfee

Browse files
authored
Apply @cliffhall's suggestions to mcpServerOutputSchema.ts
1 parent 58d6fbe commit 62abfee

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/examples/server/mcpServerOutputSchema.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const server = new McpServer(
1515
}
1616
);
1717

18+
const weatherConditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"] as const;
19+
const windDirections = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"] as const;
20+
1821
// Define a tool with structured output - Weather data
1922
server.registerTool(
2023
"get_weather",
@@ -29,11 +32,11 @@ server.registerTool(
2932
celsius: z.number(),
3033
fahrenheit: z.number()
3134
}),
32-
conditions: z.enum(["sunny", "cloudy", "rainy", "stormy", "snowy"]),
35+
conditions: z.enum(weatherConditions),
3336
humidity: z.number().min(0).max(100),
3437
wind: z.object({
3538
speed_kmh: z.number(),
36-
direction: z.string()
39+
direction: z.enum(windDirections)
3740
})
3841
},
3942
},
@@ -43,7 +46,8 @@ server.registerTool(
4346
void country;
4447
// Simulate weather API call
4548
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)];
4751

4852
const structuredContent = {
4953
temperature: {
@@ -54,7 +58,8 @@ server.registerTool(
5458
humidity: Math.round(Math.random() * 100),
5559
wind: {
5660
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)]
5863
}
5964
};
6065

@@ -77,4 +82,4 @@ async function main() {
7782
main().catch((error) => {
7883
console.error("Server error:", error);
7984
process.exit(1);
80-
});
85+
});

0 commit comments

Comments
 (0)