truncate_tool_result (mcp/truncate.rs)

jan · src-tauri/src/core/mcp/truncate.rs · rust · Apache-2.0
ai, tag:embed-classified

Truncates MCP tool results to a max character limit, adding a marker.

// Source: https://github.com/janhq/jan | License: Apache-2.0 | Copyright 2025 Menlo Research
// Provided via justclaw.it.com; keep this notice with the code.
//! Size cap for MCP tool results.
//!
//! A tool result is injected verbatim into conversation history, so one call to
//! a tool that dumps a whole page (Jan Browser MCP's snapshot, for instance) can
//! exhaust the model's context on its own, regardless of how large that context
//! is. Everything that hands an MCP result to a model funnels through here first
//! so the payload is bounded and the clipping is announced rather than silent.

use rmcp::model::{CallToolResult, ContentBlock};

/// Total text characters carried by a result, across every text block.
fn total_text_chars(result: &CallToolResult) -> usize {
    result
      

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key