Skip to main content
Glama

text_transform

Transform text with operations including case changes, Base64 encoding, slug generation, word count, and duplicate removal.

Instructions

Transform text using various operations.

Supported operations:

  • "uppercase": Convert to UPPERCASE

  • "lowercase": Convert to lowercase

  • "titlecase": Convert to Title Case

  • "camelcase": Convert to camelCase

  • "snakecase": Convert to snake_case

  • "kebabcase": Convert to kebab-case

  • "reverse": Reverse the text

  • "trim": Remove leading/trailing whitespace

  • "slug": URL-safe slug (lowercase, hyphens, no special chars)

  • "base64_encode": Encode to Base64

  • "base64_decode": Decode from Base64

  • "word_count": Count words, characters, sentences, and paragraphs

  • "remove_duplicates": Remove duplicate lines

  • "sort_lines": Sort lines alphabetically

  • "extract_emails": Extract all email addresses from text

  • "extract_urls": Extract all URLs from text

  • "hash": Simple hash summary (character frequency)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe input text to transform.
operationYesThe transformation operation to apply (see list above).

Implementation Reference

  • The main tool handler function that performs text transformations. It accepts 'text' and 'operation' parameters and uses a switch statement to handle 17 different operations: uppercase, lowercase, titlecase, camelcase, snakecase, kebabcase, reverse, trim, slug, base64_encode, base64_decode, word_count, remove_duplicates, sort_lines, extract_emails, extract_urls, hash. Returns JSON response with operation metadata and result.
        async ({ text, operation }) => {
          try {
            let result: string;
    
            switch (operation) {
              case "uppercase":
                result = text.toUpperCase();
                break;
    
              case "lowercase":
                result = text.toLowerCase();
                break;
    
              case "titlecase":
                result = text.replace(
                  /\w\S*/g,
                  (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
                );
                break;
    
              case "camelcase":
                result = toCamelCase(text);
                break;
    
              case "snakecase":
                result = toSnakeCase(text);
                break;
    
              case "kebabcase":
                result = toSnakeCase(text).replace(/_/g, "-");
                break;
    
              case "reverse":
                result = [...text].reverse().join("");
                break;
    
              case "trim":
                result = text.trim();
                break;
    
              case "slug":
                result = text
                  .toLowerCase()
                  .trim()
                  .replace(/[^\w\s-]/g, "")
                  .replace(/[\s_]+/g, "-")
                  .replace(/-+/g, "-")
                  .replace(/^-|-$/g, "");
                break;
    
              case "base64_encode":
                result = Buffer.from(text, "utf-8").toString("base64");
                break;
    
              case "base64_decode":
                result = Buffer.from(text, "base64").toString("utf-8");
                break;
    
              case "word_count": {
                const words = text.trim().split(/\s+/).filter(Boolean).length;
                const chars = text.length;
                const charsNoSpaces = text.replace(/\s/g, "").length;
                const sentences = text.split(/[.!?]+/).filter(Boolean).length;
                const paragraphs = text
                  .split(/\n\s*\n/)
                  .filter((p) => p.trim().length > 0).length;
                const lines = text.split("\n").length;
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        {
                          words,
                          characters: chars,
                          charactersNoSpaces: charsNoSpaces,
                          sentences,
                          paragraphs,
                          lines,
                          averageWordLength: chars > 0
                            ? (charsNoSpaces / words).toFixed(1)
                            : 0,
                        },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              case "remove_duplicates": {
                const lines = text.split("\n");
                const seen = new Set<string>();
                const unique: string[] = [];
                for (const line of lines) {
                  if (!seen.has(line)) {
                    seen.add(line);
                    unique.push(line);
                  }
                }
                result = unique.join("\n");
                break;
              }
    
              case "sort_lines":
                result = text
                  .split("\n")
                  .sort((a, b) => a.localeCompare(b))
                  .join("\n");
                break;
    
              case "extract_emails": {
                const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
                const emails = [...new Set(text.match(emailRegex) || [])];
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        { count: emails.length, emails },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              case "extract_urls": {
                const urlRegex =
                  /https?:\/\/[^\s<>"{}|\\^`\]]+/g;
                const urls = [...new Set(text.match(urlRegex) || [])];
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        { count: urls.length, urls },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              default:
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: `Error: Unknown operation '${operation}'. Valid operations: uppercase, lowercase, titlecase, camelcase, snakecase, kebabcase, reverse, trim, slug, base64_encode, base64_decode, word_count, remove_duplicates, sort_lines, extract_emails, extract_urls, hash`,
                    },
                  ],
                  isError: true,
                };
            }
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      operation,
                      inputLength: text.length,
                      outputLength: result.length,
                      result,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (err: any) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Text Transform Error: ${err.message}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • Input schema for the text_transform tool. Defines 'text' (string) and 'operation' (string) parameters using Zod validation.
    {
      text: z.string().describe("The input text to transform."),
      operation: z
        .string()
        .describe("The transformation operation to apply (see list above)."),
    },
  • Registration function (registerTextTransformTool) that calls server.tool(...) with name 'text_transform', description, schema, and handler.
    export function registerTextTransformTool(server: McpServer): void {
      server.tool(
        "text_transform",
        `Transform text using various operations.
    
    Supported operations:
      - "uppercase":        Convert to UPPERCASE
      - "lowercase":        Convert to lowercase
      - "titlecase":        Convert to Title Case
      - "camelcase":        Convert to camelCase
      - "snakecase":        Convert to snake_case
      - "kebabcase":        Convert to kebab-case
      - "reverse":          Reverse the text
      - "trim":             Remove leading/trailing whitespace
      - "slug":             URL-safe slug (lowercase, hyphens, no special chars)
      - "base64_encode":    Encode to Base64
      - "base64_decode":    Decode from Base64
      - "word_count":       Count words, characters, sentences, and paragraphs
      - "remove_duplicates": Remove duplicate lines
      - "sort_lines":       Sort lines alphabetically
      - "extract_emails":   Extract all email addresses from text
      - "extract_urls":     Extract all URLs from text
      - "hash":             Simple hash summary (character frequency)`,
        {
          text: z.string().describe("The input text to transform."),
          operation: z
            .string()
            .describe("The transformation operation to apply (see list above)."),
        },
        async ({ text, operation }) => {
          try {
            let result: string;
    
            switch (operation) {
              case "uppercase":
                result = text.toUpperCase();
                break;
    
              case "lowercase":
                result = text.toLowerCase();
                break;
    
              case "titlecase":
                result = text.replace(
                  /\w\S*/g,
                  (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
                );
                break;
    
              case "camelcase":
                result = toCamelCase(text);
                break;
    
              case "snakecase":
                result = toSnakeCase(text);
                break;
    
              case "kebabcase":
                result = toSnakeCase(text).replace(/_/g, "-");
                break;
    
              case "reverse":
                result = [...text].reverse().join("");
                break;
    
              case "trim":
                result = text.trim();
                break;
    
              case "slug":
                result = text
                  .toLowerCase()
                  .trim()
                  .replace(/[^\w\s-]/g, "")
                  .replace(/[\s_]+/g, "-")
                  .replace(/-+/g, "-")
                  .replace(/^-|-$/g, "");
                break;
    
              case "base64_encode":
                result = Buffer.from(text, "utf-8").toString("base64");
                break;
    
              case "base64_decode":
                result = Buffer.from(text, "base64").toString("utf-8");
                break;
    
              case "word_count": {
                const words = text.trim().split(/\s+/).filter(Boolean).length;
                const chars = text.length;
                const charsNoSpaces = text.replace(/\s/g, "").length;
                const sentences = text.split(/[.!?]+/).filter(Boolean).length;
                const paragraphs = text
                  .split(/\n\s*\n/)
                  .filter((p) => p.trim().length > 0).length;
                const lines = text.split("\n").length;
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        {
                          words,
                          characters: chars,
                          charactersNoSpaces: charsNoSpaces,
                          sentences,
                          paragraphs,
                          lines,
                          averageWordLength: chars > 0
                            ? (charsNoSpaces / words).toFixed(1)
                            : 0,
                        },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              case "remove_duplicates": {
                const lines = text.split("\n");
                const seen = new Set<string>();
                const unique: string[] = [];
                for (const line of lines) {
                  if (!seen.has(line)) {
                    seen.add(line);
                    unique.push(line);
                  }
                }
                result = unique.join("\n");
                break;
              }
    
              case "sort_lines":
                result = text
                  .split("\n")
                  .sort((a, b) => a.localeCompare(b))
                  .join("\n");
                break;
    
              case "extract_emails": {
                const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
                const emails = [...new Set(text.match(emailRegex) || [])];
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        { count: emails.length, emails },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              case "extract_urls": {
                const urlRegex =
                  /https?:\/\/[^\s<>"{}|\\^`\]]+/g;
                const urls = [...new Set(text.match(urlRegex) || [])];
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: JSON.stringify(
                        { count: urls.length, urls },
                        null,
                        2
                      ),
                    },
                  ],
                };
              }
    
              default:
                return {
                  content: [
                    {
                      type: "text" as const,
                      text: `Error: Unknown operation '${operation}'. Valid operations: uppercase, lowercase, titlecase, camelcase, snakecase, kebabcase, reverse, trim, slug, base64_encode, base64_decode, word_count, remove_duplicates, sort_lines, extract_emails, extract_urls, hash`,
                    },
                  ],
                  isError: true,
                };
            }
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      operation,
                      inputLength: text.length,
                      outputLength: result.length,
                      result,
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (err: any) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Text Transform Error: ${err.message}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • src/index.ts:55-57 (registration)
    Where registerTextTransformTool is called in the McpToolkitServer class to register the tool on the MCP server.
      registerTextTransformTool(this.server);
      registerEnvironmentTool(this.server);
    }
  • Helper function toCamelCase - converts a string to camelCase by splitting on spaces, underscores, and hyphens.
    export function toCamelCase(str: string): string {
      return str
        .replace(/[^a-zA-Z0-9\s_-]/g, "")
        .split(/[\s_-]+/)
        .filter(Boolean)
        .map((word, index) =>
          index === 0
            ? word.toLowerCase()
            : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
        )
        .join("");
    }
  • Helper function toSnakeCase - converts a string to snake_case by splitting on spaces and hyphens.
    export function toSnakeCase(str: string): string {
      return str
        .replace(/[^a-zA-Z0-9\s_-]/g, "")
        .split(/[\s-]+/)
        .filter(Boolean)
        .map((word) => word.toLowerCase())
        .join("_");
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, but the description thoroughly explains each operation's behavior, including edge cases like 'slug' (URL-safe slug) and 'hash' (character frequency). There is no contradiction with missing annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear opening line followed by a bulleted list. While it is somewhat lengthy due to the number of operations, each sentence serves a purpose. It is efficient for the content provided.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool lacks an output schema, but the description implies the return type (transformed text) for most operations. However, for operations like 'word_count' or 'extract_emails', the exact return format is not specified, leaving minor ambiguity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, and the description adds significant value by enumerating the valid operations and briefly explaining each. This goes beyond the schema's generic 'see list above' reference.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool transforms text using various operations, listing 17 specific operations. This is specific, action-oriented, and distinguishes it from sibling tools (none of which are text transformation tools).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description lists all supported operations, making it clear what can be done. However, it does not explicitly state when to use this tool versus alternatives, nor does it provide any 'when not to use' guidance. Nevertheless, the siblings are unrelated, so the context is sufficient.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/vyshnavi-nandyala/mcp-toolkit-server'

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