UNPKG

it-tools-mcp

Version:

Full MCP 2025-06-18 compliant server with 121+ IT tools, logging, ping, progress tracking, cancellation, and sampling utilities

40 lines (38 loc) 1.44 kB
import { z } from "zod"; export function registerDistinctWords(server) { server.registerTool("analyze_distinct_words", { description: "Count distinct words in text and show their frequency", inputSchema: { text: z.string().describe("Text to analyze for distinct words") }, // VS Code compliance annotations annotations: { title: "Analyze Distinct Words", description: "Count distinct words in text and show their frequency", readOnlyHint: true } }, async ({ text }) => { // Remove punctuation and split into words const cleanedText = text.replace(/[^\w\s]/g, ' ').toLowerCase(); const words = cleanedText.split(/\s+/).filter(word => word.length > 0); // Count word frequencies const wordCount = {}; words.forEach(word => { wordCount[word] = (wordCount[word] || 0) + 1; }); // Sort by frequency (descending) const sortedWords = Object.entries(wordCount) .sort(([, a], [, b]) => b - a); const result = sortedWords.map(([word, count]) => `${word}: ${count}`).join('\n'); return { content: [{ type: "text", text: `Distinct Words Analysis: Total unique words: ${sortedWords.length} Total words: ${words.length} Word frequencies: ${result}` }] }; }); }