String Utilities

Truncate

Cuts text strings to exact character limits with optional ellipsis indicators. Use via MCP in Cursor or call GET /v1/string/truncate with text and max length parameters. Returns "Hello wo..." for truncating "Hello world" to 8 chars. Handles Unicode properly unlike basic substring operations.

API Endpoint

GET /v1/string/truncate

Code Examples

curl "https://tinyfn.io/v1/string/truncate" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/string/truncate', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/string/truncate',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's string tools:

{
  "mcpServers": {
    "tinyfn-string": {
      "url": "https://tinyfn.io/mcp/string",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I truncate text with ellipsis in MCP tools?

Call the truncate function with your text and desired max_length. Set add_ellipsis=true to append '...' when text is cut, making truncated content visually obvious to users.

Does truncate handle Unicode characters correctly?

Yes, it counts actual characters rather than bytes. Emoji, accented letters, and multi-byte Unicode sequences each count as one character for accurate length calculations.

What happens if text is shorter than the truncate length?

The original text is returned unchanged. No padding or modification occurs when input length is less than or equal to the specified maximum.

Can I truncate without adding ellipsis indicators?

Absolutely. Set add_ellipsis=false or omit the parameter to get clean cuts without '...' suffixes. Useful for strict character limits in databases or APIs.

How does this differ from substring operations in code?

TinyFn's truncate handles Unicode properly, offers ellipsis options, and provides consistent behavior across languages. Basic substring can break on multi-byte characters or produce unexpected results.

Try Truncate Now

Get your free API key and start using Truncate in seconds.

Get Free API Key