@cicatriz/text-toolkit
Version:
Text Transformation & Formatting MCP Server for the Cline Marketplace
47 lines • 1.82 kB
JavaScript
/**
* Split case tool
*/
import { z } from "zod";
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
import { split } from "change-case";
import { validateNonEmptyString } from "../utils/index.js";
/**
* Register the split case tool with the MCP server
*/
export function registerSplitCase(server) {
// Register split tool
server.tool("split_text", "Split text into words using change-case split utility", {
text: z.string().describe("The text to split into words"),
join_with: z.string().optional().describe("Optional delimiter to join the words with")
}, async ({ text, join_with }) => {
validateNonEmptyString(text, "Text");
try {
// Split the text into words
const words = split(text);
// Convert all words to lowercase
const lowercaseWords = words.map(word => word.toLowerCase());
// Join the words if a delimiter is provided
const result = join_with !== undefined
? lowercaseWords.join(join_with)
: lowercaseWords;
return {
content: [
{
type: "text",
text: JSON.stringify({
words: lowercaseWords,
result: join_with !== undefined ? lowercaseWords.join(join_with) : undefined
}, null, 2)
}
]
};
}
catch (error) {
if (error instanceof McpError) {
throw error;
}
throw new McpError(ErrorCode.InternalError, `Error processing tool: ${error instanceof Error ? error.message : String(error)}`);
}
});
}
//# sourceMappingURL=split-case.js.map