| Crates.io | hedl-mcp |
| lib.rs | hedl-mcp |
| version | 1.2.0 |
| created_at | 2026-01-09 00:22:10.902244+00 |
| updated_at | 2026-01-21 03:04:35.180805+00 |
| description | Model Context Protocol (MCP) server for HEDL - AI/LLM integration |
| homepage | https://dweve.com |
| repository | https://github.com/dweve/hedl |
| max_upload_size | |
| id | 2031332 |
| size | 994,585 |
Model Context Protocol server for HEDL—complete AI/LLM integration with 11 tools, caching, rate limiting, and streaming support.
AI/LLM systems need seamless access to HEDL files: reading documents, validating schemas, converting formats, querying entities, optimizing token usage. hedl-mcp provides a production-grade MCP server that bridges AI systems with the HEDL ecosystem through 11 specialized tools (including batch operations), high-performance caching (2-5x speedup), rate limiting (DoS protection), and streaming support for large files.
This is the official Model Context Protocol server for HEDL. Connect any MCP-compatible AI system (Claude Desktop, custom agents, LLM applications) to HEDL with comprehensive tools for validation, conversion, optimization, and querying.
Complete MCP server with production-ready infrastructure:
# From source
cargo install hedl-mcp
# Or build locally
cd crates/hedl-mcp
cargo build --release
Binary location: target/release/hedl-mcp
# Start server with stdio transport
hedl-mcp --stdio
# Server listens on stdin/stdout for JSON-RPC 2.0 messages
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or equivalent:
{
"mcpServers": {
"hedl": {
"command": "/path/to/hedl-mcp",
"args": ["--stdio"],
"env": {
"HEDL_ROOT": "/path/to/hedl/documents"
}
}
}
}
Environment Variables:
HEDL_ROOT - Root directory for scoped file operations (default: current directory)use hedl_mcp::{McpServer, McpServerConfig};
use std::path::PathBuf;
let config = McpServerConfig {
root_path: PathBuf::from("/data/hedl"),
name: "hedl-server".to_string(),
version: "1.0.0".to_string(),
rate_limit_burst: 200, // Burst capacity
rate_limit_per_second: 100, // Sustained rate
cache_size: 1000, // LRU cache entries
};
let server = McpServer::new(config);
server.run_stdio().await?; // Async mode
// or
server.run_stdio_sync()?; // Sync mode
Read HEDL files from directory or specific file with optional JSON representation:
{
"tool": "hedl_read",
"arguments": {
"path": "data/users.hedl"
}
}
Arguments:
path (string, required) - File or directory path (scoped to root_path)recursive (boolean, optional) - Recursively scan directories (default: true)include_json (boolean, optional) - Include JSON representation in output (default: false)num_threads (number, optional) - Thread count for parallel processing (default: CPU core count)Output:
{
"files_read": 1,
"documents": [
{
"path": "data/users.hedl",
"version": "1.0",
"schemas": ["User", "Post"],
"entity_count": 125,
"json": { ... } // Optional JSON representation
}
]
}
Parallel Processing: Automatically uses parallel processing for directory operations with configurable thread pool. Single-file operations do not use parallelism.
Query parsed entities by type and ID with graph-aware nested children support:
{
"tool": "hedl_query",
"arguments": {
"hedl": "%VERSION: 1.0\n---\nusers: @User[id, name]\n | alice, Alice Smith",
"type_name": "User",
"id": "alice"
}
}
Arguments:
hedl (string, required) - HEDL document content to querytype_name (string, optional) - Filter by entity type nameid (string, optional) - Filter by entity IDinclude_children (boolean, optional) - Include nested children in results (default: true)Output:
{
"matches": [
{
"type": "User",
"id": "alice",
"fields": ["alice", "Alice Smith"],
"line": 3,
"children": [
{
"type": "Post",
"id": "post1",
"fields": ["post1", "My First Post"],
"line": 4
}
]
}
],
"count": 1
}
Features:
include_children: false to exclude nested entity informationValidate syntax, schema, and references with detailed diagnostics:
{
"tool": "hedl_validate",
"arguments": {
"hedl": "%VERSION: 1.0\n---\nusers: @User[id, name]\n | alice, Alice",
"strict": true,
"lint": true
}
}
Arguments:
hedl (string, required) - HEDL document content to validatestrict (boolean, optional) - Treat lint warnings as errors (default: true)lint (boolean, optional) - Include linting diagnostics (default: true)Output (valid document):
{
"valid": true,
"version": "1.0",
"schemas": 1,
"entities": 1,
"diagnostics": []
}
Output (invalid document):
{
"valid": false,
"errors": [
{
"line": 3,
"severity": "error",
"message": "Parse error: unexpected end of line, expected ']'",
"rule": null
}
],
"warnings": [
{
"line": 2,
"severity": "warning",
"message": "Matrix list 'users' missing count hint",
"rule": "add-count-hints"
}
]
}
Validation Levels:
Convert JSON to optimized HEDL format with token savings statistics:
{
"tool": "hedl_optimize",
"arguments": {
"json": "{\"users\": [{\"id\": \"alice\", \"name\": \"Alice\"}]}",
"ditto": true
}
}
Arguments:
json (string, required) - JSON content to convertditto (boolean, optional) - Enable ditto optimization for repeated values (default: true)compact (boolean, optional) - Minimize whitespace in output (default: false)Output:
{
"hedl": "users: @User[id, name]\n | alice, Alice",
"json_tokens": 150,
"hedl_tokens": 90,
"savings": 60,
"savings_percent": 40.0,
"optimization": "40% token reduction"
}
Reported Capability: 40-60% token savings for typical JSON documents
Compare HEDL vs JSON token counts with detailed breakdown:
{
"tool": "hedl_stats",
"arguments": {
"hedl": "users: @User[id, name]\n | alice, Alice\n | bob, Bob",
"tokenizer": "simple"
}
}
Arguments:
hedl (string, required) - HEDL document content to analyzetokenizer (string, optional) - Tokenizer to use: "simple" or "cl100k" (default: "simple")Output:
{
"hedl": {
"bytes": 58,
"tokens": 15
},
"json_compact": {
"bytes": 95,
"tokens": 24,
"increase_percent": 60.0
},
"json_pretty": {
"bytes": 142,
"tokens": 36,
"increase_percent": 140.0
},
"savings": {
"vs_compact": 9,
"vs_pretty": 21,
"efficiency": "37.5% fewer tokens vs JSON compact"
}
}
Tokenizers:
Canonicalize HEDL with optional ditto optimization:
{
"tool": "hedl_format",
"arguments": {
"hedl": "users:@User[id,name]\n|alice,Alice",
"ditto": true
}
}
Arguments:
hedl (string, required) - HEDL document content to formatditto (boolean, optional) - Enable ditto optimization for repeated values (default: true)Output:
{
"formatted": "users: @User[id, name]\n | alice, Alice",
"canonical": true
}
Canonicalization:
^)Write HEDL content with optional validation and formatting:
{
"tool": "hedl_write",
"arguments": {
"path": "output/data.hedl",
"content": "users: @User[id, name]\n | alice, Alice",
"validate": true,
"format": true,
"backup": true
}
}
Arguments:
path (string, required) - Output file path (scoped to root_path)content (string, required) - HEDL content to writevalidate (boolean, optional) - Validate before writing (default: true)format (boolean, optional) - Canonicalize before writing (default: false)backup (boolean, optional) - Create .hedl.bak backup (default: true)Output:
{
"written": true,
"path": "output/data.hedl",
"bytes": 58,
"backup_created": "output/data.hedl.bak"
}
Safety Features:
Export HEDL to JSON, YAML, XML, CSV, Parquet (base64), Cypher (Neo4j), or TOON:
{
"tool": "hedl_convert_to",
"arguments": {
"hedl": "users: @User[id, name]\n | alice, Alice",
"format": "json",
"options": {
"pretty": true
}
}
}
Arguments:
hedl (string, required) - HEDL document content to convertformat (string, required) - Target format: "json", "yaml", "xml", "csv", "parquet", "cypher", "toon"options (object, optional) - Format-specific options:
pretty (bool) - Pretty-print output (default: true)include_metadata (bool) - Include metadata (default: true), root_element (string)include_headers (bool) - Include CSV headers (default: true)include_constraints (bool) - Add constraints (default: false)Output:
{
"format": "json",
"content": "{\n \"users\": [\n {\"id\": \"alice\", \"name\": \"Alice\"}\n ]\n}"
}
Parquet Output: Base64-encoded parquet_base64 field with byte count
Cypher Output: Neo4j CREATE/MERGE statements with optional constraints
Import JSON, YAML, XML, CSV, Parquet, or TOON into HEDL:
{
"tool": "hedl_convert_from",
"arguments": {
"content": "{\"users\": [{\"id\": \"alice\", \"name\": \"Alice\"}]}",
"format": "json",
"options": {
"canonicalize": true
}
}
}
Arguments:
content (string, required) - Source content to convert (base64 for parquet)format (string, required) - Source format: "json", "yaml", "xml", "csv", "parquet", "toon"options (object, optional) - Format-specific options:
canonicalize (bool) - Canonicalize output (default: false)schema (array of strings) - Column names (required for headerless CSV)Output:
{
"hedl": "users: @User[id, name]\n | alice, Alice",
"canonical": true
}
CSV Conversion: Requires schema option for headerless CSV; auto-detects types for values
Parquet Input: Provide base64-encoded content in content field
Memory-efficient parsing with pagination and type filtering:
{
"tool": "hedl_stream",
"arguments": {
"hedl": "users: @User[id, name]\n | alice, Alice\n | bob, Bob",
"type_filter": "User",
"offset": 0,
"limit": 100
}
}
Arguments:
hedl (string, required) - HEDL document content to stream parsetype_filter (string, optional) - Filter entities by typeoffset (number, optional) - Skip first N entities (default: 0)limit (number, optional) - Maximum entities to return (default: 100)Output:
{
"entities": [
{
"type": "User",
"id": "alice",
"fields": ["alice", "Alice"],
"line": 2
}
],
"count": 1,
"total": 2,
"has_more": true,
"next_offset": 100
}
Performance: Streaming architecture processes documents efficiently with configurable pagination.
Execute multiple operations in a single request with dependency resolution and parallel execution:
{
"tool": "batch",
"arguments": {
"operations": [
{
"id": "validate1",
"tool": "hedl_validate",
"arguments": {
"hedl": "%VERSION: 1.0\n---\nusers: @User[id, name]\n | alice, Alice"
}
},
{
"id": "format1",
"tool": "hedl_format",
"arguments": {
"hedl": "users:@User[id,name]\n|alice,Alice"
},
"depends_on": ["validate1"]
}
],
"mode": "continue_on_error",
"parallel": true,
"transaction": false,
"timeout": 30
}
}
Arguments:
operations (array, required) - List of operations to execute:
id (string, required) - Unique operation identifiertool (string, required) - Tool name to executearguments (object, required) - Tool-specific argumentsdepends_on (array, optional) - Operation IDs this depends onmode (string, optional) - Execution mode: "continue_on_error" or "stop_on_error" (default: "continue_on_error")parallel (boolean, optional) - Enable parallel execution for independent operations (default: true)transaction (boolean, optional) - All-or-nothing transaction semantics (default: false)timeout (number, optional) - Maximum execution time in seconds (1-3600)Output:
{
"results": [
{
"id": "validate1",
"status": "success",
"result": {
"valid": true,
"version": "1.0"
}
},
{
"id": "format1",
"status": "success",
"result": {
"formatted": "users: @User[id, name]\n | alice, Alice"
}
}
],
"summary": {
"total": 2,
"succeeded": 2,
"failed": 0,
"duration_ms": 45
}
}
Features:
depends_on declarationsparallel: true)LRU cache for immutable operations provides 2-5x speedup on repeated requests:
hedl_validate - Validation results for identical contenthedl_query - Entity lookups for unchanged fileshedl_stats - Token statistics for same contentCache Key: Operation name + SHA256 hash of inputs
Configuration:
McpServerConfig {
cache_size: 1000, // Max entries (default)
...
}
Cache Statistics:
{
"cache": {
"hits": 1523,
"misses": 478,
"evictions": 23,
"hit_rate": 76.1
}
}
Impact: Validation of frequently-accessed documents drops from 50ms to <1ms.
Token bucket algorithm prevents request flooding:
Configuration:
McpServerConfig {
rate_limit_burst: 200, // Burst capacity
rate_limit_per_second: 100, // Sustained rate
...
}
Behavior:
Error Response:
{
"error": {
"code": -32000,
"message": "Rate limit exceeded. Try again in 0.5s"
}
}
Use Case: Prevents aggressive clients from overwhelming server with thousands of requests.
All file operations are scoped to configured root_path:
// Canonicalize path and check prefix
let canonical = std::fs::canonicalize(&path)?;
if !canonical.starts_with(&self.config.root_path) {
return Err(PathTraversalError);
}
Blocked Attempts:
/etc/passwd → Error: Path traversal detected
../../../secrets.hedl → Error: Path traversal detected
/data/hedl/users.hedl → OK (within root_path)
Maximum Input: 10 MB per request
if content.len() > 10_000_000 {
return Err("Input size exceeds 10 MB limit");
}
Purpose: Prevents memory exhaustion from malicious large inputs.
List and read HEDL files as MCP resources:
{
"method": "resources/list"
}
Response:
{
"resources": [
{
"uri": "file:///data/hedl/users.hedl",
"name": "users.hedl",
"mimeType": "application/x-hedl"
},
{
"uri": "file:///data/hedl/config.hedl",
"name": "config.hedl",
"mimeType": "application/x-hedl"
}
]
}
{
"method": "resources/read",
"params": {
"uri": "file:///data/hedl/users.hedl"
}
}
Response:
{
"contents": [
{
"uri": "file:///data/hedl/users.hedl",
"mimeType": "application/x-hedl",
"text": "users: @User[id, name]\n | alice, Alice"
}
]
}
Lifecycle:
initialize - Protocol handshake with capability negotiationinitialized - Client confirmation notificationshutdown - Graceful server terminationTools:
tools/list - List all 11 available tools with schemastools/call - Execute specific tool with argumentsResources:
resources/list - List HEDL files in root_pathresources/read - Read HEDL file contentHealth:
ping - Health check endpoint (always returns pong){
"capabilities": {
"tools": {
"listChanged": false
},
"resources": {
"subscribe": false,
"listChanged": false
}
},
"protocolVersion": "2024-11-05",
"serverInfo": {
"name": "hedl-mcp",
"version": "1.0.0"
}
}
Comprehensive error types with MCP error codes:
Error Codes:
-32700: Parse error (invalid JSON-RPC)-32600: Invalid request (malformed method/params)-32601: Method not found-32000: Server error (HEDL-specific errors)HEDL-Specific Errors:
{
"code": -32000,
"message": "Parse error at line 5: unexpected token",
"data": {
"line": 5,
"column": 12
}
}
Tool Errors: Returned as successful responses with is_error: true:
{
"content": [
{
"type": "text",
"text": "Error: Path traversal detected"
}
],
"isError": true
}
AI-Powered HEDL Editing: LLMs read HEDL files, suggest edits, validate changes, write back canonical HEDL—all through MCP tools.
Automated Optimization: AI agents convert JSON to HEDL, analyze token savings, optimize with ditto, validate output, deploy optimized configs.
Interactive Query Assistant: Chat with HEDL data—ask "Show me all users created in 2024", agent uses hedl_query to fetch entities, formats response.
Multi-Format Pipeline: Agent reads CSV exports, converts to HEDL via hedl_convert_from, validates schemas, exports to Neo4j Cypher, tracks token efficiency.
Bulk Document Processing: AI orchestrates parallel HEDL validation across directories, aggregates lint issues, generates summary reports.
LLM Context Optimization: Analyze HEDL vs JSON token usage with hedl_stats, optimize prompts with hedl_optimize, validate context window limits.
Direct File Watching: No file system watching—client must explicitly call tools to check for changes. Use inotify/fsevents in client if needed.
Multi-Document Transactions: Each tool call is independent—no transactional updates across multiple files. Implement transactions in client layer if required.
Schema Evolution: No automatic schema migration—manual handling of %STRUCT changes required. Use hedl-lint for schema consistency validation.
Distributed Coordination: Single-server design—no distributed consensus or multi-server coordination. Deploy multiple instances behind load balancer if needed.
Tool Execution: ~50-200 MB/s parsing throughput depending on complexity
Caching: 2-5x speedup for repeated validation/query operations
Streaming: O(1) memory per entity regardless of file size
Rate Limiting: <0.1ms overhead per request (~1% impact)
Parallel Processing: Linear speedup up to CPU core count for directory scanning
Detailed performance benchmarks are available in the HEDL repository benchmark suite.
Comprehensive test suite covering:
hedl-core 1.0 - HEDL parsing and data modelhedl-c14n 1.0 - Canonicalizationhedl-lint 1.0 - Best practices lintinghedl-json, hedl-yaml, hedl-xml, hedl-csv, hedl-parquet, hedl-neo4j 1.0 - Format conversionserde 1.0, serde_json 1.0 - JSON serializationtokio 1.0 - Async runtimedashmap 6.1 - Concurrent HashMap for cachingrayon 1.10 - Parallel processingthiserror 1.0 - Error type definitionsApache-2.0