transform-text
Modify text case, format, or structure by applying operations like uppercase, lowercase, capitalize, reverse, or word count. Ideal for processing and transforming text efficiently.
Instructions
Transform text case and format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operation | Yes | Transformation operation to apply | |
| text | Yes | Text to transform |
Implementation Reference
- src/tools/text-processing-tools.ts:32-66 (handler)The asynchronous handler function that executes the text transformation logic based on the specified operation (uppercase, lowercase, capitalize, reverse, or word-count).async ({ text, operation }) => { let result: string; switch (operation) { case "uppercase": result = text.toUpperCase(); break; case "lowercase": result = text.toLowerCase(); break; case "capitalize": result = text.split(" ") .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(" "); break; case "reverse": result = text.split("").reverse().join(""); break; case "word-count": const wordCount = text.trim().split(/\s+/).filter(word => word.length > 0).length; result = `Word count: ${wordCount}`; break; default: result = "Unknown operation"; } return { content: [ { type: "text", text: result } ] }; }
- Zod-based input schema defining the parameters for the transform-text tool: text (string) and operation (enum of transformation types).inputSchema: { text: z.string().describe("Text to transform"), operation: z.enum([ "uppercase", "lowercase", "capitalize", "reverse", "word-count" ]).describe("Transformation operation to apply") } },
- src/tools/text-processing-tools.ts:16-67 (registration)Registration of the 'transform-text' tool on the MCP server, specifying name, metadata (title, description, inputSchema), and handler function.server.registerTool( "transform-text", { title: "Text Transformer", description: "Transform text case and format", inputSchema: { text: z.string().describe("Text to transform"), operation: z.enum([ "uppercase", "lowercase", "capitalize", "reverse", "word-count" ]).describe("Transformation operation to apply") } }, async ({ text, operation }) => { let result: string; switch (operation) { case "uppercase": result = text.toUpperCase(); break; case "lowercase": result = text.toLowerCase(); break; case "capitalize": result = text.split(" ") .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(" "); break; case "reverse": result = text.split("").reverse().join(""); break; case "word-count": const wordCount = text.trim().split(/\s+/).filter(word => word.length > 0).length; result = `Word count: ${wordCount}`; break; default: result = "Unknown operation"; } return { content: [ { type: "text", text: result } ] }; } );