feat: provider-wide output compaction/truncation layer for CLI tool results

Ouverte
#105 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 5 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
25/100
Type d'issue
Fonctionnalité
Clarté
À clarifier
Activité
Active
Stack technique
go
Domaine
tooling

Piste de recherche

Start by reading the implementation of k8s_get_resources from #83 and how providers return results through mcp.TextOutput; the issue names internal/commands and mcp.TextResult as possible integration points. Work out how output formats, structured content, configuration, and metrics should fit together. Done means a shared layer reduces oversized provider output safely and clearly reports truncation, with the open design questions resolved.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

enhancement

Summary

#83 (closing #82) adds a limit parameter to k8s_get_resources to cap result size. That fixes one tool, but the underlying problem is general: almost every provider returns raw CLI output (kubectl, helm, istioctl, cilium, argo, kubescape, ...) straight into the model's context via mcp.TextOutput. Large outputs (cluster-wide listings, describe, logs, proxy-config dumps, scan reports) can blow up token usage and exhaust the context window.

Rather than adding ad-hoc limits per tool, we should consider a shared output-reduction layer, inspired by rtk-ai/rtk — a CLI proxy that reduces LLM token consumption by 60–90% on common dev commands by filtering/compacting command output.

Proposal

Add a shared component in internal/ (e.g. alongside internal/commands or as a post-processor applied in mcp.TextResult) that:

  • Truncates safely per format — row-based for tabular output (preserving headers), items-level for JSON, passthrough for formats without a safe cut point (generalizing the approach in #83).
  • Always emits an explicit truncation notice with totals and how to narrow the query, so partial data is never mistaken for complete data.
  • Compacts noisy output — e.g. strip managedFields, last-applied-configuration annotations, empty/default fields, collapse repeated log lines, dedupe events.
  • Is configurable — global defaults via server flags/env/Helm values (e.g. max bytes/rows/tokens), with per-call overrides (limit=0 to disable) where it makes sense.
  • Is observable — metrics for bytes in/out and truncation counts per tool/provider.

Open questions

  • Default on (bounded) vs opt-in? (Same trade-off raised in #83.)
  • Size budget unit: rows, bytes, or estimated tokens?
  • Should per-command filters live in Go code, or be declarative/config-driven like rtk's filters?
  • How does this interact with StructuredContent and output schema validation?

References

Langage dominant
Go
Étoiles
39
Forks
35
Merge moyen
4 j 10 h
PR mergées (30 j)
8

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Aucun modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de kagent-dev/tools

Toutes les issues de kagent-dev/tools

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.