Skip to main content
Glama

Stop AI coding tools from breaking your data files. No more grep guesswork, hallucinated fields, or non-schema-compliant data added to files. This MCP server gives AI assistants a strict, round-trip safe interface for working with structured data.

The Problem

AI coding tools often destroy structured data files:

  • They grep through huge json, yaml, and toml files (like json logs, or AI transcript files) and guess at keys.

  • They hallucinate fields that never existed.

  • They use sed and regex that leave files in invalid states.

  • They break YAML indentation and TOML syntax.

  • They can't validate changes before writing.

Related MCP server: MCP Filesystem Agent v3

The Solution

mcp-json-yaml-toml provides AI assistants with proper tools for structured data:

  • Token-efficient: Extract exactly what you need without loading entire files.

  • Schema validation: Enforce correctness using SchemaStore.org or custom schemas.

  • Safe modifications: Enforced validation on write; preserve comments and formatting.

  • Multi-format: JSON, YAML, and TOML through a unified interface.

  • Directive-based detection: Support for # yaml-language-server, #:schema, and $schema keys in all formats.

  • Constraint-based guided generation: Native LMQL support for proactive validation of partial inputs.

  • Local-First: All processing happens locally. No data ever leaves your machine.

  • Transparent JIT Assets: The server auto-downloads yq if missing and fetches missing schemas from SchemaStore.org for local caching.

NOTE

JSONC Support: Files with .jsonc extension (JSON with Comments) are fully supported for reading, querying, and schema validation. However, write operations will strip comments due to library limitations.


Getting Started

Prerequisites

  • Python ≥ 3.11 installed.

  • An MCP-compatible client (Claude Code, Cursor, Windsurf, Gemini 2.0, n8n, etc.).

Installation

The server uses uvx for automatic dependency management and zero-config execution.

AI Agents & CLI Tools

uvx mcp-json-yaml-toml

Claude Code (CLI)

claude mcp add --scope user mcp-json-yaml-toml -- uvx mcp-json-yaml-toml

Other MCP Clients

Add this to your client's MCP configuration:

{
  "mcpServers": {
    "json-yaml-toml": {
      "command": "uvx",
      "args": ["mcp-json-yaml-toml"]
    }
  }
}
TIP

Seedocs/clients.md for detailed setup guides for Cursor, VS Code, and more.


Schema Discovery & Recognition

The server automatically identifies the correct JSON schema for your files using multiple strategies:

  1. Directives: Recognizes # yaml-language-server: $schema=... and #:schema ... directives.

  2. In-File Keys: Detects $schema keys in JSON and YAML (also supports quoted "$schema" in TOML).

  3. Local IDE Config: Discovers schemas from VS Code/Cursor extension settings and caches.

  4. SchemaStore.org: Performs glob-based auto-detection against thousands of known formats.

  5. Manual Association: Use the data_schema tool to bind a file to a specific schema URL or name.


LMQL & Guided Generation

This server provides native support for LMQL (Language Model Query Language) to enable Guided Generation. This allows AI agents to validate partial inputs (e.g., path expressions) incrementally before execution.

  • Incremental Validation: Check partial inputs (e.g., .data.us) and get the remaining pattern needed.

  • Improved Reliability: Eliminate syntax errors by guiding the LLM toward valid tool inputs.

  • Rich Feedback: Get suggestions and detailed error messages for common mistakes.

TIP

See theDeep Dive: LMQL Constraints for detailed usage examples.


Available Tools

Tool

Description

data

Get, set, or delete values at specific paths

data_query

Advanced yq/jq expressions for transformations

data_schema

Manage schemas and validate files

data_convert

Convert between JSON, YAML, and TOML

data_merge

Deep merge structured data files

constraint_validate

Validate inputs against LMQL constraints

constraint_list

List available generation constraints

NOTE

ConversionTO TOML is not supported due to yq's internal encoder limitations for complex structures.


Development

Setup

git clone https://github.com/bitflight-devops/mcp-json-yaml-toml.git
cd mcp-json-yaml-toml
uv sync

Testing

ash

Run all tests (coverage included)

uv run pytest


### Code Quality

The project uses `prek` (a Rust-based pre-commit tool) for unified linting and formatting. AI Agents MUST use the scoped verification command:

```bash
# Recommended: Verify only touched files
uv run prek run --files <file edited>
IMPORTANT

Avoid--all-files during feature development to keep PR diffs clean and preserve git history.


Project Structure

mcp-json-yaml-toml/
├── packages/mcp_json_yaml_toml/  # Core logic
│   ├── server.py                 # MCP implementation
│   ├── yq_wrapper.py             # Binary management
│   ├── schemas.py                # Schema validation
├── .github/                      # CI/CD and assets
├── docs/                         # Documentation
└── pyproject.toml                # Project config
# Run all tests (coverage included)
uv run pytest

Code Quality

The project uses prek (a Rust-based pre-commit tool) for unified linting and formatting. AI Agents MUST use the scoped verification command:

# Recommended: Verify only touched files
uv run prek run --files <file edited>
IMPORTANT

Avoid--all-files during feature development to keep PR diffs clean and preserve git history.


Project Structure

graph TD
    Repo[mcp-json-yaml-toml]
    Repo --> Packages[packages/mcp_json_yaml_toml]
    Repo --> Github[.github]
    Repo --> Docs[docs]
    Repo --> Config[pyproject.toml]

    subgraph "Core Logic"
        Packages --> Server[server.py<br/>MCP Server & Tools]
        Packages --> Schemas[schemas.py<br/>Schema Validation]
        Packages --> Constraints[lmql_constraints.py<br/>LMQL Constraints]
        Packages --> YQ[yq_wrapper.py<br/>Binary Manager]
        Packages --> YAML[yaml_optimizer.py<br/>YAML Anchors]
        Packages --> TOML[toml_utils.py<br/>TOML Utils]
        Packages --> Conf[config.py<br/>Config Manager]
    end

    style Packages fill:#f9f,stroke:#333,stroke-width:2px
    style Repo fill:#eee,stroke:#333,stroke-width:4px

Token Efficiency Experiment

Two identical Claude Code sub-agents were given the same task: read ~/.claude.json and report every MCP server listed, including command, args, and env vars.

Setup

  • Agent A — standard prompt, used the built-in Read tool

  • Agent B — same prompt with one line appended: You must use the mcp__json-yaml-toml for all file interactions.

Both agents used the sonnet model.

Prompts

Agent A prompt:

Read the file ~/.claude.json and report back:
1. Every MCP server listed in the mcpServers section
2. For each server: the command, args, and any env vars configured

Just report the raw findings. Do not summarize or interpret.

Agent B prompt:

Read the file ~/.claude.json and report back:
1. Every MCP server listed in the mcpServers section
2. For each server: the command, args, and any env vars configured

You must use the mcp__json-yaml-toml for all file interactions.

Just report the raw findings. Do not summarize or interpret.

Results

Both agents returned identical findings (8 MCP servers with correct configs).

Metric

Agent A (Read tool)

Agent B (mcp-json-yaml-toml)

Total tokens

37,119

28,734

Tool uses

4

2

Duration

29.3s

12.7s

Agent B used 22.6% fewer tokens and completed in 43% of the time with half the tool calls.

Why

The Read tool loads the entire file into context. ~/.claude.json is a large file — the agent had to consume all of it to find the mcpServers section. The MCP server's data_query tool extracted just the mcpServers section directly, keeping the context window small.


Available Tools

8 tools
constraint_listA
Read-onlyIdempotent

Return a list of all registered LMQL constraints with their metadata.

Returns: ConstraintListResponse with keys: - "constraints": a list of constraint objects; each object includes a "name" key and the constraint's definition fields (e.g., "description", any other metadata). - "usage": a string describing how to validate a value against a constraint (e.g., call constraint_validate(constraint_name, value)).

Inputs: no named parameters. Returns: Response for constraint_list tool.

constraint_validateA
Read-onlyIdempotent

Validate a value against an LMQL-style constraint.

Use this tool to check if a value satisfies a constraint before using it in other operations. Supports partial validation - can tell if an incomplete input could still become valid.

Output contract: Returns {"valid": bool, "error": str?, "is_partial": bool?, ...}. Side effects: None (read-only validation). Failure modes: ToolError if constraint name unknown.

Available constraints:

  • YQ_PATH: Valid yq path (e.g., '.users[0].name')

  • YQ_EXPRESSION: Valid yq expression with pipes (e.g., '.items | length')

  • CONFIG_FORMAT: Valid format ('json', 'yaml', 'toml', 'xml')

  • KEY_PATH: Dot-separated key path (e.g., 'config.database.host')

  • INT: Valid integer

  • JSON_VALUE: Valid JSON syntax

  • FILE_PATH: Valid file path syntax

Inputs: value (required), constraint_name (required). Returns: Response for constraint_validate tool. Does NOT inherit ToolResponse -- differe…

dataA
DestructiveIdempotent

Get, set, or delete data in JSON, YAML, or TOML files.

Use when you need to get, set, or delete specific values or entire sections in a structured data file.

Output contract: Returns {"success": bool, "result": Any, "file": str, ...}. Side effects: Modifies file on disk if operation is 'set' or 'delete'. Failure modes: FileNotFoundError if file missing. ToolError if format disabled or invalid JSON.

Operations:

  • get: Retrieve data, schema, or structure

  • set: Update/create value at key_path (always writes to file)

  • delete: Remove key/element at key_path (always writes to file)

Inputs: file_path (required), operation (required), value, cursor, +6 more. Returns: result

data_convertA
Read-onlyIdempotent

Convert file format.

Use when you need to transform a file from one format (JSON, YAML, TOML) to another.

Output contract: Returns {"success": bool, "result": str, ...} or writes to file. Side effects: Writes to output_file if provided. Failure modes: FileNotFoundError if input missing. ToolError if formats same or conversion fails.

Inputs: file_path (required), output_format (required), output_file. Returns: Response for data_convert tool.

data_diffA
Read-onlyIdempotent

Compare two configuration files and return structured differences.

Performs a deep comparison of two configuration files (JSON, YAML, TOML) and returns a structured diff with statistics and a human-readable summary. Supports cross-format comparison (e.g. JSON vs YAML).

Output contract: Returns DiffResponse with has_differences, differences dict, statistics, and summary. Side effects: None (read-only). Failure modes: ToolError if files not found or formats disabled.

Inputs: file_path1 (required), file_path2 (required), ignore_order. Returns: Response for data_diff tool.

data_mergeA
Read-onlyIdempotent

Merge two files into a single deep-merged configuration.

Performs a deep merge where values from the second (overlay) file override or extend those in the first (base) file. If output_file is provided the merged result is written to that path; otherwise the merged content is returned in the response.

Parameters: file_path1 (str): Path to the base file. file_path2 (str): Path to the overlay file whose values override the base. output_format (str | None): Desired output format: "json", "yaml", or "toml". Defaults to the format of the first file. output_file (str | None): Optional path to write the merged output. When omitted, merged content is returned.

Returns: MergeResponse with "success", "file1", "file2", "output_format", and either "result" (merged content) or "output_file" (written path).

Raises: ToolError: If an input file is missing, its format is not enabled, the output format is invalid, or the merge fails.

Inputs: file_path1 (required), file_path2 (required), output_file, output_format. Returns: Response for data_merge tool.

data_queryA
Read-onlyIdempotent

Extract specific data, filter content, or transform structure without modification.

Use when you need to extract specific data, filter content, or transform the structure of a JSON, YAML, or TOML file without modifying it.

Output contract: Returns {"success": bool, "result": Any, "format": str, "file": str, ...}. Side effects: None (read-only). Failure modes: FileNotFoundError if file missing. ToolError if format disabled or query fails.

Inputs: file_path (required), expression (required), cursor, output_format, +1 more. Returns: Response for data GET and data_query returns.

data_schemaA
Idempotent

Unified schema operations tool.

Actions:

  • validate: Validate file syntax and optionally against schema

  • scan: Recursively search for schema directories

  • add_dir: Add custom schema directory

  • add_catalog: Add custom schema catalog

  • associate: Bind file to schema URL or name

  • disassociate: Remove file-to-schema association

  • list: Show current schema configuration

Examples:

  • action="validate", file_path="config.json"

  • action="associate", file_path=".gitlab-ci.yml", schema_name="gitlab-ci"

  • action="disassociate", file_path=".gitlab-ci.yml"

  • action="list"

Inputs: action (required), uri, name, path, +8 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 8 tools

    Disambiguation4/5

    Most tools are distinct, but 'data' and 'data_query' both support reading data; agents may be unsure which to use for extraction queries. Descriptions help differentiate (data for CRUD, data_query for queries/transformations), but some overlap remains.

    Naming Consistency4/5

    The majority follow a consistent 'data_<verb>' pattern (convert, diff, merge, query, schema) and 'constraint_<verb>' pattern. However, the bare 'data' tool without a suffix breaks the pattern, creating a minor inconsistency.

    Tool Count5/5

    With 8 tools covering CRUD, format conversion, diff, merge, query, schema, and constraints, the count is well-scoped for the domain. Each tool serves a clear purpose without unnecessary bloat or undercoverage.

    Completeness5/5

    The tool surface provides full lifecycle support for JSON/YAML/TOML files: read, write, delete, format conversion, comparison, merging, querying, and schema operations. No obvious gaps for common use cases.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Agent-optimized MCP server that replaces built-in file, search, exec, and git tools with compact, structured JSON equivalents. Benchmarked 20–45% token savings for AI coding agents.
      20
      3
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      MCP server that enables AI to read, search, and edit local files securely without external data exposure, using local LLMs via Ollama and integrating with Open WebUI or Claude Desktop.
      -