mcp-analytics-middleware
v1.0.5
Published
Analytics middleware for Model Context Protocol servers
Downloads
74
Maintainers
Readme
MCP Analytics Middleware
A simple way to track and visualize how your MCP server is being used. See which tools are most popular, catch errors early, and understand your server's performance.
Features
- 🔍 Track all tool calls and resource requests
- 📊 See performance metrics and error rates
- 🌐 Beautiful web dashboard for live analytics
- 💾 SQLite database for persistent storage
- ⚡ Real-time updates every 5 seconds
Quick Start
- Install the package:
yarn add mcp-analytics-middleware- Add it to your MCP server:
import { McpAnalytics } from 'mcp-analytics-middleware';
const analytics = new McpAnalytics('analytics.db');
server.use(analytics.middleware);- View your analytics:
# Console view
yarn mcp-analytics-view --db-path=analytics.db
# Or check out the fancy web dashboard
yarn web-viewer --db-path=analytics.dbThe web dashboard will open at http://localhost:5000 and show you live analytics!
Live Analytics
Want to see what's happening on your server right now? Just start the web viewer with your database path:
yarn web-viewer --db-path=analytics.dbYou'll see:
- Total tool calls and resource requests
- Error rates and performance metrics
- Most used tools and slowest operations
- Daily usage patterns
- And it all updates automatically every 5 seconds!
Running with Inspector
If you're using the MCP Inspector, just add the analytics flag:
yarn inspector --db-path=analytics.dbAPI Reference
McpAnalytics
The main class that handles everything.
class McpAnalytics {
constructor(dbPath: string);
middleware: Middleware;
db: AnalyticsDB;
analytics: Analytics;
}AnalyticsDB
Handles all the database stuff.
class AnalyticsDB {
getToolCallStats(): ToolStats;
getResourceRequestStats(): ResourceStats;
}Analytics
Gives you all the cool analytics calculations.
class Analytics {
getTopTools(limit: number): ToolStats[];
getSlowestTools(limit: number): ToolStats[];
getErrorProneTool(limit: number): ToolStats[];
}Development
# Install everything
yarn install
# Build the project
yarn build
# Start the development server
yarn devLicense
MIT
