ASON压缩服务器

用于JSON数据压缩和解压的模型上下文协议服务器,支持ASON格式以减少20-60%的令牌使用。

  • by ason-format
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 ason-format/mcp-server

使用说明

ASON MCP服务器

用于ASON压缩/解压缩的模型上下文协议(MCP)服务器。使Claude Desktop、Cline、Continue和其他MCP客户端能够使用令牌优化的ASON格式压缩JSON数据。

特性

  • compress_json:将JSON转换为ASON格式(令牌减少20-60%)
  • 解压:将ASON转换回JSON(无损)
  • get_pression_stats:在不执行压缩的情况下分析压缩度量
  • 配置压缩机:全局自定义压缩设置

安装

方案1:地方发展

cd mcp-server
npm install
npm run build

选项2:全局安装

npm install -g @ason-format/mcp-server

使用Claude Desktop

添加到您的Claude Desktop配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "ason": {
      "command": "node",
      "args": [
        "/absolute/path/to/ason/mcp-server/dist/index.js"
      ]
    }
  }
}

或者,如果全局安装:

{
  "mcpServers": {
    "ason": {
      "command": "ason-mcp"
    }
  }
}

可用工具

1.压缩

将JSON数据压缩为ASON格式。

输入:

{
  "json": {"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]},
  "config": {
    "indent": 1,
    "delimiter": "|",
    "useReferences": true,
    "useSections": true,
    "useTabular": true
  }
}

输出:

ASON 2.0 Output:

users:[2]{id,name}
1|Alice
2|Bob

Configuration used:
{
  "indent": 1,
  "delimiter": "|",
  "useReferences": true,
  "useSections": true,
  "useTabular": true
}

2.解压

将ASON解压缩回JSON。

输入:

{
  "ason": "users:[2]{id,name}\n1|Alice\n2|Bob"
}

输出:

{
  "users": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"}
  ]
}

3.获取压缩数据

分析压缩统计数据。

输入:

{
  "json": {"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]},
  "config": {
    "indent": 1,
    "delimiter": "|"
  }
}

输出:

Compression Statistics:

Original Tokens: 32
Compressed Tokens: 15
Reduction: 53.13%

Original Size: 78 bytes
Compressed Size: 41 bytes
Savings: 37 bytes

Configuration:
{
  "indent": 1,
  "delimiter": "|",
  "useReferences": true,
  "useSections": true,
  "useTabular": true
}

4.配置压缩机

更新全局压缩设置。

输入:

{
  "config": {
    "indent": 2,
    "delimiter": ",",
    "useReferences": false
  }
}

输出:

Global configuration updated:

{
  "indent": 2,
  "delimiter": ",",
  "useReferences": false,
  "useSections": true,
  "useTabular": true
}

配置选项

选项 类型 默认值 描述
indent 编号 1 嵌套结构的缩进级别
delimiter 字符串 `" "`
useReferences 布尔值 true 启用 $var 参考重复数据删除
useSections 布尔值 true 启用 @section 对象组织
useTabular 布尔值 true 启用 [N]{fields} 数组的表格格式
minFieldsForSection 编号 3 创建最小字段数 @section
minRowsForTabular 编号 2 表格数组格式的最小行数
minReferenceOccurrences 编号 2 创建一个 $var 参考文献

发展

# Build
npm run build

# Watch mode
npm run watch

# Test locally
node dist/index.js

Claude Desktop中的示例用法

User: Can you compress this JSON for me?
{
  "products": [
    {"id": 1, "name": "Laptop", "price": 999},
    {"id": 2, "name": "Mouse", "price": 25}
  ]
}

Claude: I'll use the compress_json tool to compress this JSON.
[Uses MCP tool compress_json]

Result:
products:[2]{id,name,price}
1|Laptop|999
2|Mouse|25

This compressed version uses 45% fewer tokens!

🚀 出版

要发布新版本,请执行以下操作:

# Run the release script
./scripts/release.sh

# 1. Select version bump (patch/minor/major)
# 2. Update CHANGELOG.md when prompted
# 3. Confirm push

# GitHub Actions will automatically:
# - Build the package
# - Publish to NPM (@ason-format/mcp-server)
# - Create GitHub Release

🧪 支持的MCP客户端

  • ✅ 克劳德桌面 (人类学)
  • ✅ 克莱恩 (VS代码扩展)
  • ✅ 继续 (VS代码扩展)
  • ✅ 任何MCP客户端 使用stdio传输

📚 ASON 2.0是什么?

ASON(别名序列化对象表示法)2.0是一种为LLM设计的令牌优化的JSON压缩格式。它将令牌使用量减少了20-60%,同时保持了100%的无损往返保真度。

主要特点:

  • 章节 (@section)-组织相关对象
  • 表格阵列 (key:[N]{fields})CSV格式适用于统一数组
  • 参考文献 ($var)-消除重复值
  • 管道分隔符 (|)-比逗号更有令牌效率

了解更多: 原因格式.ithub.io/son

📖 文档

📝 许可证

麻省理工学院©ASON项目贡献者

🤝 贡献

欢迎投稿!请打开问题或拉取请求。

🔗 链接

  • NPM: https://www.npmjs.com/package/@ason格式/mcp服务器
  • GitHub: https://github.com/ason-format/mcp-server
  • 问题: https://github.com/ason-format/mcp-server/issues
  • ASON核心: https://github.com/ason-format/ason