Token Analyzer MCP
Provides intelligent analysis of token usage patterns and optimization recommendations to improve efficiency and reduce costs in Claude Code sessions. Offers real-time analysis, cost metrics, and actionable insights for better context window and tool usage optimization.
README
Token Analyzer MCP
Precise token counting and context efficiency analysis for MCP (Model Context Protocol) servers. Optimize your Claude Code setup by analyzing token consumption and identifying optimization opportunities.
Features
🔍 Comprehensive Token Analysis
- Real-time MCP Server Scanning: Automatically discovers and analyzes all configured MCP servers
- Incremental Impact Analysis: Shows how each server affects your total token budget
- Schema Complexity Measurement: Analyzes tool definitions for optimization opportunities
- Context Window Optimization: Tracks usage against 200k token context limit
📊 Multiple Analysis Modes
- Full Analysis: Complete token breakdown with detailed recommendations
- Quick Estimation: Fast overhead estimation without server connections
- Configuration Audit: Validate MCP setup and server accessibility
- Health Check: Verify analyzer dependencies and permissions
🎯 Optimization Intelligence
- Scenario Planning: Compare "what-if" optimization scenarios
- Smart Recommendations: Prioritized suggestions based on impact analysis
- Complexity Scoring: Identify overly complex tool schemas
- Usage Pattern Detection: Find verbose descriptions and optimization opportunities
📈 Professional Reporting
- Multi-format Export: JSON, CSV, and formatted text reports
- Visual Context Tracking: Color-coded overhead warnings
- Incremental Impact Tables: Step-by-step token accumulation analysis
- Executive Summaries: Quick overview for decision making
Installation
npm install -g token-analyzer-mcp
Quick Start
Analyze Your Current Setup
# Complete analysis with recommendations
token-analyzer-mcp analyze
# Quick overhead estimation
token-analyzer-mcp quick
# Check MCP configuration
token-analyzer-mcp config
# Verify analyzer setup
token-analyzer-mcp doctor
Export Detailed Results
# Save complete analysis to files
token-analyzer-mcp analyze \
--output analysis.json \
--report report.txt \
--csv data.csv
Usage Examples
Basic Analysis
$ token-analyzer-mcp analyze
🔍 MCP Token Analyzer v1.0.0
Analyzing MCP server token consumption...
📋 Phase 1: Analyzing MCP Configuration
✅ Found 8 servers in ~/.claude/claude_desktop_config.json
✅ 6 active servers to analyze
🔌 Phase 2: Extracting Server Schemas
✅ document-organizer: 12 tools extracted
✅ conversation-search: 15 tools extracted
✅ claude-telemetry: 8 tools extracted
🔢 Phase 3: Measuring Token Impact
✅ Token analysis complete
📊 Phase 4: Incremental Impact Analysis
✅ Incremental analysis complete
Configuration Check
$ token-analyzer-mcp config
📋 MCP Configuration Analysis
✅ Configuration found: ~/.claude/claude_desktop_config.json
Total servers: 8
Configured Servers:
• document-organizer (mcpServers) - ACTIVE
• conversation-search (mcpServers) - ACTIVE
• claude-telemetry (mcpServers) - ACTIVE
• playwright (mcpServers) - DISABLED
Analysis Results
Token Usage Overview
┌─────────────────┬────────────┬────────────┐
│ Component │ Tokens │ Percentage │
├─────────────────┼────────────┼────────────┤
│ Built-in Tools │ 2,250 │ 1.13% │
│ MCP Servers │ 8,540 │ 4.27% │
│ Total Overhead │ 10,790 │ 5.40% │
│ Available │ 189,210 │ 94.60% │
└─────────────────┴────────────┴────────────┘
Incremental Impact Analysis
┌──────┬────────────────────┬─────────┬───────┬──────────────┐
│ Step │ Server │ Tokens │ Tools │ Cumulative % │
├──────┼────────────────────┼─────────┼───────┼──────────────┤
│ 1 │ document-organizer │ 3,240 │ 12 │ 2.75% │
│ 2 │ conversation-search│ 2,890 │ 15 │ 4.19% │
│ 3 │ claude-telemetry │ 1,860 │ 8 │ 5.12% │
│ 4 │ github-integration │ 550 │ 6 │ 5.40% │
└──────┴────────────────────┴─────────┴───────┴──────────────┘
Configuration Requirements
The analyzer automatically discovers MCP configurations from standard locations:
~/.claude/claude_desktop_config.json~/.config/claude-desktop/claude_desktop_config.json- Windows:
%APPDATA%/Claude/claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Supported Configuration Formats
{
"mcpServers": {
"document-organizer": {
"command": "document-organizer-mcp",
"args": [],
"disabled": false
}
}
}
Optimization Recommendations
The analyzer provides actionable recommendations:
High Priority
- Token Overhead > 10%: Consider lazy loading or server reduction
- Complex Schemas: Simplify tool definitions or break into smaller tools
- Heavy Servers: Review servers consuming >2000 tokens
Medium Priority
- Verbose Descriptions: Reduce description length while maintaining clarity
- Unused Tools: Disable servers with low utilization
- Schema Optimization: Flatten nested object structures
Low Priority
- Naming Conventions: Use shorter but descriptive tool names
- Documentation: Add examples instead of lengthy descriptions
Advanced Features
Scenario Analysis
Compare optimization scenarios:
- Current Configuration: Baseline token usage
- Without Heaviest Server: Impact of removing the largest consumer
- Top 3 Only: Keep only the most valuable servers
- 50% Optimized: Simulated optimization results
Export Options
# Detailed JSON for integration
token-analyzer-mcp analyze --output detailed.json
# CSV for spreadsheet analysis
token-analyzer-mcp analyze --csv servers.csv
# Formatted report for documentation
token-analyzer-mcp analyze --report optimization-plan.txt
Programmatic Usage
import { IncrementalImpactAnalyzer } from 'token-analyzer-mcp';
const analyzer = new IncrementalImpactAnalyzer();
const results = await analyzer.performCompleteAnalysis();
console.log(`Total overhead: ${results.tokens.totalOverhead.overheadPercentage}%`);
Performance Considerations
- Connection Timeout: 10 seconds per server (configurable)
- Retry Logic: Up to 2 retry attempts for failed connections
- Memory Usage: Minimal overhead, designed for continuous monitoring
- Caching: Results can be cached for comparison over time
Troubleshooting
Common Issues
No MCP configuration found
# Check configuration locations
token-analyzer-mcp doctor
# Verify file permissions
ls -la ~/.claude/claude_desktop_config.json
Server connection failures
# Test individual server
node /path/to/server/index.js
# Check server logs
token-analyzer-mcp analyze --debug
High token consumption
# Identify heavy servers
token-analyzer-mcp analyze --summary
# Get optimization recommendations
token-analyzer-mcp analyze --report optimization.txt
Development
# Clone repository
git clone https://github.com/cordlesssteve/token-analyzer-mcp.git
cd token-analyzer-mcp
# Install dependencies
npm install
# Run tests
npm test
# Run analyzer locally
node src/index.js analyze
Architecture
src/
├── index.js # CLI interface
├── IncrementalImpactAnalyzer.js # Main analysis engine
├── TokenMeasurementEngine.js # Token counting logic
├── MCPConfigurationAnalyzer.js # Configuration discovery
├── MCPSchemaExtractor.js # Server schema extraction
└── ReportGenerator.js # Report formatting
API Reference
IncrementalImpactAnalyzer
performCompleteAnalysis(): Execute full token analysisanalyzeTokenImpact(servers): Measure token consumptionanalyzeIncrementalImpact(tokens): Calculate cumulative impactgenerateRecommendations(analysis): Create optimization suggestions
TokenMeasurementEngine
countServerTokens(server): Analyze individual server tokensanalyzeSchemaComplexity(schema): Calculate complexity metricsmeasureBaselineTokens(): Get built-in tool overheadcalculateTotalOverhead(servers): Compute total token usage
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes with tests
- Run the test suite:
npm test - Submit a pull request
Guidelines
- Follow existing code style
- Add tests for new features
- Update documentation
- Ensure backward compatibility
License
MIT License - see LICENSE file for details.
Support
Optimize your Claude Code setup with precise token analysis!
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。