Token导航 LogoToken导航TokenDH.com
Toon Context MCP logo
AI代理stdio官方级别未说明来源级核验

Toon Context MCP

MCP Server

TOON-MCP是一个模型上下文协议服务器,能够将冗长的JSON结构转换为Token优化的对象表示法(TOON),在AI辅助开发工作流程中减少高达60%的令牌消耗。

工具数

0

提示词数

0

GitHub Stars

5

资源数

0
令牌优化PythonClaude数据转换Claude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

aj-geddes

提供方

aj-geddes

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install -e .

详细介绍

TOON-MCP:令牌优化对象表示法

![License: MIT](LICENSE) ![Python 3.10+](https://www.python.org/downloads/) ![MCP](https://modelcontextprotocol.io)

TOON-MCP是一个模型上下文协议服务器,可以自动将详细的JSON结构转换为 令牌优化对象表示法(TOON),将人工智能辅助开发工作流程中的代币消耗减少高达 60%.

🚀 特性

  • 智能压缩:自动模式检测和智能JSON优化
  • 令牌监控:实时跟踪会话令牌使用情况,并提供优化建议
  • MCP集成:与Claude和其他MCP客户无缝集成
  • 无损转换:JSON和TOON之间的完美往返转换
  • 自动优化:主动转换工具产出,以实现最高效率
  • 预提交钩子:扫描JSON代码并建议TOON转换
  • 上下文管理:监控和优化对话中的令牌使用情况

📊 快速示例

原始JSON (142个代币):

{
  "id": 12345,
  "name": "John Doe",
  "email": "john@example.com",
  "type": "user",
  "status": "active",
  "metadata": {
    "created_at": "2025-01-01T00:00:00Z",
    "updated_at": "2025-01-15T10:30:00Z"
  }
}

TOON格式 (68个令牌, 减少52%):

{"_toon":"1.0","d":{"i":12345,"n":"John Doe","eml":"john@example.com","t":"user","s":"active","meta":{"ca":"2025-01-01T00:00:00Z","ua":"2025-01-15T10:30:00Z"}}}

📦 安装

先决条件

  • Python 3.10或更高版本
  • pip包管理器

快速安装

# Clone the repository
git clone https://github.com/aj-geddes/toon-context-mcp.git
cd toon-context-mcp

# Install TOON-MCP
cd mcp-server-toon
pip install -e .

Docker安装

TOON-MCP可以在Docker容器中运行,以便于部署和隔离:

# Clone the repository
git clone https://github.com/aj-geddes/toon-context-mcp.git
cd toon-context-mcp/mcp-server-toon

# Build the Docker image
docker build -t toon-mcp-server:latest .

# Run with Docker
docker run -i toon-mcp-server:latest

# Or use Docker Compose
docker-compose up -d

备注Docker镜像使用基于Debian的Python(Python:3.10-slim)来获得最佳性能,而不是Alpine。

对于MCP与Docker的集成,请更新您的Claude Desktop配置以使用容器化服务器:

{
  "mcpServers": {
    "toon": {
      "command": "docker",
      "args": ["run", "-i", "toon-mcp-server:latest"]
    }
  }
}

MCP配置

添加到您的Claude桌面配置(~/.config/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "toon": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/toon-context-mcp/mcp-server-toon"
    }
  }
}

🎯 项目结构

toon-context-mcp/
├── mcp-server-toon/          # Phase 1: Core MCP Server
│   ├── src/
│   │   ├── toon_converter.py  # Core TOON logic
│   │   ├── server.py          # MCP server
│   │   └── patterns.py        # Pattern detection
│   ├── tests/
│   │   └── test_conversions.py
│   ├── pyproject.toml
│   └── README.md
├── claude-code-integration/   # Phase 2: Claude Code Integration
│   ├── auto_converter.py      # Auto-conversion system
│   └── example_generator.py   # TOON example generator
├── context-manager/           # Phase 3: Context Manager
│   ├── token_monitor.py       # Token usage monitoring
│   ├── tool_output_optimizer.py # Proactive conversion
│   └── mcp_integration.py     # MCP integration helpers
├── docs/                      # Complete Jekyll documentation
│   ├── index.md
│   ├── guides/
│   │   ├── setup.md
│   │   ├── user-guide.md
│   │   └── troubleshooting.md
│   └── api/
│       └── reference.md
└── .git/hooks/
    └── pre-commit              # JSON scanning hook

🔧 用法

基本转换

from src.toon_converter import convert_json_to_toon, convert_toon_to_json

# Convert to TOON
toon_format = convert_json_to_toon(your_json_data)

# Convert back to JSON
original = convert_toon_to_json(toon_format)

MCP工具

在Claude中使用这些工具:

  • convert_to_toon -将JSON转换为TOON格式
  • convert_to_json -将TOON转换回JSON
  • analyze_patterns -检测优化模式
  • get_compression_strategy -获得最佳压缩策略
  • calculate_savings -计算代币节省
  • batch_convert -转换多个JSON对象

令牌监控

from context_manager.token_monitor import TokenMonitor

monitor = TokenMonitor(warn_threshold=50000)

# Analyze messages
monitor.analyze_message(message_content, role='user')

# Get metrics
metrics = monitor.get_metrics()
print(f"Total tokens: {metrics.total_tokens:,}")
print(f"Potential savings: {metrics.savings_percent:.1f}%")

刀具输出优化

from context_manager.tool_output_optimizer import ToolOutputOptimizer

optimizer = ToolOutputOptimizer(auto_optimize=True, min_savings=15.0)

# Automatically optimize tool outputs
optimized, metadata = optimizer.optimize_tool_output("api_call", tool_output)

📚 文档

完整的文档可在 /docs:

在本地查看文档

cd docs
# Install Jekyll (if not already installed)
gem install bundler jekyll

# Create Gemfile
cat > Gemfile  4.3"
gem "minima", "~> 2.5"
gem "jekyll-seo-tag"
gem "jekyll-sitemap"
gem "jekyll-feed"
EOF

# Install and serve
bundle install
bundle exec jekyll serve

# Open http://localhost:4000

🧪 测试

cd mcp-server-toon
pytest tests/ -v

🎨 按阶段划分的功能

第一阶段:核心MCP服务器✅

  • 带智能压缩的TOON转换器
  • 图案检测系统
  • 配备6个工具的MCP服务器
  • 全面的测试套件
  • 包配置

第二阶段:Claude代码集成✅

  • JSON扫描的预提交钩子
  • 代码/文档自动转换系统
  • TOON示例生成器
  • 支持多种语言

阶段3:上下文管理器✅

  • 令牌使用监控
  • 主动工具输出转换
  • MCP服务器集成助手
  • 优化建议

📈 演出

按数据类型分类的典型代币节省:

  • API响应:节省40-60%
  • 数据库结果:节省50-65%
  • 配置文件:节省35-50%
  • 对象数组:节省55-70%

🤝 贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支
  3. 运行测试: pytest tests/ -v
  4. 提交拉取请求

📄 许可证

MIT许可证-请参阅 许可证 详细信息文件

🔗 链接

  • 文档:参见 /docs 目录
  • 问题:
  • 讨论:

🌟 为什么是TOON?

在人工智能辅助开发中,令牌限制可能会限制您的工作流程。TOON帮助您:

  • 适应更多上下文 在对话中
  • 降低API成本 代币较少
  • 缩短响应时间 有效载荷较小
  • 处理更大的数据集 在令牌限制范围内

📊 建筑

graph TB
    subgraph "TOON-MCP Server"
        A[MCP Server] --> B[TOON Converter]
        A --> C[Pattern Detector]
        A --> D[Token Monitor]
    end

    subgraph "Claude Code Integration"
        E[Pre-commit Hook] --> F[Auto-Converter]
        F --> G[Example Generator]
    end

    subgraph "Context Manager"
        H[Token Monitor] --> I[Tool Optimizer]
        I --> J[MCP Integration]
    end

    K[Claude / MCP Client] --> A
    A --> K

🎯 路线图

  • \[x\] 核心TOON转换器
  • \[x\] MCP服务器实现
  • \[x\] 模式检测
  • \[x\] Claude代码集成
  • \[x\] 上下文管理器
  • \[x\] 完整的文档
  • \[\]Types/JavaScript端口
  • \[\]VSCode扩展
  • \[\]浏览器扩展
  • \[\]性能基准
  • \[\]社区模板

💡 用例

  1. 大型代码库分析:压缩文件列表和搜索结果
  2. API集成:优化对话中的API响应存储
  3. 数据库查询:共享查询结果时减少令牌使用
  4. 配置管理:以紧凑格式存储配置
  5. 文档:包括没有令牌开销的示例

______________________________________________________________________

内置于❤️ 面向人工智能开发社区

*减少代币。提高生产率。*

目录标签

目录标签

令牌优化PythonClaude数据转换JSON压缩本地部署AI开发工具MCP集成

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

token

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiotoken部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP