feat(mcp): add compact description mode to reduce context token overhead#2853
feat(mcp): add compact description mode to reduce context token overhead#2853lg320531124 wants to merge 2 commits into
Conversation
Add OPENVIKING_MCP_DESCRIPTION_MODE environment variable: - 'full' (default): no change, full docstrings exposed as tool descriptions - 'compact': truncate each tool description to the first sentence When 15 MCP tools are exposed, their combined descriptions consume ~200-400 context tokens per turn. Compact mode reduces this by 33-60% by keeping only the first sentence of each docstring. Implementation wraps the @mcp.tool decorator to auto-compact descriptions at registration time. No changes to individual tool functions. Set via: OPENVIKING_MCP_DESCRIPTION_MODE=compact ov serve Fixes volcengine#2849
|
looks okay, @t0saki pls check for effect changes. (first line should be the one-liner doc in code. but i don't see multi-line in docs, probably schemas?) if lost schema would that affect MCP server's behavior and result in another round of tool usage search |
|
Thanks for the review @ZaynJarvis! Re: "first line should be the one-liner doc" — Agreed. The current docstrings follow Python convention (one-line summary + blank line + details), so Re: "if lost schema would that affect MCP server behavior and result in another round of tool usage search" — Good concern. Two points:
That said, if you prefer a more conservative approach, I can change the truncation to keep the first paragraph (up to |
|
I think 6k total tokens is acceptable, but I do agree some tools desc can be compressed, especially add_resource and code series. I worry the results will deteriorate, hope we can shorten the description length of add_resource and the code series (can make direct changes, no need an extra configuration). |
…escriptions Instead of OPENVIKING_MCP_DESCRIPTION_MODE=compact config switch, directly shorten tool descriptions that were unnecessarily verbose. Add_resource dropped from 2120→191 chars, code_search 824→247, code_outline 610→158, code_expand 432→155, forget 348→118. Total description chars: ~4700→2078 (56% reduction). Per @t0saki review feedback on volcengine#2853.
|
@t0saki — good point, agree that a config switch is over-engineering for this. Rewrote in 8f1d5b1:
No env var, no config — just shorter descriptions. |
Problem
OpenViking MCP server exposes 15 tools whose
descriptiondocstrings are injected into the LLM context on every turn. These descriptions total ~6000 chars (~1500 tokens), consuming context budget even when the model only needs 2-3 tools per turn.Fix
Add a
compactdescription mode that truncates each tool description to its first sentence. Controlled viaOPENVIKING_MCP_DESCRIPTION_MODEenv var:full(default)compactSavings
findsearchreadlsrememberadd_resourcelist_watchescancel_watchgrepglobforgetcode_outlinecode_searchcode_expandhealthUsage
Implementation
Wraps
mcp.tooldecorator to auto-compactfn.__doc__before registration. Zero changes to tool logic — only affects the description string passed to the MCP schema.Fixes #2849