@ccusage/mcp
Model Context Protocol (MCP) server implementation for ccusage - provides Claude Code usage data through the MCP protocol for real-time integration with Claude Desktop and other MCP-compatible tools.Quick Start
What is MCP?
The Model Context Protocol is an open standard that enables AI applications to securely access external data sources and tools. The@ccusage/mcp server exposes ccusage data and functionality through this protocol.
Installation
Claude Desktop Integration
Add to your Claude Desktop MCP configuration file: macOS:~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%/Claude/claude_desktop_config.json
Claude Code Integration
Add the MCP server to Claude Code:Available Tools
Once configured, the following tools become available in Claude Desktop:daily
Get daily usage reports with token counts and costs
monthly
Get monthly aggregated usage reports
session
Get session-based usage reports grouped by conversation
blocks
Get 5-hour billing blocks usage reports
Usage in Claude Desktop
Once configured, you can ask Claude Desktop questions like:- “Show me my Claude Code usage from last week”
- “What are my total costs for this month?”
- “Which models did I use yesterday?”
- “Show my most expensive conversation sessions”
Transport Options
The MCP server supports multiple transport protocols:STDIO Transport (Default)
Used for Claude Desktop integration:HTTP Transport
For web-based integrations:--type http- Enable HTTP transport--port <number>- Specify port (default: 3000)--host <string>- Specify host (default: localhost)
Features
Real-time Data
Access current usage data directly from Claude Desktop
Multiple Reports
Daily, monthly, session, and blocks reports available
Secure Access
Local data access with no external API calls required
Standard Protocol
Uses open MCP standard for broad compatibility
Data Source
The MCP server reads from the same data sources as the ccusage CLI:- Claude Code:
~/.claude/projects/or~/.config/claude/projects/ - Supports custom paths via
CLAUDE_CONFIG_DIRenvironment variable - Automatic discovery of both old and new Claude data directories
Example Queries
Here are some example questions you can ask Claude Desktop:Cost Analysis
“What were my Claude Code costs last month?”Claude will use the
monthly tool to fetch and display your monthly usage.
Model Usage
“Which Claude models did I use this week?”Claude will use the
daily tool with date filters to show model usage.
Session Breakdown
“Show me my most expensive conversation sessions”Claude will use the
session tool to list sessions sorted by cost.
Billing Windows
“Am I close to my 5-hour block limit?”Claude will use the
blocks tool to show your current billing window usage.
Configuration
The MCP server respects the same environment variables as ccusage:| Variable | Description | Default |
|---|---|---|
CLAUDE_CONFIG_DIR | Custom Claude data directory paths | ~/.claude,~/.config/claude |
LOG_LEVEL | Control logging verbosity (0-5) | - |
Troubleshooting
Server Not Appearing in Claude Desktop
- Check your config file syntax is valid JSON
- Ensure the path to
claude_desktop_config.jsonis correct - Restart Claude Desktop after making changes
- Check the Claude Desktop logs for errors
Permission Issues
- Ensure the MCP server has read access to your Claude data directories
- On macOS/Linux, check file permissions with
ls -la ~/.claude/
Connection Errors
For HTTP transport:- Verify the port is not already in use
- Check firewall settings allow the connection
- Try a different port with
--portflag
Architecture
The MCP server is built with:- @hono/mcp - MCP implementation for Hono
- @modelcontextprotocol/sdk - Official MCP SDK
- Hono - Fast, lightweight web framework
- ccusage - Core usage analysis functionality
Links
npm Package
View on npm registry
MCP Specification
Learn about Model Context Protocol
ccusage Family
Explore all related tools
Claude Desktop
Download Claude Desktop