Skip to main content
Glama
tanamurayuuki

Gemini URL Context & Search MCP Server

TextTrimmer.ts1.31 kB
export class TextTrimmer { private static readonly ELLIPSIS = '...'; static trim(text: string, maxChars: number): string { if (maxChars <= 0) { throw new Error('maxChars must be greater than 0'); } if (text.length <= maxChars) { return text; } const availableChars = maxChars - TextTrimmer.ELLIPSIS.length; if (availableChars <= 0) { return TextTrimmer.ELLIPSIS.substring(0, maxChars); } return text.substring(0, availableChars) + TextTrimmer.ELLIPSIS; } static trimAtWordBoundary(text: string, maxChars: number): string { if (maxChars <= 0) { throw new Error('maxChars must be greater than 0'); } if (text.length <= maxChars) { return text; } const availableChars = maxChars - TextTrimmer.ELLIPSIS.length; if (availableChars <= 0) { return TextTrimmer.ELLIPSIS.substring(0, maxChars); } // Find the last word boundary within the available characters const truncated = text.substring(0, availableChars); const lastSpaceIndex = truncated.lastIndexOf(' '); if (lastSpaceIndex > 0) { return truncated.substring(0, lastSpaceIndex) + TextTrimmer.ELLIPSIS; } // If no space found, fall back to character truncation return truncated + TextTrimmer.ELLIPSIS; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tanamurayuuki/MCP-URLcontext'

If you have feedback or need assistance with the MCP directory API, please join our Discord server