hedl-mcp
Model Context Protocol server for HEDL: AI systems deserve structured data that doesn't waste tokens.
LLMs work with context windows measured in tokens, and every token counts. JSON is verbose, repetitive, and expensive. HEDL delivers the same structured data in 56% fewer tokens on average, but AI systems need a way to work with HEDL files natively.
That's what hedl-mcp provides: a complete MCP server that gives any compatible AI system (Claude Desktop, custom agents, LLM applications) the ability to read, validate, convert, query, and optimize HEDL documents. Eleven specialized tools cover the full lifecycle from parsing to persistence, backed by high-performance caching and rate limiting to keep things fast and safe.
Getting Started
Or build from source:
# Binary at target/release/hedl-mcp
Running the Server
The server uses stdio transport for JSON-RPC 2.0 communication:
Claude Desktop Integration
Add this to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
The HEDL_ROOT environment variable scopes all file operations to a specific directory for security.
Programmatic Integration
use ;
use PathBuf;
let config = McpServerConfig ;
let server = new;
server.run_stdio.await?; // Async mode
// or
server.run_stdio_sync?; // Sync mode
Tools
hedl_read
Read and parse HEDL files from the filesystem. Handles both individual files and recursive directory scans with parallel processing.
Returns parsed document metadata including schemas, entity counts, and optionally the JSON representation of the data.
hedl_query
Query entities by type and ID with graph-aware nested children support. Understands %NEST relationships for hierarchical data traversal.
hedl_validate
Full document validation with syntax checking, schema validation, reference resolution, and optional linting. Returns detailed diagnostics with line numbers and severity levels.
hedl_optimize
Convert JSON to HEDL and see exactly how many tokens you're saving. The output includes before/after token counts and percentage savings.
hedl_stats
Compare HEDL vs JSON token usage with your choice of tokenizer: a fast 4-chars-per-token heuristic, or OpenAI's cl100k_base for GPT-accurate counts.
hedl_format
Canonicalize HEDL documents to consistent formatting: 2-space indentation, normalized whitespace, sorted header directives.
hedl_write
Write HEDL content to files with optional pre-write validation, canonicalization, and backup creation. Path traversal protection keeps writes scoped to the configured root.
hedl_convert_to
Export HEDL to JSON, YAML, XML, CSV, Parquet (base64), Cypher (Neo4j), or TOON. Each format has specific options for pretty-printing, headers, metadata inclusion, and more.
hedl_convert_from
Import from JSON, YAML, XML, CSV, Parquet, or TOON into HEDL. Automatically infers schemas and types from the source data.
hedl_stream
Memory-efficient parsing with pagination for large documents. Process millions of entities without loading everything into memory.
batch
Execute multiple operations in a single request. Supports dependency resolution between operations, parallel execution of independent tasks, transaction semantics, and timeout protection.
Caching and Rate Limiting
Immutable operations like validation, queries, and stats are cached using an LRU cache keyed by SHA256 hashes. Repeated requests for the same content return cached results in under 1ms instead of re-parsing.
Rate limiting uses a token bucket algorithm (200 burst, 100/sec sustained by default) to prevent runaway clients from overwhelming the server. Exceeded limits return a retry-after time.
Security
All file operations are scoped to the configured root_path using canonicalized path checking. Attempts to escape via ../ sequences are blocked. Input size is capped at 10MB to prevent memory exhaustion.
Resource Protocol
The server also supports the MCP resource protocol, allowing clients to list and read HEDL files directly:
Real-World Usage
AI agents can use these tools to build sophisticated HEDL workflows: convert JSON configs to HEDL for 40% token savings, validate documents before deployment, query specific entities for targeted responses, stream through large datasets without memory pressure, and batch multiple operations for efficiency.
The server handles the complexity of parsing, validation, and format conversion so AI systems can focus on reasoning about the data.
License
Apache-2.0