transform-text
Convert text to uppercase, lowercase, capitalize words, reverse strings, or count words using this text transformation tool from the Demo MCP Server.
Instructions
Transform text case and format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to transform | |
| operation | Yes | Transformation operation to apply |
Implementation Reference
- src/tools/text-processing-tools.ts:32-66 (handler)Handler function that executes the transform-text tool logic. Takes input text and operation (uppercase, lowercase, capitalize, reverse, word-count), performs the transformation, and returns the result as text content.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 for the transform-text tool, validating 'text' as string and 'operation' as one of the specified enum values.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, including name, metadata (title, description), input schema, 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 } ] }; } );