Skip to main content
Glama
cablate

Simple Document Processing MCP Server

text_formatter

Format text files by applying proper indentation and line spacing. Specify input file and output directory to produce consistently formatted documents.

Instructions

Format text with proper indentation and line spacing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input text file
outputDirYesDirectory where formatted file should be saved

Implementation Reference

  • The formatText function is the core handler for the text_formatter tool. It reads a text file, trims whitespace from each line, removes consecutive blank lines, and writes the formatted result to a new file.
    export async function formatText(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting text formatting...`);
        console.error(`Input file: ${inputPath}`);
        console.error(`Output directory: ${outputDir}`);
    
        // 確保輸出目錄存在
        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, "utf-8");
    
        // 基本格式化:移除多餘空白行,統一縮排
        const formatted = content
          .split("\n")
          .map((line) => line.trim())
          .filter((line, index, array) => !(line === "" && array[index - 1] === ""))
          .join("\n");
    
        const outputPath = path.join(outputDir, `formatted_${uniqueId}.txt`);
        await fs.writeFile(outputPath, formatted);
        console.error(`Written formatted text to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully formatted text: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in formatText:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • The TEXT_FORMAT_TOOL constant defines the schema for text_formatter: name 'text_formatter', description, and inputSchema requiring 'inputPath' (string) and 'outputDir' (string).
    // 文字格式化工具
    export const TEXT_FORMAT_TOOL: Tool = {
      name: "text_formatter",
      description: "Format text with proper indentation and line spacing",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input text file",
          },
          outputDir: {
            type: "string",
            description: "Directory where formatted file should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • TEXT_FORMAT_TOOL is imported from txtTools.ts and included in the exported 'tools' array that registers all tools with the MCP server.
    import { TEXT_DIFF_TOOL, TEXT_ENCODING_CONVERT_TOOL, TEXT_FORMAT_TOOL, TEXT_SPLIT_TOOL } from "./txtTools.js";
    
    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];
  • The server's CallToolRequestSchema handler dispatches to formatText when name === 'text_formatter', extracting inputPath and outputDir from args and returning the result.
    if (name === "text_formatter") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await formatText(inputPath, outputDir);
      if (!result.success) {
        return {
          content: [{ type: "text", text: `Error: ${result.error}` }],
          isError: true,
        };
      }
      return {
        content: [{ type: "text", text: fileOperationResponse(result.data) }],
        isError: false,
      };
    }
Behavior2/5

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

With no annotations, the description must disclose behavioral traits fully. It only states the intended formatting action but omits details like whether input is modified in-place, if existing files are overwritten, or any side effects. The agent cannot infer safety or side-effect profile.

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 a single sentence with no wasted words, appropriate for a simple tool. However, it is too brief to cover key details, trading conciseness for completeness.

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 lack of output schema, the description should explain the result of formatting (e.g., new file created, encoding, style). It fails to provide enough context for the agent to understand inputs and outputs, making it incomplete.

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?

Schema coverage is 100%, so baseline is 3. The description does not elaborate on parameter roles or constraints beyond the schema's own descriptions, thus adding no extra value.

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 formats text with indentation and line spacing, which is a specific verb-resource pair. However, it does not differentiate from sibling tools like html_formatter or text_diff, which also involve text formatting, thus missing a chance to clarify scope.

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 (e.g., html_formatter, text_splitter). No context on prerequisites or excluded use cases is given, leaving the agent without decision support.

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