Token Analyzer MCP

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.

Category
Visit Server

README

Token Analyzer MCP

CI/CD Pipeline npm version License: MIT

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 analysis
  • analyzeTokenImpact(servers): Measure token consumption
  • analyzeIncrementalImpact(tokens): Calculate cumulative impact
  • generateRecommendations(analysis): Create optimization suggestions

TokenMeasurementEngine

  • countServerTokens(server): Analyze individual server tokens
  • analyzeSchemaComplexity(schema): Calculate complexity metrics
  • measureBaselineTokens(): Get built-in tool overhead
  • calculateTotalOverhead(servers): Compute total token usage

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes with tests
  4. Run the test suite: npm test
  5. 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!

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured