export function countTokens(text: string): number {
// Normalize whitespace (convert tabs and newlines to spaces)
const normalized = text
.replace(/\s+/g, ' ') // Replace multiple whitespace with a single space
.replace(/[\n\t]/g, ' ') // Replace newlines and tabs with a space
.trim();
// Split into words and individual symbols
const tokens = normalized.match(/\w+|[^\s\w]/g);
// Return the number of tokens
return tokens ? tokens.length : 0;
}
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/nulab/backlog-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server