Skip to main content
Glama

Agent Data Tools: Utilities

JSON repair: fix broken JSON

json_repair
Read-only

Fix JSON as LLMs often write it: removes json fences and surrounding prose, comments and trailing commas, converts single quotes, quotes bare keys, maps True/False/None, and closes unclosed brackets. Returns the repaired JSON and whether it now parses. Use when an LLM's JSON output fails to parse. Example: text=json {name: 'Ada', tags: ['x',],}

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": "json_repair"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesThe broken JSON text

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.6/5.0
Behavior5/5

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

Goes well past the annotations: it discloses the return contract ('the repaired JSON and whether it now parses') and the billing model ('$0.01/call via x402 USDC or a card key', 'first 10 free; failed calls free'), which is essential given idempotentHint=false and the note that repeats are charged. The claim 'Reads or computes only and changes nothing' is consistent with readOnlyHint=true and destructiveHint=false, so nothing contradicts the structured data.

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-loads the verb and the failure classes, then the usage condition, then the example and cost. Every clause carries information, but the priced-per-call and card-key details sit in the same block, making one dense paragraph where a brief structural break would help scanning.

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 one-parameter, no-output-schema, read-only repair tool this covers everything an agent needs: what it repairs, when to call it, what comes back (repaired JSON plus a parse flag), and that repeat calls cost money. No gap remains that would cause a wrong invocation.

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

Parameters4/5

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

Schema coverage is 100% for the single 'text' parameter, and the description's worked example clarifies that the value is the raw broken JSON string including fences and trailing prose. That is genuine added meaning beyond 'The broken JSON text', but the format detail is delivered only by example rather than stated.

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?

Names a specific verb ('Fix') and resource ('JSON'), then enumerates exactly what classes of breakage it handles (code fences, prose, comments, trailing commas, single quotes, bare keys, True/False/None, unclosed brackets). That enumeration implicitly separates it from siblings like json_validate and json_format, which check or restyle already-valid JSON.

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 an explicit trigger: "Use when an LLM's JSON output fails to parse." No exclusion is stated, though — an agent is not told to prefer json_validate when the text might already be valid, so the routing signal is clear but not complete.

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