Skip to content

Commit 2fcd9cf

Browse files
author
Lasim
committed
feat(all): implemented token usage statistics
1 parent da6a24e commit 2fcd9cf

File tree

30 files changed

+2299
-341
lines changed

30 files changed

+2299
-341
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ VS Code → HTTPS Request → DeployStack Satellite → MCP Server Process → E
207207
- **[Done]** Global Event Bus System - event-driven architecture with plugin integration
208208
- **[Done]** Three-Tier MCP Configuration Architecture - complete database schema redesign separating template, team, and user-level configurations
209209
- **[Done]** Multi-User Configuration Management - support for multiple users within teams, each with personalized device-specific configurations
210-
- **[Done]** Advanced MCP Argument & Environment Variable Handling - comprehensive service layer with schema validation and runtime configuration assembly
210+
- **[Done]** Advanced MCP Argument & Environment Variable Handling - complete service layer with schema validation and runtime configuration assembly
211211
- **[Done]** HTTP Headers & URL Query Parameters Support - three-tier configuration for HTTP/SSE transport with intelligent URL parsing, automatic secret detection, and transport type validation
212212
- **[Done]** Selective Secret Masking in Satellite Logs - backend sends secret metadata to satellites for selective masking of sensitive query parameters, headers, and environment variables in logs (first 3 chars + *****), preventing credential exposure in log files and monitoring systems
213213

@@ -237,7 +237,7 @@ VS Code → HTTPS Request → DeployStack Satellite → MCP Server Process → E
237237
- **[Done]** **Performance Benchmarks** - achieved 99.5% token reduction (exceeded 90%+ target): 2 meta-tools (350 tokens) vs 150 tools (75,000 tokens)
238238
- **[Done]** **MCP Tool Metadata Collection** - automatic tool discovery with token counting, event-driven metadata sync from satellites to backend, per-installation tool storage with descriptions and input schemas
239239
- **[Done]** **Tool Display & Analytics API** - team-aware endpoints for fetching tool lists per installation and aggregated token savings across all team installations
240-
- **[To Do]** **Token Analytics Dashboard** - real-time monitoring UI of context window usage with before/after comparisons
240+
- **[Done]** **Token Analytics Dashboard** - complete statistics dashboard with visual token comparison (stacked bar chart), 4 summary cards (installations, tools, savings %, DeployStack usage), side-by-side traditional vs hierarchical comparison, and expandable installation breakdown table with per-tool token counts
241241
- **[To Do]** **Optimization Recommendations** - suggest which servers to disable based on usage patterns
242242
- **[To Do]** **Documentation & Case Study** - technical deep-dive blog post with real-world metrics
243243

package-lock.json

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/backend/api-spec.json

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11990,6 +11990,273 @@
1199011990
}
1199111991
}
1199211992
},
11993+
"/api/teams/{teamId}/mcp/tools/stats": {
11994+
"get": {
11995+
"summary": "Get team MCP tools statistics",
11996+
"tags": [
11997+
"MCP Tools"
11998+
],
11999+
"description": "Retrieves aggregated statistics for all MCP tool installations in a team, including token consumption analysis and hierarchical routing savings calculations. Shows the value of DeployStack's hierarchical router vs traditional MCP tool exposure. Requires mcp.tools.stats.view permission.",
12000+
"parameters": [
12001+
{
12002+
"schema": {
12003+
"type": "string",
12004+
"minLength": 1
12005+
},
12006+
"in": "path",
12007+
"name": "teamId",
12008+
"required": true,
12009+
"description": "Team ID"
12010+
}
12011+
],
12012+
"security": [
12013+
{
12014+
"cookieAuth": []
12015+
}
12016+
],
12017+
"responses": {
12018+
"200": {
12019+
"description": "Statistics retrieved successfully",
12020+
"content": {
12021+
"application/json": {
12022+
"schema": {
12023+
"type": "object",
12024+
"properties": {
12025+
"success": {
12026+
"type": "boolean",
12027+
"description": "Indicates if the operation was successful"
12028+
},
12029+
"data": {
12030+
"type": "object",
12031+
"properties": {
12032+
"team_id": {
12033+
"type": "string",
12034+
"description": "Team identifier"
12035+
},
12036+
"total_installations": {
12037+
"type": "number",
12038+
"description": "Total number of installations with discovered tools"
12039+
},
12040+
"total_tools": {
12041+
"type": "number",
12042+
"description": "Total number of tools across all installations"
12043+
},
12044+
"total_tokens": {
12045+
"type": "number",
12046+
"description": "Total tokens consumed across all tools"
12047+
},
12048+
"traditional_approach": {
12049+
"type": "object",
12050+
"properties": {
12051+
"total_tools": {
12052+
"type": "number",
12053+
"description": "Total number of tools exposed directly to LLM"
12054+
},
12055+
"total_tokens": {
12056+
"type": "number",
12057+
"description": "Total tokens consumed when exposing all tools"
12058+
},
12059+
"context_window_utilization_percent": {
12060+
"type": "number",
12061+
"description": "Percentage of context window consumed"
12062+
}
12063+
},
12064+
"required": [
12065+
"total_tools",
12066+
"total_tokens",
12067+
"context_window_utilization_percent"
12068+
]
12069+
},
12070+
"hierarchical_approach": {
12071+
"type": "object",
12072+
"properties": {
12073+
"exposed_tools": {
12074+
"type": "number",
12075+
"description": "Number of meta-tools exposed (always 2)",
12076+
"default": 2
12077+
},
12078+
"total_tokens": {
12079+
"type": "number",
12080+
"description": "Total tokens consumed by hierarchical router (always 1372)",
12081+
"default": 1372
12082+
},
12083+
"context_window_utilization_percent": {
12084+
"type": "number",
12085+
"description": "Percentage of context window consumed"
12086+
}
12087+
},
12088+
"required": [
12089+
"exposed_tools",
12090+
"total_tokens",
12091+
"context_window_utilization_percent"
12092+
]
12093+
},
12094+
"savings": {
12095+
"type": "object",
12096+
"properties": {
12097+
"tokens_saved": {
12098+
"type": "number",
12099+
"description": "Number of tokens saved by using hierarchical routing"
12100+
},
12101+
"reduction_percent": {
12102+
"type": "number",
12103+
"description": "Percentage reduction in token consumption"
12104+
}
12105+
},
12106+
"required": [
12107+
"tokens_saved",
12108+
"reduction_percent"
12109+
]
12110+
},
12111+
"installations": {
12112+
"type": "array",
12113+
"items": {
12114+
"type": "object",
12115+
"properties": {
12116+
"installation_id": {
12117+
"type": "string",
12118+
"description": "Installation unique identifier"
12119+
},
12120+
"installation_name": {
12121+
"type": "string",
12122+
"description": "Installation name"
12123+
},
12124+
"server_slug": {
12125+
"type": "string",
12126+
"description": "MCP server slug"
12127+
},
12128+
"server_name": {
12129+
"type": "string",
12130+
"description": "MCP server name"
12131+
},
12132+
"tool_count": {
12133+
"type": "number",
12134+
"description": "Number of tools in this installation"
12135+
},
12136+
"total_tokens": {
12137+
"type": "number",
12138+
"description": "Total tokens consumed by all tools in this installation"
12139+
},
12140+
"average_tokens_per_tool": {
12141+
"type": "number",
12142+
"description": "Average tokens per tool"
12143+
}
12144+
},
12145+
"required": [
12146+
"installation_id",
12147+
"installation_name",
12148+
"server_slug",
12149+
"server_name",
12150+
"tool_count",
12151+
"total_tokens",
12152+
"average_tokens_per_tool"
12153+
]
12154+
},
12155+
"description": "Breakdown by installation"
12156+
}
12157+
},
12158+
"required": [
12159+
"team_id",
12160+
"total_installations",
12161+
"total_tools",
12162+
"total_tokens",
12163+
"traditional_approach",
12164+
"hierarchical_approach",
12165+
"savings",
12166+
"installations"
12167+
]
12168+
}
12169+
},
12170+
"required": [
12171+
"success",
12172+
"data"
12173+
],
12174+
"description": "Statistics retrieved successfully"
12175+
}
12176+
}
12177+
}
12178+
},
12179+
"401": {
12180+
"description": "Unauthorized - Authentication required",
12181+
"content": {
12182+
"application/json": {
12183+
"schema": {
12184+
"type": "object",
12185+
"properties": {
12186+
"success": {
12187+
"type": "boolean",
12188+
"default": false,
12189+
"description": "Indicates failure"
12190+
},
12191+
"error": {
12192+
"type": "string",
12193+
"description": "Error message detailing what went wrong"
12194+
}
12195+
},
12196+
"required": [
12197+
"success",
12198+
"error"
12199+
],
12200+
"description": "Unauthorized - Authentication required"
12201+
}
12202+
}
12203+
}
12204+
},
12205+
"403": {
12206+
"description": "Forbidden - Insufficient permissions or not a team member",
12207+
"content": {
12208+
"application/json": {
12209+
"schema": {
12210+
"type": "object",
12211+
"properties": {
12212+
"success": {
12213+
"type": "boolean",
12214+
"default": false,
12215+
"description": "Indicates failure"
12216+
},
12217+
"error": {
12218+
"type": "string",
12219+
"description": "Error message detailing what went wrong"
12220+
}
12221+
},
12222+
"required": [
12223+
"success",
12224+
"error"
12225+
],
12226+
"description": "Forbidden - Insufficient permissions or not a team member"
12227+
}
12228+
}
12229+
}
12230+
},
12231+
"500": {
12232+
"description": "Internal Server Error",
12233+
"content": {
12234+
"application/json": {
12235+
"schema": {
12236+
"type": "object",
12237+
"properties": {
12238+
"success": {
12239+
"type": "boolean",
12240+
"default": false,
12241+
"description": "Indicates failure"
12242+
},
12243+
"error": {
12244+
"type": "string",
12245+
"description": "Error message detailing what went wrong"
12246+
}
12247+
},
12248+
"required": [
12249+
"success",
12250+
"error"
12251+
],
12252+
"description": "Internal Server Error"
12253+
}
12254+
}
12255+
}
12256+
}
12257+
}
12258+
}
12259+
},
1199312260
"/api/teams/{teamId}/cloud-providers": {
1199412261
"get": {
1199512262
"summary": "List available cloud providers",

0 commit comments

Comments
 (0)