Skip to main content
Glama
cablate

Simple Document Processing MCP Server

text_splitter

Split large text files into smaller segments using line count or custom delimiters for easier processing and management.

Instructions

Split text file by specified delimiter or line count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input text file
outputDirYesDirectory where split files should be saved
splitByYesSplit method: by line count or delimiter
valueYesLine count (number) or delimiter string

Implementation Reference

  • The core handler function `splitText` that executes the text splitting logic: reads the input file, splits content by lines or delimiter, and writes split parts to numbered files in the output directory.
    export async function splitText(
      inputPath: string,
      outputDir: string,
      splitBy: "lines" | "delimiter",
      value: string
    ) {
      try {
        console.error(`Starting text splitting...`);
        console.error(`Input file: ${inputPath}`);
        console.error(`Output directory: ${outputDir}`);
        console.error(`Split by: ${splitBy}`);
        console.error(`Value: ${value}`);
    
        // 確保輸出目錄存在
        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 parts: string[] = [];
    
        if (splitBy === "lines") {
          const lineCount = parseInt(value, 10);
          if (isNaN(lineCount) || lineCount <= 0) {
            throw new Error("Invalid line count");
          }
    
          const lines = content.split("\n");
          for (let i = 0; i < lines.length; i += lineCount) {
            parts.push(lines.slice(i, i + lineCount).join("\n"));
          }
        } else {
          parts.push(...content.split(value));
        }
    
        const results: string[] = [];
        for (let i = 0; i < parts.length; i++) {
          const outputPath = path.join(outputDir, `part_${uniqueId}_${i + 1}.txt`);
          await fs.writeFile(outputPath, parts[i]);
          results.push(outputPath);
          console.error(`Written part ${i + 1} to ${outputPath}`);
        }
    
        return {
          success: true,
          data: `Successfully split text into ${parts.length} parts: ${results.join(
            ", "
          )}`,
        };
      } catch (error) {
        console.error(`Error in splitText:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • Tool schema definition for 'text_splitter', including name, description, and inputSchema specifying parameters for input file, output directory, split method, and value.
    export const TEXT_SPLIT_TOOL: Tool = {
      name: "text_splitter",
      description: "Split text file by specified delimiter or line count",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input text file",
          },
          outputDir: {
            type: "string",
            description: "Directory where split files should be saved",
          },
          splitBy: {
            type: "string",
            enum: ["lines", "delimiter"],
            description: "Split method: by line count or delimiter",
          },
          value: {
            type: "string",
            description: "Line count (number) or delimiter string",
          },
        },
        required: ["inputPath", "outputDir", "splitBy", "value"],
      },
    };
  • Registration of the text_splitter tool: imports TEXT_SPLIT_TOOL from txtTools.ts and includes it in the exported `tools` array, which is used by the MCP server to list available tools.
    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];
  • src/index.ts:302-320 (registration)
    Tool dispatch/registration in the main MCP server request handler: matches tool name 'text_splitter', extracts arguments, calls the `splitText` handler, and formats the response.
    if (name === "text_splitter") {
      const { inputPath, outputDir, splitBy, value } = args as {
        inputPath: string;
        outputDir: string;
        splitBy: "lines" | "delimiter";
        value: string;
      };
      const result = await splitText(inputPath, outputDir, splitBy, value);
      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?

No annotations are provided, so the description carries full burden. While 'Split' implies a read-and-write operation, the description doesn't disclose important behavioral traits: whether it overwrites existing files in outputDir, what file naming convention it uses, error handling for invalid inputs, or performance characteristics. It mentions the action but lacks operational context.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core functionality. Every word earns its place: 'Split' (action), 'text file' (resource), 'by specified delimiter or line count' (methods). There's no redundancy or unnecessary elaboration.

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?

For a tool with 4 required parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (success/failure indicators, file paths, error messages), doesn't cover edge cases, and provides minimal behavioral context. The 100% schema coverage helps, but the description alone leaves significant gaps for proper tool invocation.

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 description coverage is 100%, so the schema already fully documents all four parameters. The description adds minimal value beyond the schema by mentioning 'delimiter or line count' which corresponds to the 'splitBy' enum, but doesn't provide additional semantic context about parameter interactions or usage examples. This meets the baseline for high schema coverage.

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 function with a specific verb ('Split') and resource ('text file'), and specifies two methods ('by specified delimiter or line count'). It distinguishes from most siblings by focusing on text splitting rather than reading, converting, or formatting. However, it doesn't explicitly differentiate from 'pdf_splitter' which performs a similar operation on PDFs.

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 doesn't mention when to choose 'lines' vs 'delimiter' splitting, nor does it reference sibling tools like 'pdf_splitter' for PDF files or 'text_formatter' for other text manipulations. There's no context about prerequisites or typical use cases.

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