Skip to main content
Glama

merge

Combine multiple JSON files into a single file by specifying the path, streamlining data integration and management within the json-mcp-server environment.

Instructions

Merge JSON files into a one JSON file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Handler for the 'merge' tool: parses arguments, validates and expands path to directory, loads all JSON files in the directory, flattens and merges their contents, writes to 'merged.json' in the same directory, returns success message.
    case 'merge': {
      const parsed = PathArgSchema.safeParse(args)
      if (!parsed.success) {
        throw new Error(`Invalid arguments for merge: ${parsed.error}`)
      }
      const { path } = parsed.data
    
      const validPath = await validatePath(path)
      const content = await loadFlatJsons(validPath)
      const fileName = _path.join(validPath, 'merged.json')
    
      try {
        await fs.promises.writeFile(
          fileName,
          JSON.stringify(content, null, 2)
        )
        console.log(`Successfully wrote ${fileName}`)
      } catch (err) {
        console.error(`Error writing file ${fileName}:`, err)
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Successfully merged to ${fileName}`,
          },
        ],
      }
    }
  • Zod input schema for the 'merge' tool: requires a single 'path' string argument pointing to the directory containing JSON files to merge.
    const PathArgSchema = z.object({
      path: z.string(),
    })
  • src/index.ts:147-151 (registration)
    Registration of the 'merge' tool in the ListTools response, including name, description, and input schema reference.
    {
      name: 'merge',
      description: 'Merge JSON files into a one JSON file',
      inputSchema: zodToJsonSchema(PathArgSchema) as ToolInput,
    },
  • Key helper function used by merge handler: asynchronously loads all JSON files in the given directory path, parses them, and returns a flat array of all objects.
    const loadFlatJsons = async (path: string) => {
      const promises = await parseMultipleJson(path)
      if (promises.length === 0) throw new Error(`No files in ${path}`)
      const jsons = await Promise.all(promises)
      return jsons.flat()
    }
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 mentions merging but doesn't disclose behavioral traits like whether it overwrites files, handles errors, requires specific file formats, or returns output details. This is inadequate 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.

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words. It's appropriately sized for a simple tool, though it could be more informative without sacrificing brevity.

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 1 parameter, no annotations, no output schema, and 0% schema coverage, the description is incomplete. It doesn't explain the merge behavior, parameter usage, or output, leaving significant gaps for the agent to understand and invoke the tool correctly.

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%, and the description doesn't explain the 'path' parameter's meaning (e.g., directory path, file pattern, output location). It fails to compensate for the lack of schema documentation, leaving the parameter's purpose unclear.

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

Purpose3/5

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

The description states the tool's purpose ('Merge JSON files into a one JSON file'), which is clear but vague. It specifies the verb ('merge') and resource ('JSON files'), but doesn't distinguish from its sibling tool 'split' or explain what 'merge' entails (e.g., concatenation, deep merging, conflict resolution).

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 is provided on when to use this tool versus alternatives. The description doesn't mention the sibling tool 'split' or any prerequisites, leaving the agent to infer usage from the tool name alone.

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