Skip to main content
Glama
cablate

Simple Document Processing MCP Server

text_encoding_converter

Convert text file encoding from one character set to another, supporting formats like Big5, GBK, and UTF-8. Specify source and target encodings to handle legacy or localized text.

Instructions

Convert text between different encodings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input text file
outputDirYesDirectory where converted file should be saved
fromEncodingYesSource encoding (e.g., 'big5', 'gbk', 'utf8')
toEncodingYesTarget encoding (e.g., 'utf8', 'big5', 'gbk')

Implementation Reference

  • The async function that executes the text encoding conversion logic. Reads the file, decodes from the source encoding using iconv-lite, encodes to the target encoding, and writes the output file.
    export async function convertTextEncoding(
      inputPath: string,
      outputDir: string,
      fromEncoding: string,
      toEncoding: string
    ) {
      try {
        console.error(`Starting text encoding conversion...`);
        console.error(`Input file: ${inputPath}`);
        console.error(`Output directory: ${outputDir}`);
        console.error(`From encoding: ${fromEncoding}`);
        console.error(`To encoding: ${toEncoding}`);
    
        // 確保輸出目錄存在
        try {
          await fs.access(outputDir);
          console.error(`Output directory exists: ${outputDir}`);
        } catch {
          console.error(`Creating output directory: ${outputDir}`);
          await fs.mkdir(outputDir, { recursive: true });
          console.error(`Created output directory: ${outputDir}`);
        }
    
        const uniqueId = generateUniqueId();
        const content = await fs.readFile(inputPath);
        const text = iconv.decode(content, fromEncoding);
        const converted = iconv.encode(text, toEncoding);
    
        const outputPath = path.join(outputDir, `converted_${uniqueId}.txt`);
        await fs.writeFile(outputPath, converted);
        console.error(`Written converted text to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully converted text encoding: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in convertTextEncoding:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • The tool definition with name 'text_encoding_converter', description, and input schema requiring inputPath, outputDir, fromEncoding, and toEncoding.
    export const TEXT_ENCODING_CONVERT_TOOL: Tool = {
      name: "text_encoding_converter",
      description: "Convert text between different encodings",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input text file",
          },
          outputDir: {
            type: "string",
            description: "Directory where converted file should be saved",
          },
          fromEncoding: {
            type: "string",
            description: "Source encoding (e.g., 'big5', 'gbk', 'utf8')",
          },
          toEncoding: {
            type: "string",
            description: "Target encoding (e.g., 'utf8', 'big5', 'gbk')",
          },
        },
        required: ["inputPath", "outputDir", "fromEncoding", "toEncoding"],
      },
    };
  • The tools array that registers TEXT_ENCODING_CONVERT_TOOL as one of the available tools in the MCP server.
    export const tools = [DOCUMENT_READER_TOOL, PDF_MERGE_TOOL, PDF_SPLIT_TOOL, DOCX_TO_PDF_TOOL, DOCX_TO_HTML_TOOL, HTML_CLEAN_TOOL, HTML_TO_TEXT_TOOL, HTML_TO_MARKDOWN_TOOL, HTML_EXTRACT_RESOURCES_TOOL, HTML_FORMAT_TOOL, TEXT_DIFF_TOOL, TEXT_SPLIT_TOOL, TEXT_FORMAT_TOOL, TEXT_ENCODING_CONVERT_TOOL, EXCEL_READ_TOOL, FORMAT_CONVERTER_TOOL];
  • src/index.ts:240-263 (registration)
    The MCP server handler that routes the 'text_encoding_converter' tool call to the convertTextEncoding function.
    if (name === "text_encoding_converter") {
      const { inputPath, outputDir, fromEncoding, toEncoding } = args as {
        inputPath: string;
        outputDir: string;
        fromEncoding: string;
        toEncoding: string;
      };
      const result = await convertTextEncoding(
        inputPath,
        outputDir,
        fromEncoding,
        toEncoding
      );
      if (!result.success) {
        return {
          content: [{ type: "text", text: `Error: ${result.error}` }],
          isError: true,
        };
      }
      return {
        content: [{ type: "text", text: fileOperationResponse(result.data) }],
        isError: false,
      };
    }
  • The iconv-lite library import used for encoding/decoding in the convertTextEncoding handler.
    import iconv from "iconv-lite";
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It only says 'convert text between different encodings,' omitting details like file overwriting behavior, output file naming conventions, error handling for invalid encodings, or any side effects.

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

Conciseness3/5

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

The description is very concise (one sentence), but it sacrifices necessary detail. Conciseness is positive, but not at the expense of completeness; it should include more context to be truly effective.

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

Completeness2/5

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

Given the tool performs file conversion with no output schema, the description should explain return values, output file format, and potential side effects. It fails to provide this context, leaving agents to guess the tool's behavior.

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

Parameters3/5

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

The input schema has 100% coverage with descriptions for all four parameters. The description does not add extra meaning beyond what the schema provides, so it meets the baseline expectation.

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

Purpose4/5

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

The description clearly states the tool's purpose: converting text between encodings. It uses a specific verb and resource, and distinguishes itself from sibling tools like docx_to_html or text_formatter, as none of those focus on encoding conversion.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, when not to use it, or differentiate from sibling tools that might perform similar operations in different contexts.

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/cablate/mcp-doc-forge'

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