AI Token Cost Optimization MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AI Token Cost Optimization MCP Servercount tokens in 'What is the capital of France?' for gpt-4o"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
AI Token Cost Optimization — MCP Server
A production-ready Model Context Protocol (MCP) server that provides 4 tools to count tokens, estimate API costs, optimize prompts, and compare AI model pricing. Compatible with Cline, Claude Desktop, and any MCP-compatible client.
Tools Overview
Tool | Description |
count_tokens | Count tokens in any text for GPT-4o, GPT-4o-mini, Claude 3.5 Sonnet, Claude 3.5 Haiku, or Gemini 1.5 Flash. Includes cost estimation. |
estimate_cost | Estimate the full API call cost: input cost + output cost. Supports USD and INR. |
optimize_prompt | Analyze a prompt and get suggestions to reduce token usage. Also recommends the cheapest model for your text. |
compare_models | Compare all 5 models side-by-side for your prompt, sorted from cheapest to most expensive. |
Related MCP server: ohmytoken
Project Structure
my-mcp-server/
├── src/
│ ├── index.ts # MCP server (4 tools)
│ ├── types.ts # TypeScript interfaces
│ ├── pricing.ts # Model pricing data (USD/INR)
│ └── tokenizer.ts # Token counting (gpt-tokenizer o200k_base)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── README.md # This file
└── DOCUMENTATION.md # Full process documentationPrerequisites
Node.js v18 or higher
npm (comes with Node.js)
Quick Start
# Navigate to the project directory
cd C:\Users\ghosh\Documents\MSS\my-mcp-server
# Install dependencies
npm install
# Run in development mode
npm run devUsage
Development Mode (hot-reload with tsx)
npm run devDevelopment Mode (with auto-reload)
npm run dev:watchProduction Mode
npm run build # Compile TypeScript to dist/
npm start # Run compiled versionTypeScript Type-Check
npx tsc --noEmitTesting the Server
Option 1: MCP Inspector (Recommended)
npx @modelcontextprotocol/inspector npx tsx src/index.tsOpens a web UI at http://localhost:5173 — browse tools, call them, see responses.
Option 2: Quick Command-Line Test
Test all 4 tools in one command:
cd C:\Users\ghosh\Documents\MSS\my-mcp-server
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"count_tokens","arguments":{"text":"Hello World!","model":"gpt-4o"}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"compare_models","arguments":{"prompt":"Hello","estimated_output_tokens":100}}}' | npx tsx src/index.ts 2>/dev/nullCline Configuration
Add to your Cline MCP settings:
{
"mcpServers": {
"hello-world": {
"command": "npx",
"args": [
"tsx",
"C:\\Users\\ghosh\\Documents\\MSS\\my-mcp-server\\src\\index.ts"
]
}
}
}macOS/Linux: Use forward slashes:
"/Users/ghosh/Documents/MSS/my-mcp-server/src/index.ts"
Tool Details
count_tokens
Parameters:
Field | Type | Required | Description |
| string | ✅ | The text to count tokens for |
| string | ✅ | gpt-4o, gpt-4o-mini, claude-3.5-sonnet, claude-3.5-haiku, gemini-1.5-flash |
| string | ❌ | USD (default) or INR |
Example response:
{
"model": "gpt-4o",
"token_count": 7,
"character_count": 31,
"tokenizer": "OpenAI o200k_base (via gpt-tokenizer) — exact",
"estimated_input_cost": "$0.000018",
"currency": "USD"
}estimate_cost
Parameters:
Field | Type | Required | Description |
| string | ✅ | The input prompt text |
| number | ❌ | Default: 500 |
| string | ✅ | Model identifier |
| string | ❌ | USD (default) or INR |
Example response:
{
"model": "gpt-4o",
"provider": "OpenAI",
"input_tokens": 6,
"output_tokens": 200,
"input_cost": "$0.000015",
"output_cost": "$0.002000",
"total_cost": "$0.002015",
"currency": "USD"
}optimize_prompt
Parameters:
Field | Type | Required | Description |
| string | ✅ | The prompt to analyze |
| string | ✅ | Model identifier |
Example response:
{
"original_token_count": 15,
"character_count": 62,
"suggested_improvements": [
{ "suggestion": "Replace verbose phrases...", "estimated_savings_percent": 5 },
{ "suggestion": "Consider using GPT-4o-mini...", "estimated_savings_percent": 60 }
],
"best_model_recommendation": "Switch to gpt-4o-mini for ~60% cost savings."
}compare_models
Parameters:
Field | Type | Required | Description |
| string | ✅ | The input prompt text |
| number | ❌ | Default: 500 |
| string | ❌ | USD (default) or INR |
Example response:
{
"prompt_character_count": 11,
"estimated_output_tokens": 100,
"currency": "USD",
"comparisons": [
{ "model": "gpt-4o-mini", "total_cost": "$0.000060" },
{ "model": "claude-3.5-haiku", "total_cost": "$0.000503" }
],
"summary": {
"cheapest": "gpt-4o-mini",
"most_expensive": "claude-3.5-sonnet"
}
}Supported Models & Pricing
Model | Provider | Input (per 1K tokens) | Output (per 1K tokens) |
GPT-4o | OpenAI | $0.00250 | $0.01000 |
GPT-4o-mini | OpenAI | $0.00015 | $0.00060 |
Claude 3.5 Sonnet | Anthropic | $0.00300 | $0.01500 |
Claude 3.5 Haiku | Anthropic | $0.00100 | $0.00500 |
Gemini 1.5 Flash | $0.00150 | $0.00900 |
Technical Details
Field | Value |
SDK |
|
Token Counting |
|
Transport |
|
Module System | ES Modules ( |
Runtime | Node.js >= 18 |
Dev Runner |
|
Example Cline Prompts
After connecting the server, try asking Cline:
"Count the tokens in 'Hello World from my MCP Server!' using GPT-4o"
"Estimate the cost of sending a 100-token prompt with 500 output tokens on Claude 3.5 Sonnet in INR"
"Which is the cheapest model for this prompt: 'Write a poem about artificial intelligence' with 200 output tokens?"
"Analyze this prompt for optimization: 'I would like you to please write a detailed report'"
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/SujanGhosh2002/my-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server