Skip to main content
Glama

reverse_text

Reverse text character-by-character or word-by-word. Also detects palindromes to identify text that reads the same forwards and backwards.

Instructions

Reverse text character-by-character or word-by-word.

Also detects if the text is a palindrome.

Args:

  • text (string): The text to reverse

  • reverse_words_only (boolean): Reverse word order only, not characters (default: false)

Returns: Reversed text, palindrome detection.

Example: reverse_text("hello") → "olleh"; reverse_text("racecar") → "racecar" (palindrome!)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text to reverse
reverse_words_onlyNoReverse word order only

Implementation Reference

  • The handler function that executes the core logic of the reverse_text tool: reverses the input text either character-by-character or word-by-word, detects palindromes, and returns structured output.
    export function reverseText(input: ReverseTextInput): ReverseTextOutput { const { text, reverse_words_only } = input; let reversed: string; if (reverse_words_only) { // Reverse order of words but keep each word's characters in order reversed = text.split(/(\s+)/).reverse().join(''); } else { // Reverse all characters reversed = [...text].reverse().join(''); } const normalizedOriginal = text.toLowerCase().replace(/[^a-z0-9]/g, ''); const normalizedReversed = [...normalizedOriginal].reverse().join(''); const is_palindrome = normalizedOriginal === normalizedReversed && normalizedOriginal.length > 0; const description = reverse_words_only ? `Words reversed: "${text}" → "${reversed}"` : `Characters reversed: "${text}" → "${reversed}"${is_palindrome ? ' (This is a palindrome!)' : ''}`; return { original: text, reversed, reverse_words_only, is_palindrome, description, }; }
  • TypeScript interfaces defining the input schema (text and reverse_words_only option) and output schema (reversed text, palindrome check, description) for the reverse_text tool.
    export interface ReverseTextInput { text: string; reverse_words_only: boolean; } export interface ReverseTextOutput { original: string; reversed: string; reverse_words_only: boolean; is_palindrome: boolean; description: string; }
  • src/index.ts:341-371 (registration)
    Registration of the reverse_text tool in the MCP server, defining Zod input schema, tool description, annotations, and wrapper that calls the reverseText handler.
    server.registerTool( "reverse_text", { title: "Reverse Text", description: `Reverse text character-by-character or word-by-word. Also detects if the text is a palindrome. Args: - text (string): The text to reverse - reverse_words_only (boolean): Reverse word order only, not characters (default: false) Returns: Reversed text, palindrome detection. Example: reverse_text("hello") → "olleh"; reverse_text("racecar") → "racecar" (palindrome!)`, inputSchema: z.object({ text: z.string().min(1).describe("The text to reverse"), reverse_words_only: z.boolean().default(false).describe("Reverse word order only"), }).strict(), annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }, }, async (params) => { const result = reverseText({ text: params.text, reverse_words_only: params.reverse_words_only, }); return { content: [{ type: "text" as const, text: result.description }], }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Aaryan-Kapoor/mcp-character-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server