Skip to main content
Glama

split

Divide a JSON file into a specified number of objects for parallel processing or data distribution.

Instructions

Split a JSON file into a specified number of objects

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
numObjectsYes

Implementation Reference

  • Zod schema for the split tool's input arguments: path (string) and numObjects (positive integer).
    const SplitArgSchema = z.object({
      path: z.string(),
      numObjects: z.number().int().positive(),
    })
  • src/index.ts:143-146 (registration)
    Registration of the 'split' tool in the ListToolsRequestSchema handler, with description and inputSchema.
      name: 'split',
      description: 'Split a JSON file into a specified number of objects',
      inputSchema: zodToJsonSchema(SplitArgSchema) as ToolInput,
    },
  • Main handler for the 'split' tool: parses args, validates path, reads JSON file, splits it into parts with a specified number of objects, and writes each part to a file (part1.json, part2.json, etc.).
    case 'split': {
      const parsed = SplitArgSchema.safeParse(args)
      if (!parsed.success) {
        throw new Error(`Invalid arguments for split: ${parsed.error}`)
      }
      const { path, numObjects } = parsed.data
    
      const validPath = await validatePath(path)
      const content = await fs.promises.readFile(validPath, 'utf-8')
      const folder = await getParentDir(path)
    
      const jsonData = JSON.parse(content)
    
      if (numObjects >= jsonData.length / 2) {
        throw new Error(
          `The number of objects (${numObjects}) per file cannot be half or more of the total (${jsonData.length}) JSON data length.`
        )
      }
    
      const totalParts = Math.ceil(jsonData.length / numObjects)
    
      await Promise.all(
        Array.from({ length: totalParts }, async (_, i) => {
          const partArray = jsonData
            .slice(i * numObjects, (i + 1) * numObjects)
            ?.flat()
          const partFileName = _path.join(folder, `part${i + 1}.json`)
          try {
            await fs.promises.writeFile(
              partFileName,
              JSON.stringify(partArray, null, 2)
            )
            console.log(`Successfully wrote ${partFileName}`)
          } catch (err) {
            console.error(`Error writing file ${partFileName}:`, err)
          }
        })
      )
    
      return {
        content: [
          {
            type: 'text',
            text: `Successfully splitted to ${parsed.data.path}`,
          },
        ],
      }
    }
Behavior2/5

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

The description does not disclose side effects (e.g., whether the original file is modified or a new file created), required permissions, or other behavioral traits. With no annotations, the description carries the full burden but provides minimal info.

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?

Single sentence, no unnecessary words. However, the description could benefit from additional structure to cover key behavioral aspects.

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

Completeness3/5

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

For a simple tool with two parameters, the description is minimally adequate but leaves questions unanswered, such as output behavior and impact on input file. Missing details reduce completeness.

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

Parameters2/5

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

Schema coverage is 0%, and the description adds no meaning beyond the schema. For example, 'path' and 'numObjects' are not detailed—no clarification on file format, location constraints, or how numObjects is applied.

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 action (split) and the resource (JSON file). It distinguishes from the sibling tool 'merge' by implying opposite functionality.

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?

No guidance on when to use this tool versus alternatives (e.g., 'merge'). No context about prerequisites or exclusions.

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/VadimNastoyashchy/json-mcp'

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