A human-friendly DSL for ATProto Lexicons

+++ title = "Getting Started" description = "Install MLF and write your first lexicon" weight = 1 +++

Installation#

Clone and build from source:

git clone https://tangled.org/@stavola.xyz/mlf
cd mlf
cargo build --release

The binary will be at target/release/mlf.

Optionally, install to your PATH:

# Option 1: Use cargo install
cargo install --path mlf-cli

# Option 2: Manually copy the binary
cp target/release/mlf /usr/local/bin/

Your First Lexicon#

Create a file thread.mlf:

/// A forum thread
record thread {
    /// Thread title
    title!: string constrained {
        maxLength: 200,
        minLength: 1,
    },
    /// Thread body
    body!: string constrained {
        maxLength: 10000,
    },
    /// Thread creation timestamp
    createdAt!: Datetime,
};

Generate JSON Lexicon#

mlf generate lexicon -i thread.mlf -o lexicons/

This creates lexicons/com/example/thread.json with the ATProto JSON lexicon.

Validate MLF Files#

mlf check thread.mlf

This checks your MLF file for syntax and validation errors.

Validate Records#

Given a JSON record file record.json:

{
  "title": "Welcome to the forums!",
  "body": "This is my first thread. Looking forward to discussions!",
  "createdAt": "2024-01-15T10:30:00Z"
}

Validate it against your lexicon:

mlf validate thread.mlf record.json

Convert JSON Lexicons to MLF#

Already have ATProto JSON lexicons? Convert them to MLF format:

mlf generate mlf -i my-lexicon.json -o ./

This is useful for:

  • Migrating existing lexicons to MLF
  • Learning MLF syntax by seeing JSON conversions
  • Working with lexicons from other sources

Next Steps#