feat(tools): rename get_random_words tool and improve error handling

This commit is contained in:
2026-02-22 19:12:13 -06:00
parent 8e19ae07bb
commit 8e353dce44

View File

@@ -5,30 +5,30 @@ import { getRandomWords } from "@/services/randomWord"
export const addRandomWordsTool = (server: McpServer) => { export const addRandomWordsTool = (server: McpServer) => {
server.registerTool( server.registerTool(
"get_random_words", "get_random_words_from_dict",
{ {
title: "Get Random Words", title: "Get Random Word From Dictionary",
description: "Get a list of random words from a dictionary.", description: "Get a list of random words from a dictionary.",
inputSchema: z.object({ inputSchema: z.object({
dictionary: z.string(), dictionary_name: z.string(),
count: z.number().optional().default(1) count: z.number().optional().default(1)
}) })
}, },
async (input) => { async (input) => {
try { try {
const words: string[] = (await readDictionary(input.dictionary)).split("\n") const words: string[] = (await readDictionary(input.dictionary_name)).split("\n")
return { content: [{ type: "text", text: getRandomWords(words, input.count).join("\n") }] } return { content: [{ type: "text", text: getRandomWords(words, input.count).join("\n") }] }
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof Error) {
return { return {
isError: true, isError: true,
content: [] content: [{ type: "text", text: `Error reading dictionary: ${error.message}` }]
} }
} }
return { return {
isError: true, isError: true,
content: [] content: [{ type: "text", text: "Unknown error reading dictionary" }]
} }
} }
} }