Skip to content

feat(tools): compress tool schemas and truncate descriptions#110

Open
juslintek wants to merge 1 commit intojwadow:mainfrom
juslintek:feat/compress-tool-schemas
Open

feat(tools): compress tool schemas and truncate descriptions#110
juslintek wants to merge 1 commit intojwadow:mainfrom
juslintek:feat/compress-tool-schemas

Conversation

@juslintek
Copy link
Copy Markdown

What

Adds opt-in tool schema compression and description truncation to reduce token usage when many MCP tools are present.

Why

Claude Code with MCP servers can send 100+ tools per request. Each tool's JSON Schema includes verbose fields (description, title, examples, $comment, markdownDescription) that consume context window tokens but aren't needed for tool call generation. With 134 tools observed in live traffic, this saves thousands of tokens per request.

How

compress_json_schema() recursively strips verbose fields from JSON Schema properties, keeping only structural fields (type, properties, required, enum, items, etc.).

Long tool descriptions are also truncated to a configurable limit.

Changes

  • config.py: Add KIRO_COMPRESS_TOOL_SCHEMAS (default: true) and KIRO_TOOL_DESC_MAX_CHARS (default: 200)
  • converters_core.py: Add compress_json_schema() function, integrate into convert_tools_to_kiro_format()

Config

# Enable/disable schema compression (default: true)
KIRO_COMPRESS_TOOL_SCHEMAS=true

# Max description length, 0 to disable (default: 200)
KIRO_TOOL_DESC_MAX_CHARS=200

Testing

All 1413 existing tests pass. No dependencies on other PRs — this is independent.

Adds opt-in tool schema compression to reduce token usage when many
MCP tools are present. With 100+ tools (common with Claude Code),
stripping verbose schema fields saves significant context window space.

compress_json_schema() recursively strips: description, title, examples,
$comment, markdownDescription from JSON Schema properties — keeping only
structural fields needed for tool call generation.

Long tool descriptions are also truncated to a configurable limit.

Config:
- KIRO_COMPRESS_TOOL_SCHEMAS=true (default) — enable schema compression
- KIRO_TOOL_DESC_MAX_CHARS=200 (default) — max description length (0=disable)
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 21, 2026

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@juslintek
Copy link
Copy Markdown
Author

I have read the CLA and I accept its terms

@kosuke-zhang
Copy link
Copy Markdown

I have read the CLA and I accept its terms

Author has been inactive for a long time... Could you fork this repo and maintain it?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants