Merged
Conversation
Member
|
Cool, will take a look soon! |
Add a tool_post_invoke plugin that converts JSON tool results to TOON (Token-Oriented Object Notation) format, achieving 30-70% token reduction. Features: - Pure Python TOON encoder/decoder per spec v3.0 - Configurable size thresholds and tool filtering - Format markers for downstream parsing - Graceful error handling with skip_on_error fallback - Columnar format for homogeneous object arrays Closes IBM#2574 Signed-off-by: Joe Stein <joe.stein@sscinc.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
be408dc to
260abcf
Compare
crivetimihai
approved these changes
Jan 30, 2026
Member
|
Thanks @joestein-ssc for this excellent contribution! The TOON encoder plugin is a great addition for token efficiency. I've rebased your branch onto Fixes AppliedTOON Spec Compliance:
Decoder Fixes:
Plugin Improvements:
Cleanup:
All 121 TOON encoder tests and 5285 unit tests pass. The branch has been force-pushed to your fork. Please review and let me know if you have any questions! |
Add documentation about tab/pipe delimiter limitation in columnar array headers. The TOON spec v3.0 allows alternative delimiters, which our regex matches but decoder doesn't parse correctly (always splits on commas). Document this as a known decoder limitation. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add support for alternative delimiters (tab, pipe) in columnar array headers per TOON spec v3.0. The decoder now detects the delimiter from the header and uses it consistently for parsing row values. - Add _detect_delimiter() function to identify delimiter from header - Update _decode_columnar_array() to accept and use delimiter parameter - Update _split_row_values() to split on configurable delimiter - Add tests for pipe and tab delimiter decoding - Remove limitation from README (now fully supported) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
- Remove unused Union import (F401) - Remove unused ind variable in _encode_array (F841) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Silence vulture warnings by prefixing intentionally unused parameters: - _as_root in _encode_array and _encode_object (for API consistency) - _expected_count in _split_row_values (for potential validation) - _context in tool_post_invoke (required by plugin interface) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
get_plugin_by_name() only checked the registry for enabled plugins, causing "Not Found" errors when clicking View Details on disabled plugins. Now falls back to checking config.plugins for disabled plugins, matching the behavior of get_all_plugins(). Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
hughhennelly
pushed a commit
to hughhennelly/mcp-context-forge
that referenced
this pull request
Feb 8, 2026
* feat(plugins): add TOON encoder plugin for token-efficient responses Add a tool_post_invoke plugin that converts JSON tool results to TOON (Token-Oriented Object Notation) format, achieving 30-70% token reduction. Features: - Pure Python TOON encoder/decoder per spec v3.0 - Configurable size thresholds and tool filtering - Format markers for downstream parsing - Graceful error handling with skip_on_error fallback - Columnar format for homogeneous object arrays Closes IBM#2574 Signed-off-by: Joe Stein <joe.stein@sscinc.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * lint Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs(toon): document alternative delimiter limitation Add documentation about tab/pipe delimiter limitation in columnar array headers. The TOON spec v3.0 allows alternative delimiters, which our regex matches but decoder doesn't parse correctly (always splits on commas). Document this as a known decoder limitation. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * feat(toon): support tab/pipe delimiters in columnar arrays Add support for alternative delimiters (tab, pipe) in columnar array headers per TOON spec v3.0. The decoder now detects the delimiter from the header and uses it consistently for parsing row values. - Add _detect_delimiter() function to identify delimiter from header - Update _decode_columnar_array() to accept and use delimiter parameter - Update _split_row_values() to split on configurable delimiter - Add tests for pipe and tab delimiter decoding - Remove limitation from README (now fully supported) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(toon): remove unused import and variable - Remove unused Union import (F401) - Remove unused ind variable in _encode_array (F841) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(toon): prefix unused parameters with underscore Silence vulture warnings by prefixing intentionally unused parameters: - _as_root in _encode_array and _encode_object (for API consistency) - _expected_count in _split_row_values (for potential validation) - _context in tool_post_invoke (required by plugin interface) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(admin): return disabled plugin details in View Details get_plugin_by_name() only checked the registry for enabled plugins, causing "Not Found" errors when clicking View Details on disabled plugins. Now falls back to checking config.plugins for disabled plugins, matching the behavior of get_all_plugins(). Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Joe Stein <joe.stein@sscinc.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: hughhennnelly <hughhennelly06@gmail.com>
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
* feat(plugins): add TOON encoder plugin for token-efficient responses Add a tool_post_invoke plugin that converts JSON tool results to TOON (Token-Oriented Object Notation) format, achieving 30-70% token reduction. Features: - Pure Python TOON encoder/decoder per spec v3.0 - Configurable size thresholds and tool filtering - Format markers for downstream parsing - Graceful error handling with skip_on_error fallback - Columnar format for homogeneous object arrays Closes IBM#2574 Signed-off-by: Joe Stein <joe.stein@sscinc.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * lint Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs(toon): document alternative delimiter limitation Add documentation about tab/pipe delimiter limitation in columnar array headers. The TOON spec v3.0 allows alternative delimiters, which our regex matches but decoder doesn't parse correctly (always splits on commas). Document this as a known decoder limitation. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * feat(toon): support tab/pipe delimiters in columnar arrays Add support for alternative delimiters (tab, pipe) in columnar array headers per TOON spec v3.0. The decoder now detects the delimiter from the header and uses it consistently for parsing row values. - Add _detect_delimiter() function to identify delimiter from header - Update _decode_columnar_array() to accept and use delimiter parameter - Update _split_row_values() to split on configurable delimiter - Add tests for pipe and tab delimiter decoding - Remove limitation from README (now fully supported) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(toon): remove unused import and variable - Remove unused Union import (F401) - Remove unused ind variable in _encode_array (F841) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(toon): prefix unused parameters with underscore Silence vulture warnings by prefixing intentionally unused parameters: - _as_root in _encode_array and _encode_object (for API consistency) - _expected_count in _split_row_values (for potential validation) - _context in tool_post_invoke (required by plugin interface) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(admin): return disabled plugin details in View Details get_plugin_by_name() only checked the registry for enabled plugins, causing "Not Found" errors when clicking View Details on disabled plugins. Now falls back to checking config.plugins for disabled plugins, matching the behavior of get_all_plugins(). Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Joe Stein <joe.stein@sscinc.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
TOON Encoder Plugin - Converts JSON tool results to TOON (Token-Oriented Object Notation) format for reduced token consumption when sending responses to LLM agents/GPUs.
Problem
When using MCP Gateway as a proxy for multiple MCP servers (e.g., 10+ servers), the JSON responses from tool invocations consume significant tokens. For users running local inference or paying per-token for API calls, this represents both a performance bottleneck and cost concern.
Solution
A
tool_post_invokeplugin that converts JSON tool results to TOON format before returning to the agent, achieving 30-70% token reduction.Expected Token Savings
Verified Example
Files Added
🏷️ Type of Change
🧪 Verification
make lintmake testmake coveragePlugin-specific tests:
✅ Checklist
make black isort pre-commit)📓 Notes
Design Decisions
Why a Plugin (vs. Core Gateway Change)?
tool_post_invokehook likejson_repair,output_length_guardWhy Pure Python (vs. Rust FFI)?
Safety Features:
skip_on_error: truefallbackannotations.format: "toon") for downstream parsingUsage
Add to
plugins/config.yaml:Agent Integration Required
When enabling TOON encoding, agents must update their system prompts to understand TOON format. See
plugins/toon_encoder/README.mdfor complete system prompt examples.TOON Format Reference
{"name": "alice", "age": 30}name: aliceage: 30[{"id":1},{"id":2}][2]{id}:12["a","b","c"][3]: a,b,cDesign Specification
Full design documentation available at:
specs/toon-encoder/Test Coverage