Skip to main content
Glama

split

Divide a JSON file into a specified number of objects for easier processing or analysis. Input the file path and the desired number of objects to split the content efficiently.

Instructions

Split a JSON file into a specified number of objects

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
numObjectsYes
pathYes

Implementation Reference

  • The handler for the 'split' tool. It validates input, reads a JSON file, splits its array into multiple files each containing up to numObjects items, writes them as part1.json, part2.json etc., and returns a success message.
    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}`,
          },
        ],
      }
    }
  • Zod schema defining the input arguments for the split tool: path (string) and numObjects (positive integer).
    const SplitArgSchema = z.object({
      path: z.string(),
      numObjects: z.number().int().positive(),
    })
  • src/index.ts:142-146 (registration)
    Registration of the 'split' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'split',
      description: 'Split a JSON file into a specified number of objects',
      inputSchema: zodToJsonSchema(SplitArgSchema) as ToolInput,
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the action ('split') but lacks critical behavioral details: it doesn't specify what happens to the original file (e.g., deletion, preservation), how the split is performed (e.g., by size, count, or structure), output format, error handling, or any permissions/rate limits. This is a significant gap for a mutation tool with zero annotation coverage.

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 with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration, making it easy for an agent to parse quickly.

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 complexity (a file-splitting mutation tool), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't explain the mutation behavior, output details, or error scenarios, leaving the agent with insufficient information to use the tool effectively in context.

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 description coverage is 0%, so the description must compensate. It mentions 'numObjects' and 'path' implicitly but adds minimal meaning: 'path' is not explained (e.g., file path, URL), and 'numObjects' lacks context (e.g., what constitutes an object). The description doesn't clarify parameter roles or constraints beyond the basic action, failing to address the coverage gap adequately.

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 verb ('split') and resource ('a JSON file'), specifying the action and target. It distinguishes from the sibling 'merge' tool by focusing on division rather than combination. However, it doesn't specify what 'objects' means in this context (e.g., JSON objects, files, or something else), keeping it from being fully specific.

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 the sibling 'merge' tool or any other context for usage, such as prerequisites, scenarios, or exclusions. This leaves the agent without direction on appropriate application.

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

Related 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