Skip to main content
Glama
Aaryan-Kapoor

MCP Character Tools

reverse_text

Reverse text character-by-character or word-by-word, with palindrome detection. Use this tool to transform text order for analysis or creative purposes.

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 core handler function implementing the reverse_text tool logic: reverses text character-by-character or word-by-word, detects palindromes, and provides descriptive 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 (text and reverse_words_only option) and output (reversed text, palindrome check, description) types for the reverseText handler.
    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)
    MCP server registration of the 'reverse_text' tool, including Zod input schema validation, description, annotations, and wrapper calling 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 }],
        };
      }
    );
  • Zod runtime input schema for the reverse_text tool registration, validating text (non-empty string) and reverse_words_only (boolean, default false).
    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(),

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