mcp-cost-tracker 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -0
  3. package/dist/dashboard/generator.d.ts +54 -0
  4. package/dist/dashboard/generator.d.ts.map +1 -0
  5. package/dist/dashboard/generator.js +577 -0
  6. package/dist/dashboard/generator.js.map +1 -0
  7. package/dist/index.d.ts +12 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +60 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/pricing/models.d.ts +48 -0
  12. package/dist/pricing/models.d.ts.map +1 -0
  13. package/dist/pricing/models.js +207 -0
  14. package/dist/pricing/models.js.map +1 -0
  15. package/dist/storage/database.d.ts +129 -0
  16. package/dist/storage/database.d.ts.map +1 -0
  17. package/dist/storage/database.js +374 -0
  18. package/dist/storage/database.js.map +1 -0
  19. package/dist/tools/index.d.ts +4 -0
  20. package/dist/tools/index.d.ts.map +1 -0
  21. package/dist/tools/index.js +660 -0
  22. package/dist/tools/index.js.map +1 -0
  23. package/dist/tools/prompts.d.ts +3 -0
  24. package/dist/tools/prompts.d.ts.map +1 -0
  25. package/dist/tools/prompts.js +111 -0
  26. package/dist/tools/prompts.js.map +1 -0
  27. package/dist/tools/resources.d.ts +4 -0
  28. package/dist/tools/resources.d.ts.map +1 -0
  29. package/dist/tools/resources.js +138 -0
  30. package/dist/tools/resources.js.map +1 -0
  31. package/dist/utils/helpers.d.ts +29 -0
  32. package/dist/utils/helpers.d.ts.map +1 -0
  33. package/dist/utils/helpers.js +81 -0
  34. package/dist/utils/helpers.js.map +1 -0
  35. package/package.json +52 -0
  36. package/src/dashboard/generator.ts +628 -0
  37. package/src/index.ts +73 -0
  38. package/src/pricing/models.ts +246 -0
  39. package/src/storage/database.ts +525 -0
  40. package/src/tools/index.ts +780 -0
  41. package/src/tools/prompts.ts +124 -0
  42. package/src/tools/resources.ts +171 -0
  43. package/src/utils/helpers.ts +71 -0
  44. package/tsconfig.json +20 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # MCP Cost Tracker
2
+
3
+ **An open-source MCP server that automatically tracks LLM API call costs, token usage, and generates visual dashboards.**
4
+
5
+ [![MCP Server](https://img.shields.io/badge/MCP-Server-blue?style=flat-square)](https://modelcontextprotocol.io/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
8
+
9
+ `mcp-cost-tracker` is a powerful, easy-to-use MCP server designed for developers who want to monitor and control their LLM API spending. It provides a comprehensive suite of tools to track token usage, calculate costs across 50+ models, set budgets, and visualize spending patterns.
10
+
11
+ ![Dashboard Screenshot](https://raw.githubusercontent.com/your-username/mcp-cost-tracker/main/assets/dashboard.png)
12
+ *(This is a placeholder image. A real screenshot will be added after the first release.)*
13
+
14
+ ## ✨ Key Features
15
+
16
+ - **Comprehensive Cost Tracking**: Automatically calculates costs for 50+ models from major providers including OpenAI, Anthropic, Google, DeepSeek, Mistral, and more.
17
+ - **15+ MCP Tools**: A rich set of tools for tracking usage, analyzing costs, setting budgets, comparing models, and exporting data.
18
+ - **Visual Dashboard**: Generate a beautiful, interactive HTML dashboard with charts for daily trends, cost breakdowns by model/provider/project, and top expensive requests.
19
+ - **Budget Management**: Set daily, weekly, or monthly budgets with alerts to prevent cost overruns.
20
+ - **SQLite Persistence**: All usage data is stored locally in a SQLite database, ensuring data ownership and enabling historical analysis.
21
+ - **Easy Integration**: Use as a standalone MCP server with any compatible client (like Claude Desktop) or integrate into your existing applications.
22
+ - **Non-Intrusive**: Designed to work without modifying your existing API call logic.
23
+
24
+ ## 🚀 Getting Started
25
+
26
+ ### Installation
27
+
28
+ ```bash
29
+ npm install -g mcp-cost-tracker
30
+ ```
31
+
32
+ ### Running the Server
33
+
34
+ Simply run the command in your terminal:
35
+
36
+ ```bash
37
+ mcp-cost-tracker
38
+ ```
39
+
40
+ This will start the MCP server, listening on `stdio` for requests from a compatible client.
41
+
42
+ ### Connecting with Claude Desktop
43
+
44
+ 1. Open Claude Desktop settings.
45
+ 2. Go to the "MCP Servers" section.
46
+ 3. Click "Add Server" and choose "From Command".
47
+ 4. Enter `mcp-cost-tracker` as the command.
48
+ 5. Save and enable the server.
49
+
50
+ Now you can use all the cost tracking tools directly within Claude!
51
+
52
+ ## 🛠️ MCP Tools
53
+
54
+ `mcp-cost-tracker` provides a rich set of tools to manage your LLM costs. Here are some of the key tools available:
55
+
56
+ | Tool Name | Description |
57
+ | :--- | :--- |
58
+ | `track_usage` | Record an API call with token counts and automatically calculate its cost. |
59
+ | `get_summary` | Get a summary of total costs, tokens, and request counts, with filters. |
60
+ | `get_cost_by_model` | See a cost breakdown grouped by model to identify top cost drivers. |
61
+ | `get_daily_trend` | View daily cost trends to spot spending patterns. |
62
+ | `set_budget` | Create or update a spending budget with alerts. |
63
+ | `check_budget` | Check the current status of your budgets. |
64
+ | `generate_dashboard` | Generate an interactive HTML dashboard. |
65
+ | `lookup_pricing` | Look up pricing for any supported model. |
66
+ | `estimate_cost` | Estimate the cost of an API call before making it. |
67
+ | `compare_models` | Compare the cost of a workload across different models. |
68
+ | `export_data` | Export usage data to CSV or JSON for external analysis. |
69
+
70
+ For a full list of tools and their arguments, you can use the `tools/list` method from your MCP client.
71
+
72
+ ## 📊 Dashboard
73
+
74
+ To generate the HTML dashboard, use the `generate_dashboard` tool:
75
+
76
+ ```
77
+ > generate_dashboard
78
+ ```
79
+
80
+ This will create a `dashboard.html` file in your `~/.mcp-cost-tracker/` directory. Open this file in your browser to see a detailed visualization of your spending.
81
+
82
+ ## ⚙️ Configuration
83
+
84
+ By default, the database is stored at `~/.mcp-cost-tracker/costs.db`.
85
+
86
+ You can specify a custom database path by setting the `MCP_COST_TRACKER_DB` environment variable:
87
+
88
+ ```bash
89
+ export MCP_COST_TRACKER_DB=/path/to/your/costs.db
90
+ mcp-cost-tracker
91
+ ```
92
+
93
+ ## 🤝 Contributing
94
+
95
+ Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss improvements.
96
+
97
+ ## 📄 License
98
+
99
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,54 @@
1
+ import { CostDatabase } from '../storage/database.js';
2
+ export interface DashboardData {
3
+ summary: {
4
+ total_cost: number;
5
+ total_input_tokens: number;
6
+ total_output_tokens: number;
7
+ total_cached_tokens: number;
8
+ total_requests: number;
9
+ avg_cost_per_request: number;
10
+ };
11
+ costByModel: Array<{
12
+ provider: string;
13
+ model: string;
14
+ total_cost: number;
15
+ total_input_tokens: number;
16
+ total_output_tokens: number;
17
+ request_count: number;
18
+ }>;
19
+ costByProvider: Array<{
20
+ provider: string;
21
+ total_cost: number;
22
+ total_input_tokens: number;
23
+ total_output_tokens: number;
24
+ request_count: number;
25
+ }>;
26
+ costByDay: Array<{
27
+ date: string;
28
+ total_cost: number;
29
+ total_tokens: number;
30
+ request_count: number;
31
+ }>;
32
+ costByProject: Array<{
33
+ project: string;
34
+ total_cost: number;
35
+ total_tokens: number;
36
+ request_count: number;
37
+ }>;
38
+ topExpensive: Array<{
39
+ timestamp: string;
40
+ provider: string;
41
+ model: string;
42
+ total_cost: number;
43
+ total_tokens: number;
44
+ description: string;
45
+ }>;
46
+ generatedAt: string;
47
+ }
48
+ export declare function collectDashboardData(db: CostDatabase, days?: number): DashboardData;
49
+ export declare function generateDashboardHTML(data: DashboardData): string;
50
+ /**
51
+ * Generate a Markdown text report (for terminal / MCP response).
52
+ */
53
+ export declare function generateTextReport(data: DashboardData): string;
54
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/dashboard/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE;QACP,UAAU,EAAE,MAAM,CAAC;QACnB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC;QAC5B,mBAAmB,EAAE,MAAM,CAAC;QAC5B,cAAc,EAAE,MAAM,CAAC;QACvB,oBAAoB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,WAAW,EAAE,KAAK,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC;QAC5B,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,cAA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