Lambë

io.github.hakimjonas由 GitHub 账号 hakimjonas 发布v0.14.0更新于 Oct 27, 2026

Shape-aware query language for structured data — JSON, YAML, TOML, HCL, CSV, Markdown.

概览

AI 生成的概览

本地 MCP 服务器,提供 Lambë 查询语言,用于查询 JSON、YAML、TOML、HCL、CSV、TSV 和 Markdown,并支持形状检查与 schema 校验。

可以做什么
  • 用管道式表达式查询、过滤、转换和聚合结构化数据文件
  • 返回推断出的形状(JSON Schema 子集文档),帮助了解陌生数据的结构
  • 按 JSON Schema 校验数据,并指出不一致的具体路径
  • 静态追踪查询,显示每个管道阶段的形状、警告以及可序列化的输出格式
  • 对查询结果做布尔断言,并在 JSON、YAML、TOML、CSV、TSV、HCL 之间转换输出
适用场景
适合在助手尚不了解数据结构时使用:检查 API 响应、审计 Helm 或 Terraform 文件、验证 CI 假设,或在不猜测结构的情况下提取字段值。
运行要求
以本地进程(stdio)方式运行,仅限桌面端;清单列出 Linux、macOS 和 Windows 的预编译二进制,README 另提供 Dart 包或从源码构建的方式。未声明需要账号、API 密钥或环境变量。
安装前请注意
它会读取被指定的数据文件,因此不要指向含有不希望进入助手上下文的密钥的文件。它不会就地修改数据,README 说明其不支持原地变更。安装脚本会从 GitHub 发布页下载二进制文件。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Lambë,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Lambë

A query language for structured data that shows you what you're working with.

lam queries JSON, YAML, TOML, HCL, CSV, TSV, and Markdown. Unlike other query tools, it tells you what your query does before you run it — the shape at each pipe stage, which output formats can serialize the result, what would go wrong.

Use it when you don't already know the data: inspecting an unfamiliar API response, auditing a Helm chart, verifying a CI pipeline's assumptions, or asking an AI agent to extract something without guessing at the structure.

$ lam --to toml '.dependencies | keys' pubspec.yamlError: TOML output requires a map at the root, got list<string>.Try appending one of:  | as(toml)    # Wraps the list under a single-entry map (equivalent to `{items: .}`).
$ lam --to toml '.dependencies | keys | as(toml)' pubspec.yamlitems = ["rumil", "rumil_parsers", "rumil_expressions"]

Queries are bounded and always terminate. No recursion, no lambdas, no def. That's the tradeoff: Lambë doesn't try to be a programming language, so its shape inference, --explain, --schema, and error remediations all work.

Lambë (pronounced "lam-beh") means "language" in Quenya (Tolkien's elvish). The package name is lambe for ASCII compatibility.

Installation

One-line installer (Linux and macOS, no sudo, verifies SHA256 checksums):

bash
curl -fsSL https://raw.githubusercontent.com/hakimjonas/lambe/main/install.sh | sh

This downloads lam and lam-mcp from the latest GitHub release into ~/.local/bin/. Environment variables LAMBE_VERSION (pin a version) and LAMBE_PREFIX (change install dir) are supported; see the script for details.

Other options:

bash
# From pub.dev (Dart users)dart pub global activate lambe
# Dart librarydart pub add lambe
# Build from sourcegit clone https://github.com/hakimjonas/lambe.git && cd lambedart compile exe bin/lam.dart -o lam

See Getting started for all installation options.

Shape-aware output

Lambë checks the result of your query against the shape the target format can serialize. When they match, output is produced. When they don't, the error names the required shape and lists query fragments that would bridge it. In an interactive terminal, Lambë offers to apply the chosen fragment and retry in place.

$ lam --to toml '.name' pubspec.yamlTOML output requires a map at the root, got string.Try appending one of:  | as(toml)    # Wraps the scalar under a single-entry map (equivalent to `{value: .}`).
Apply a bridge?  [1] | as(toml)    # Wraps the scalar under a single-entry map (equivalent to `{value: .}`).  [q] cancel> 1value = "rumil"

The same flow applies to CSV and TSV (which require a list of records at the root) and HCL (which requires a map).

Suggestions surface the intent-level as(<format>) form. The explanation names the raw fragment ({value: .}, to_entries, etc.) the bridge composes, so --explain and manual composition stay available to anyone who wants them.

Non-scalar cells in CSV/TSV

By default, nested lists or maps in CSV/TSV cells are rejected — there is no faithful delimited rendering for them. When you need a quick export and lossy is acceptable, pass --flatten-cells json (CLI) or :flatten-cells json (REPL) to encode them as JSON strings inline. Round-tripping the resulting file back into Lambë does not recover the original structure; prefer reshaping the data query-side when fidelity matters.

as(fmt) — bridging in the query language

When the shape of the target format is known up front, as(fmt) performs the bridge inside the query. The combinator is a no-op when the input already satisfies the target, applies a single curated bridge when one exists, and lists the candidates when more than one could apply.

$ lam --to toml '.dependencies | as(toml)' pubspec.yamlrumil = "^0.6.0"rumil_parsers = "^0.6.0"rumil_expressions = "^0.6.0"
$ lam --to csv '.dependencies | as(csv)' pubspec.yamlkey,valuerumil,^0.6.0rumil_parsers,^0.6.0rumil_expressions,^0.6.0

as accepts json, yaml, toml, csv, tsv, and hcl.

--explain — see the shape at every pipe stage

--explain walks the pipe backbone of a query and reports the shape at each stage, followed by the set of output formats the final shape can be serialized as. It performs static analysis only and does not evaluate the query; pass a data file to seed with real shape information, or omit it to trace against an unknown input.

$ lam --explain '.dependencies | keys' pubspec.yaml.dependencies  : map<rumil: string, rumil_parsers: string, rumil_expressions: string>| keys         : list<string>
Writable as: json, yaml, csv, tsvNot writable as: toml, hcl

Explain flags provably-empty filters (filter(.missing) on a known shape) and runtime-rejection mismatches (filter on a non-list input) by default. Pass --explain-trivial to also flag sort_by/group_by/map/unique_by whose argument references a missing field (often a typo, sometimes intentional). For agent tooling and build pipelines, --explain-json emits the same information as a structured JSON document.

--schema — declare a shape and let Lambë check your work

When you have a JSON Schema for your data — from an API contract, OpenAPI spec, or hand-written docs — point --schema at it:

$ lam --schema api.schema.json --explain '.users | map(.email)' response.json.users         : list<map<id: string, name: string, email: optional<string>>>| map(.email)  : list<optional<string>>
Writable as: json, yaml, csv, tsvNot writable as: toml, hcl

The schema fills in information data alone can't express: optional fields (from JSON Schema's required), element shapes of empty lists, types shapeOf couldn't infer from sampling. --explain shows them; the evaluator trusts them.

With data present, Lambë also validates: a schema saying age: number against data with age: "30" exits 1 at load time with a JSON-path-annotated diagnostic. No silent drift, no running a query against data that doesn't match its contract.

A sibling <datafile>.schema.json is auto-detected, so a project convention of placing schemas next to data works without explicit flags.

The reverse direction is symmetrical: lam --print-shape data.json emits the inferred shape as a JSON Schema document. Round-trip:

lam --print-shape data.json > data.schema.json    # bootstrap a schema from datalam --schema data.schema.json '.users' data.json  # use it back

Accepted JSON Schema keywords: type, properties, items, required. Value-level constraints (minimum, pattern, enum, etc.), structural combinators (allOf, oneOf), $ref, and conditional schemas are rejected with a per-keyword error. Lambë is a shape system, not a validation engine — for richer validation, reach for ajv or check-jsonschema.

Query Syntax

Queries start with . (the current data) and chain operations with |:

.                              the whole document.name                          access a field.users[0]                      index into a list.users[0].address.city         chain access.users | filter(.age > 30)     pipe into an operation.users | map(.name)            transform each element

Pipelines read left to right. Each | passes its result to the next operation:

.users | filter(.active) | sort_by(.name) | map(.name)

This takes .users, keeps active ones, sorts by name, and extracts names.

Expressions

.price * .qty                  arithmetic (+, -, *, /, %).age > 30                      comparison (<, >, <=, >=, ==, !=).active && .verified           logic (&&, ||, !)if .age > 65 then "senior" else "active"   conditional{name, total: .price * .qty}   construct a new object"\(.name) is \(.age)"          string interpolation.[1:3]                         slice a list or string

Operations

Operations follow | and transform the piped value:

. | filter(.age > 30)          keep matching elements. | map(.name)                 transform each element. | sort_by(.age)              sort by a key. | group_by(.dept)            group into [{key, values}]. | length                     count elements. | first                      first element. | sum                        sum numbers. | keys                       map keys or list indices. | has("field")               check if a field exists. | unique                     remove duplicates. | flatten                    flatten one level of nesting. | to_entries                 map to [{key, value}] pairs. | filter_values(. > 5)       filter a map's values. | as(toml)                   bridge to an output format

See the full list in Pipeline Operations below.

CLI

bash
# Extract valueslam '.database.host' config.tomllam '.spec.containers[0].image' deployment.yaml
# Filter and transformlam '.users | filter(.age > 30) | map(.name)' data.json
# Aggregatelam '.items | map(.price) | sum' data.json
# Sort and picklam '.items | sort_by(.price) | first' data.json
# Object constructionlam '.users | map({name, senior: .age > 65})' data.json
# String interpolationlam '.users | map("\(.name) is \(.age)")' data.json
# Shape tracelam --explain '.users | map(.name)' data.json
# Shape inspection (JSON Schema output)lam --print-shape data.json
# Schema-checked queries: validate data against a schema as it runslam --schema api.schema.json '.users | map(.email)' response.json
# CI validationlam --assert '.version != "0.0.0"' package.jsonlam --assert '.replicas >= 2' deployment.yaml
# Format conversionlam --to yaml '.config' data.jsonlam --to csv '.users | map({name, age})' data.jsonlam --to toml '.config | as(toml)' data.jsonlam --to csv --flatten-cells json '.users' data.json   # encode nested cells as JSON
# Line-delimited JSON (logs, event streams)lam --ndjson '.user.id' events.ndjsontail -f app.log | lam --ndjson '.level'
# Query any format (auto-detected from extension)lam '. | filter(.status != "closed")' issues.csvlam '.resource | map(._labels)' main.tflam '.children | filter(.type == "heading") | map(.children[0].text)' README.md
# Pipe from stdincurl -s https://api.example.com/users | lam '.results | filter(.active)'

Interactive REPL

bash
lam -i data.json
lambe v0.14.0 - type :help for commands, :q to quitData loaded: {3 fields, 42 users}
lambe> .users | filter(.age > 30) | map(.name)["Bob", "Carol"]
lambe> .users[0]{name: "Alice", age: 25, active: true}
lambe> :schema{users: [{name: "string", age: "number", active: "boolean"}]}
lambe> :to yamlOutput format: yaml

When a query produces a result the current output format cannot serialize, the REPL lists the available bridges inline; pressing the number of a suggestion applies it and prints the bridged output. Tab completion works on field names (.us<TAB>) and pipeline operations (| fil<TAB>). The REPL also supports syntax highlighting, persistent history (~/.lambe_history), Ctrl+R reverse search, and multi-line input with \ continuation.

Library

dart
import 'package:lambe/lambe.dart';
// Query pre-parsed datafinal name = query('.users[0].name', data);
// Query a JSON stringfinal version = queryJson('.version', '{"version": "1.0.0"}');
// Query any formatfinal host = queryString('.database.host', tomlString, format: Format.toml);
// Parse once, evaluate many timesfinal ast = parseAst('.users | filter(.active) | map(.name)');final result1 = evaluateAst(ast, dataset1);final result2 = evaluateAst(ast, dataset2);
// Format conversionfinal yaml = formatOutput(data, OutputFormat.yaml);final csv = formatOutput(users, OutputFormat.csv);
// Shape inference and JSON Schema outputfinal shape = shapeOf(data);                    // Shape ADTfinal schemaJson = renderJsonSchema(shape);     // JSON Schema text
// Or parse a schema file and merge with observed datafinal schema = parseJsonSchema(schemaSource);final merged = mergeSchemaWithData(schema, shape);  // throws on disagreement

Shape and bridging API

dart
// Infer the structural shape of a valuefinal shape = shapeOf(data);// e.g. SMap({'users': SList(SMap({'name': SString(), 'age': SNum()}))})
// Check whether a value can be written in a given formatfinal report = canWriteAs(result, OutputFormat.toml);switch (report) {  case Writable():    stdout.writeln(formatOutput(result, OutputFormat.toml));  case NotWritable(:final suggestions):    for (final r in suggestions) {      print('${r.label}: | ${r.display} — ${r.explanation}');    }}
// Compose a user query with a bridge fragmentfinal bridges = synthesize(shape, OutputFormat.csv);if (bridges.isNotEmpty) {  final composed = applyBridge(userAst, bridges.first);  final bridged = evaluateAst(composed, data);}
// Static shape tracefinal trace = explain(parseAst('.users | map(.name)'), shapeOf(data));for (final stage in trace.stages) {  print('${stage.source}: ${renderShape(stage.shape)}');}

Supported Formats

FormatInputOutputConformance
JSONyesyesRFC 8259 (318/318)
YAMLyesyesYAML 1.2.2 (333/333)
TOMLyesyesTOML 1.1 (681/681)
HCL/TerraformyesyesHashiCorp spec (2760/2760)
CSVyesyesRFC 4180 + auto-dialect detection
TSVyesyesTab-separated variant of CSV
Markdownyes—CommonMark 0.31.2 (652/652)

Parsers from rumil_parsers, tested against official spec suites.

Markdown is input-only in this release. The Markdown AST is a presentation tree rather than a data structure, so there is no general-purpose mapping from arbitrary query results back to Markdown text. Projections of a Markdown document (lists of headings, counts, filtered sections) emit as JSON, YAML, CSV, or TSV through the usual --to flag.

Pipeline Operations

OperationExampleDescription
filter.users | filter(.active)Keep elements matching predicate
map.users | map(.name)Transform each element
sort. | sortSort naturally
sort_by.users | sort_by(.age)Sort by key
group_by.users | group_by(.dept)Group into {key, values}
unique. | uniqueRemove duplicates
unique_by.users | unique_by(.id)Remove duplicates by key
flatten. | flattenFlatten one level
reverse. | reverseReverse order
keys. | keysMap keys or list indices
values. | valuesMap values
length. | lengthLength of list, map, or string
first. | firstFirst element
last. | lastLast element
sum. | sumSum numbers
avg. | avgAverage
min. | minMinimum
max. | maxMaximum
has. | has("name")Check field exists
to_entries. | to_entriesMap to [{key, value}]
from_entries. | from_entries[{key, value}] to map
to_number.price | to_numberParse a string as a number
type. | typeRuntime type as a string
filter_values. | filter_values(. > 5)Filter map values
map_values. | map_values(. * 2)Transform map values
filter_keys. | filter_keys(. != "secret")Filter map keys
as. | as(toml)Bridge to an output format's shape

AI Integration

Lambë ships as both an Agent Skill (loaded into an agent's session as expertise) and an MCP server (callable as a runtime tool).

Agent Skill

The skill folder lives at .agents/skills/lambe/ in this repository, following the cross-vendor agent-skills specification that Claude Code, OpenAI Codex, GitHub Copilot, Cursor, and the Microsoft Agent Framework all read.

To make Lambë available to an agent in another project, copy the folder into the agent-conventional location:

bash
# Personal (available across all your projects)git clone https://github.com/hakimjonas/lambe /tmp/lambe-skillmkdir -p ~/.agents/skillscp -r /tmp/lambe-skill/.agents/skills/lambe ~/.agents/skills/
# Project-localcp -r /tmp/lambe-skill/.agents/skills/lambe <your-project>/.agents/skills/

Agents that follow the spec auto-discover the skill at session start.

MCP Server

Install, then add .mcp.json to your project:

json
{  "mcpServers": {    "lambe": {      "command": "lam-mcp",      "args": []    }  }}

This gives AI assistants five tools that cover the whole feedback loop:

  • lambe_query — extract/filter/transform, with an optional schema parameter that validates data structurally before the query runs.
  • lambe_print_shape — inspect unfamiliar data; returns a JSON Schema subset document.
  • lambe_check — validate data against a JSON Schema. Returns {"ok": true} or {"ok": false, "error": "..."} naming the disagreement path.
  • lambe_explain — trace a query statically (with or without data); returns a structured JSON report with shape-per-stage, warnings, and writability.
  • lambe_assert — boolean assertion on a query result.

When lambe_query encounters a shape mismatch with the requested output format, the error response includes a structured suggestions array: each entry carries a template_text, an apply_as (the complete query formed by appending the template to the original expression), and a one-line explanation. Agents can call the tool again with an apply_as verbatim.

For AI Coding Agents

Add AGENTS.md and .mcp.json to your project root. AI assistants that open the project will discover and use Lambë for data queries.

In CI

yaml
# Validate config in GitHub Actions- run: |    dart pub global activate lambe    lam --assert '.version != "0.0.0"' pubspec.yaml    lam --assert '.jobs | keys | length > 0' .github/workflows/ci.yml

Test Matchers

The lambe_test package provides test matchers for Dart:

dart
import 'package:lambe_test/lambe_test.dart';
expect(response, lamWhere('.errors | length == 0'));expect(config, lamEquals('.database.port', 5432));expect(data, lamMatches('.name', startsWith('A')));expect(data, lamHas('.users[0].address.city'));

Documentation

What lambë is not

Lambë is a bounded tree transformer over JSON-shaped data. It deliberately omits Turing-completeness, user-defined functions, recursive descent (..), try/catch, regex, streaming, and in-place mutation. Staying bounded is what makes shape inference, --explain, and as(fmt) bridging work.

See doc/non-goals.md for the full list and the lambë idiom that replaces each omission.

Design

See DESIGN.md for architecture and design decisions.

Part of the Arda Ecosystem

Built on Rumil parser combinators with left-recursive grammar support.

  • Rumil - parser combinators with left recursion
  • Rumil Parsers - format parsers for JSON, YAML, TOML, XML, CSV, HCL, Proto3, Markdown
  • Rumil Expressions - shared evaluation helpers

来源:README.md,提交 18c0a1a

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.14.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分