( content: MCPToolResult, )
| 178 | } |
| 179 | |
| 180 | export async function truncateMcpContent( |
| 181 | content: MCPToolResult, |
| 182 | ): Promise<MCPToolResult> { |
| 183 | if (!content) return content |
| 184 | |
| 185 | const maxChars = getMaxMcpOutputChars() |
| 186 | const truncationMsg = getTruncationMessage() |
| 187 | |
| 188 | if (typeof content === 'string') { |
| 189 | return truncateString(content, maxChars) + truncationMsg |
| 190 | } else { |
| 191 | const truncatedBlocks = await truncateContentBlocks( |
| 192 | content as ContentBlockParam[], |
| 193 | maxChars, |
| 194 | ) |
| 195 | truncatedBlocks.push({ type: 'text', text: truncationMsg }) |
| 196 | return truncatedBlocks |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | export async function truncateMcpContentIfNeeded( |
| 201 | content: MCPToolResult, |
no test coverage detected