Labsco
adbertram logo

Tiktoken MCP

โ˜… 1

from adbertram

Count tokens using OpenAI's tiktoken library.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

tiktoken-mcp

An MCP (Model Context Protocol) server that provides token counting functionality using OpenAI's tiktoken library.

Features

  • ๐Ÿ”ข Token Counting: Count tokens for any text using various tiktoken encodings
  • ๐Ÿ’ฐ Cost Estimation: Estimate token costs for popular AI models (GPT-4, Claude, etc.)
  • ๐Ÿš€ Easy to Use: Run directly with npx - no installation required
  • ๐Ÿ”ง Claude Desktop Integration: Seamlessly integrates with Claude Desktop app

Available Tools

count_tokens

Count tokens in text using various tiktoken encodings.

Parameters:

  • text (required): The text to count tokens for
  • model (optional): The encoding model to use. Options: 'cl100k_base' (default), 'p50k_base', 'p50k_edit', 'r50k_base'

estimate_cost

Estimate token costs for various AI models.

Parameters:

  • text (required): The text to estimate cost for
  • model (required): The model to estimate cost for. Options: 'gpt-4', 'gpt-4-turbo', 'gpt-3.5-turbo', 'claude-3-opus', 'claude-3-sonnet', 'claude-3-haiku'

How It Works

This MCP server uses Python's tiktoken library under the hood to accurately count tokens. It supports multiple encoding models:

  • cl100k_base: Used by GPT-4, GPT-3.5-turbo, and newer models
  • p50k_base: Used by Codex models
  • p50k_edit: Used by edit models
  • r50k_base: Used by GPT-3 models

Issues

If you encounter any problems, please file an issue on the GitHub repository.