Skip to main content
Glama

Mend

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 (re-asking a model to "fix the JSON" changes data and costs tokens). If the text is already valid it says so. Up to 100,000 characters.

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. First observed

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already establish readOnly/idempotent/non-destructive, and the description piles on genuinely useful context beyond that: deterministic (not heuristic) repair, values never rewritten so numbers and key order are preserved, output includes a per-fix list with line/column, valid input is reported rather than altered, and a 100,000-character ceiling. That is the behavioral disclosure an agent needs before deciding to trust the output.

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 'Use when...' clause is front-loaded and the length limit closes the block cleanly. The first sentence is a long run-on enumerating every malformed-input symptom, which is dense but each item is load-bearing for recognition; the reward/warning sentence about re-prompting a model earns its place too.

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?

There is no output schema, and the description compensates by describing the return: repaired formatted JSON plus a list of fixes with line and column, and the already-valid case. Combined with the input-size limit, an agent knows exactly what it will get back for a simple 3-parameter tool.

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 coverage is 100% and each parameter (text, indent, sort_keys) is documented in the schema itself. The description only obliquely touches on formatting ('valid, formatted JSON') and never mentions indent or sort_keys, so it adds little beyond the structured fields. Baseline 3 is appropriate.

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?

States a specific verb+resource ('repair ... JSON') and immediately scopes the input classes (LLM output, API, log, config, copy-paste). It also implies the boundary with the validator sibling by noting 'If the text is already valid it says so,' so an agent can tell repair apart from check.

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?

Explicit trigger list: JSON.parse errors, 'Unexpected token', 'Expecting property name', trailing commas, single quotes, fences, truncation, etc. It also motivates why to use this over re-prompting a model. It stops short of naming sibling tools like mend_check_json or mend_outline_json as alternatives, leaving that inference to the agent.

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