datoon

io.github.andrii-su由 GitHub 账号 andrii-su 发布v1.9.1更新于 Oct 24, 2026

Smart structured-data to TOON gateway: converts to TOON only when it saves LLM tokens.

概览

AI 生成的概览

把 JSON、CSV、YAML 等结构化数据转换为 TOON 格式供 LLM 提示使用,但仅在确实节省 token 时才转换。

可以做什么
datoon 是一个本地 MCP 服务器,在结构化数据进入提示之前将其转换为紧凑的表格文本格式 TOON。它提供三个工具:convert_json 进行带策略门控的完整 JSON 转换,convert_text 处理 CSV、YAML、XML 或 JSONL 文本,analyze_json 仅做结构分析。决策层会检查数据是否为行数足够的统一对象数组,以及预估 token 节省是否超过阈值;不满足时返回原始数据。每次结果都附带包含决策、原因和 token 估算的报告。
适用场景
当提示中包含大量统一表格数据(如 CSV 导出、JSONL 事件日志或 API 响应),并希望在不冒转换反而变差风险的前提下减少 payload token 时使用。也适合需要在流水线中为每次格式决策留下明确可记录原因的场景。
运行要求
作为本地进程运行,通常通过 uvx 从 PyPI 包 datoon 加 mcp 附加组件启动。需要 Python 3.12 或更高版本。TOON 转换本身需要 PATH 中有 Node.js 和 npx;分析与格式读取无需 Node.js。可选附加组件支持 YAML、Excel、Parquet/ORC/Avro、Apple Numbers 以及基于 tiktoken 的 token 计数。未声明任何账号、API 密钥或环境变量。
安装前请注意
转换会通过 npx 调用外部 TOON CLI,被转换的数据会离开 Python 进程进入该子进程。--force 标志会绕过节省门控,可能产生更大的 payload。token 节省仅为 payload 部分的估算,并非端到端模型用量,且取决于数据形态。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[图片]

datoon

smart structured-data→TOON gateway — converts only when it actually saves tokens

[Tests] [Pre-commit] [Release] [PyPI] [Python] [License: MIT]

Before/After • Install • What You Get • How It Works • Benchmarks • Full install guide


Raw structured data is often verbose in LLM prompts. TOON can save tokens — but blind conversion can also make payloads worse. datoon adds a decision layer: convert when structure and savings justify it, skip when they don't, and always explain why.

Supports JSON, CSV, JSONL, YAML, XML, Parquet, Avro, ORC, Excel, and Apple Numbers — auto-detected from file extension.

Before / After

JSON in the prompt (43 tokens)

json
{"users":[  {"id":1,"name":"Ada","role":"admin"},  {"id":2,"name":"Lin","role":"analyst"},  {"id":3,"name":"Grace","role":"viewer"}]}

datoon converts → TOON (24 tokens)

toon
users[3]{id,name,role}:  1,Ada,admin  2,Lin,analyst  3,Grace,viewer
json
{"decision":"convert","reason":"Estimated savings 44.19% (threshold 15.00%)."}

CSV from a data pipeline (111 tokens as JSON)

csv
id,name,role1,Ada,admin2,Lin,analyst3,Grace,viewer

datoon auto-converts → TOON (24 tokens)

bash
datoon data.csv --report-stdout

Same result. Zero JSON serialization in your code.

Non-uniform payload (26 tokens)

json
{"config":{"debug":true},"tags":["a","b"]}

datoon skips → keeps JSON

json
{"decision":"skip","reason":"No uniform object arrays found with at least 3 rows."}

No Node.js call. No silent corruption.

Same data. Right format. Always explained.

┌──────────────────────────────────────────────────┐│  PAYLOAD SAVINGS (auto avg)    ████░░░░░░   28%  ││  PAYLOAD SAVINGS (agent skill) ████████░░   62%  ││  DECISION ACCURACY             ██████████  100%  ││  HARMFUL CONVERSIONS BLOCKED   ██████████  100%  │└──────────────────────────────────────────────────┘

[!IMPORTANT] datoon saves payload tokens — the structured data portion of your prompt. Token savings depend on payload shape: uniform tabular data converts well; deeply nested or non-uniform structures are skipped. Every decision includes a reason so pipelines can log, debug, and trust the outcome.

Install

bash
# core (JSON, CSV, JSONL, XML — no extra deps)uv add datoonpip install datoon
# with YAML supportpip install "datoon[yaml]"
# with Excel supportpip install "datoon[excel]"
# with Parquet / ORC / Avro supportpip install "datoon[columnar]"
# with Apple Numbers supportpip install "datoon[numbers]"
# with tiktoken-based token countingpip install "datoon[tokens]"
# with MCP serverpip install "datoon[mcp]"
# everythingpip install "datoon[all]"

Requires Python 3.12+. TOON conversion requires Node.js with npx in PATH — analysis and format reading work without it.

For Claude Code plugin, Codex, and MCP config → INSTALL.md.

What You Get

What
datoon CLIAuto-gate any supported format → TOON from terminal or scripts
Python APIconvert_json_for_llm() + read_tabular() for any LLM pipeline
MCP Serverconvert_json, convert_text, analyze_json tools for Claude Desktop, Cursor, Windsurf
Claude Code Plugin/datoon in-session trigger, installs from GitHub in one command
Codex PluginMarketplace plugin — structured-data mode for Codex

Supported input formats

FormatExtensionExtra needed
JSON.json—
JSONL.jsonl, .ndjson—
CSV.csv—
XML.xml—
YAML.yaml, .ymldatoon[yaml]
Excel.xlsx, .xlsdatoon[excel]
Parquet.parquetdatoon[columnar]
Avro.avrodatoon[columnar]
ORC.orcdatoon[columnar]
Apple Numbers.numbersdatoon[numbers]

How It Works

  1. Detect format — from --format flag, file extension, or default to JSON for stdin
  2. Read + normalize — parse source into list of row dicts; serialize to compact JSON
  3. Analyze structure — uniform object arrays? acceptable depth? minimum rows?
  4. Gate early — non-candidates skip before any CLI call; no Node.js overhead
  5. Convert + estimate — TOON CLI runs, token savings calculated
  6. Gate savings — below threshold → return JSON; above → return TOON with report

Every path returns a ConversionReport with decision, reason, and token estimates. Pipelines never get silent surprises.


Quick Start

JSON (stdin):

bash
echo '{"users":[{"id":1,"name":"Ada"},{"id":2,"name":"Lin"},{"id":3,"name":"Grace"}]}' | datoon --report-stdout

CSV (auto-detected from extension):

bash
datoon data.csv --report-stdout

JSONL:

bash
datoon data.jsonl -o output.toon

YAML (requires datoon[yaml]):

bash
datoon data.yaml --report-stdout

Parquet (requires datoon[columnar]):

bash
datoon data.parquet --report ./report.json

Explicit format override:

bash
datoon --format csv < data.csv --report-stdout

Force conversion (bypass gating — for experiments):

bash
datoon data.json --force --report-stdout

Python API

JSON conversion:

python
from datoon import convert_json_for_llm, ConversionConfig, DatoonError
config = ConversionConfig(min_savings_ratio=0.15, max_depth=6, min_uniform_rows=3)
try:    outcome = convert_json_for_llm(raw_json, config)except DatoonError as exc:    raise
# outcome.payload_text  — TOON or original JSON# outcome.report.decision  — "convert" | "skip"# outcome.report.reason    — human-readable explanationsend_to_model(outcome.payload_text)

Any format via read_tabular:

python
import jsonfrom pathlib import Pathfrom datoon import read_tabular, convert_json_for_llm, ConversionConfig
# text formats: csv, jsonl, yaml, xmlrows = read_tabular("csv", text=csv_string)
# binary formats: excel, parquet, orc, avro, numbersrows = read_tabular("parquet", path=Path("data.parquet"))
json_text = json.dumps(rows, separators=(",", ":"))outcome = convert_json_for_llm(json_text, ConversionConfig())send_to_model(outcome.payload_text)

Structure-only analysis (no Node.js required):

python
from datoon.analyzer import analyze_payloadfrom datoon.models import ConversionConfig
analysis = analyze_payload(parsed_data, ConversionConfig())print(analysis.is_candidate, analysis.reason)

MCP Server

datoon ships an MCP server with three tools:

ToolDescription
convert_jsonFull JSON conversion with policy gating
convert_textConverts CSV, YAML, XML, or JSONL text with policy gating
analyze_jsonStructure analysis only — no Node.js needed

Claude Desktop / Cursor / Windsurf config:

json
{  "mcpServers": {    "datoon": {      "command": "uvx",      "args": ["--from", "datoon[mcp]", "datoon", "mcp"]    }  }}

Run locally:

bash
datoon mcp     # or the standalone script: datoon-mcp

Listed on the MCP Registry, Smithery, and Glama. See MARKETPLACES.md.


Claude Code Plugin

Install directly from GitHub:

bash
claude plugin marketplace add andrii-su/datoonclaude plugin install datoon@datoon

Trigger in-session:

/datoonconvert this JSON to TOON if it saves tokensuse datoon mode for structured data

CLI Reference

FlagDefaultDescription
--formatautoInput format: json, csv, jsonl, yaml, xml, excel, parquet, avro, orc, numbers
--forcefalseBypass gating and minimum savings threshold
--min-savings0.15Minimum relative token savings required
--max-depth6Maximum nesting depth for auto-conversion
--min-uniform-rows3Minimum rows in uniform object arrays
--timeout30Seconds before TOON CLI call is aborted
--report <path>—Write JSON conversion report to file
--report-stdout—Print JSON conversion report to stderr
-o <path>stdoutOutput file path
--version—Print version and exit

Format is auto-detected from file extension. Use --format to override or when reading from stdin.


Benchmarks

bash
PYTHONPATH=src python benchmarks/run.py --dry-runPYTHONPATH=src python benchmarks/run.pyPYTHONPATH=src python benchmarks/run.py --update-readme

Why auto mode outperforms forced conversion

Auto mode avoids low-benefit and high-risk payloads (orders-nested, mixed-non-uniform) while matching forced TOON's average token count on suitable ones. Every decision comes with a reasoned report.

ScenarioJSON BaselineForced TOONdatoon Auto
Average tokens775050
Avg token saved0.0%26.8%28.1%
Decision qualityn/aConverts allConverts 3/5, skips harmful cases
DatasetJSONTOON (forced)Raw SavedAutoAuto TokensAuto Saved
users-small544025.9%convert4025.9%
events-medium21916226.0%convert16226.0%
orders-nested106116-9.4%skip1060.0%
mixed-non-uniform3547-34.3%skip350.0%
metrics-wide14210327.5%convert10327.5%
Average111947.1%3/5 convert8915.9%

Forced conversion succeeded for 5/5 payloads.

Format conversion benchmark

Token savings when converting from common structured formats (CSV, JSONL, XML, YAML). Baseline is the JSON representation of the same data — what an LLM would receive without datoon.

DatasetFormatJSON TokensTOON (forced)AutoAuto TokensAuto Saved
users-csvcsv5329convert2945.3%
events-jsonljsonl194109convert10943.8%
catalog-xmlxml9650convert5047.9%
metrics-yamlyaml12961convert6152.7%
Average—118624/4 convert6247.4%

Forced conversion succeeded for 4/4 payloads.

Agent skill evaluation

Artifact-based subagent comparison — identical analysis tasks, two modes:

  • with_skill: agent received the datoon skill and followed the conversion workflow.
  • without_skill: agent used JSON directly, no TOON or datoon.

3 payload sizes × 3 iterations = 18 total agent runs. Both modes: 100% correct answers.

ScenarioAvg JSON TokensAvg TOON TokensAvg Payload Saved
small22511847.6%
medium2,9721,13861.7%
large17,7576,67362.4%

Full report and raw outputs: benchmarks/agent_skill_eval/. Savings are payload-token estimates, not full end-to-end model-token usage.


Development

Contributor workflow: CONTRIBUTING.md. Maintainer/agent notes: CLAUDE.md.

Setup:

bash
uv sync --extra devuvx pre-commit install

Tests:

bash
pytest -m "not integration"   # unit only (102 tests)pytest                        # with integration (requires Node.js + npx)

Skill sync + plugin metadata:

bash
python scripts/validate_skill_sync.pypython scripts/validate_plugin_metadata.py

Links


License

MIT

来源:README.md,提交 1579e24

工具

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

版本历史

1
  1. v1.9.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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