Skip to main content
Glama

Repair broken or LLM-generated JSON

mend_repair_json
Read-onlyIdempotent

Use when JSON from an LLM, API, log, config or copy-paste fails to parse (JSON.parse error, "Unexpected token", "Expecting property name"), or the user pastes JSON with trailing commas, single quotes, unquoted keys, comments, Python True/False/None, NaN, missing commas or brackets, a ```json fence, text around it, or output that was cut off. Deterministic repair: returns valid, formatted JSON plus a list of every fix with line and column. Values are never rewritten, so big numbers, number formatting and key order stay exactly as written. If the text is already valid it says so. Up to 100,000 characters.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "text": "<text>"
    },
    "name": "mend_repair_json"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesThe broken JSON, or any text that contains JSON (a chat reply, a log line, a code block).
indentNoSpaces per indent level in the output. Default 2. Use 0 for one minified line.
sort_keysNoSort object keys alphabetically. Default false (keep the original order).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already declare readOnly/idempotent/non-destructive, and the description adds substantive behavior beyond that: deterministic repair, return shape (valid formatted JSON plus a fix list with line and column), and the strong guarantee that values, big numbers, number formatting and key order are never rewritten. It also states the 100,000-character ceiling, which is the main operational constraint.

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?

Front-loaded with the trigger phrase and structured as trigger list → behavior → guarantees → limit, with no filler. The middle sentence is a long comma-chained enumeration of malformed-input cases; it is informative but slightly dense.

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

Completeness5/5

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

For a single-input transform tool with no output schema, the description covers what goes in, what comes out (formatted JSON plus a fix list), what is preserved, the size limit, and the already-valid case. An agent has everything needed to call it correctly and interpret the result.

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 `text`, `indent` and `sort_keys` are already fully documented, including defaults and bounds. The description adds only the character limit echo and no extra meaning about indent or sort_keys behavior, so baseline 3 applies.

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?

Opens with a specific verb+resource ('Repair broken ... JSON') and enumerates the exact input defects it fixes (trailing commas, single quotes, unquoted keys, comments, True/False/None, fences, truncation). An agent can immediately tell this is the fixer, not the outliner or queryer among the mend_* siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete trigger conditions with real error strings ('Unexpected token', 'Expecting property name') and lists the input shapes that qualify, plus a no-op case ('if the text is already valid it says so'). It never names mend_outline_json or mend_query_json as the alternative when the JSON is already valid or needs extracting, so the routing boundary is left implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources