Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CodeKarma MCP ServerIdentify the CPU-intensive methods in the payment-service"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CodeKarma MCP Server
A Model Context Protocol (MCP) server that provides production insights and code analysis capabilities using your Nexus instrumentation data. Analyze real production flows, identify hot methods, generate test cases, and make data-driven decisions about your code.
โก Quick Start Reference
๐ Local Setup (Development)
๐ Remote Setup (Docker)
๐ง Quick Commands
./restart-server.sh- Restart Docker container./generate-config.sh- Create MCP client configs (Direct or nginx proxy)python3 quick_test.py- Test all 4 tools locallycurl http://localhost:8547/health- Check Docker server health
๐ Deployment Options
๐ Local Server (Original)
Direct Python execution
Uses stdio transport
For local development and testing
๐ Remote Server (New!)
HTTP/JSON-RPC transport with flexible authentication
Docker containerized
For shared team access and production use
Port: 8547 (non-common port)
Authentication: Two models supported:
Direct: ck-domain header (no auth needed)
nginx Proxy: Bearer token (nginx validates and adds ck-domain)
๐ Features
๐ฅ Hot Method Detection - Identify CPU-intensive methods above configurable thresholds
๐ Production Usage Analysis - Get real-time insights about method execution patterns
๐ณ Flow Tree Visualization - View individual and aggregated execution flow trees
โก Performance Optimization - Get CPU utilization insights and optimization recommendations
๐ฏ Data-Driven Development - Make code changes based on real production usage
๐ Prerequisites
Python 3.8+
Nexus service running on
http://localhost:8081Instrumented Java application with production flow data
โก Quick Start
๐ Local Server Setup
1. Setup (One Command)
2. Test the Server
3. Configure Claude Desktop
Add this to your Claude Desktop claude_desktop_config.json:
4. Start Using
๐ Remote Server Setup (Recommended for Teams)
1. Deploy with Docker
2. Generate Client Configuration
Two Connection Models:
Direct Connection: Uses ck-domain header, connects directly to MCP server (port 8547)
nginx Proxy: Uses Bearer token, connects through nginx (nginx validates token and adds ck-domain)
Options:
Connection Type: Choose Direct or nginx Proxy
Client Type: Choose Windsurf or Claude Desktop/Cursor
Domain Examples: test, production, staging, or custom
Script will output ready-to-use JSON config for your specific deployment!
3. Verify Connection
๐ ๏ธ Available Tools
1. find_service_names ๐
Find service names from a list of class names visible in your IDE. This tool helps discover which services contain the specified classes when the service name is unknown.
Parameters:
class_names(required): Array of fully qualified class names (e.g.,['com.example.service.UserService', 'com.example.util.DatabaseUtil'])
Usage:
When you don't know the service name but have class names from your IDE
Provide 10-20 class names for optimal matching accuracy
If multiple services are found, the tool will prompt you to ask the user which service to analyze
Use discovered service names with other production analysis tools
Example Workflows:
Single Service Found:
Multiple Services Found:
2. get_production_usage
Get production usage information for methods including throughput and activity status.
Parameters:
service_name(required): Name of the service (e.g., 'codetrails')class_name(required): Full class namemethod_name(optional): Specific method namestep(optional): Time window (default: '1m')
3. get_production_call_flows
Analyze production method call patterns and flows with aggregated performance metrics and hot method annotations.
Parameters:
service_name(required): Name of the serviceclass_name(required): Full class namemethod_name(optional): Specific method namestep(optional): Time window (default: '1m')
4. get_hot_methods ๐ฅ
Get details about hot methods that have high CPU utilization in production (above 1% CPU threshold).
Parameters:
service_name(required): Name of the servicestep(optional): Time window (default: '1m')
๐ก Usage Examples
Service Discovery (New!)
Automatically discovers service names from class names
No need to manually know service names
Sets up other tools for further analysis
Complete Workflow (Unknown Service)
Start with class names from your IDE
Discover services automatically
Dive into production analysis
Hot Method Analysis
Identifies CPU-intensive methods
Shows CPU utilization percentages
Provides optimization recommendations
Production Flow Analysis
Shows QPS, error rates, latency for each method
Identifies active vs inactive methods
Highlights HTTP endpoints
Execution Tree Visualization
Displays aggregated flow trees
Shows CPU annotations for hot methods (๐ฅ)
Includes flow IDs and metrics
Combined Analysis
Shows comprehensive flow analysis
Annotates hot methods with CPU utilization
Provides context about flow patterns
๐ฏ Key Features in Detail
๐ฅ Hot Method Detection
CPU Threshold: Automatically detects methods above 1% CPU utilization
Performance Impact: Shows actual CPU consumption percentages
Optimization Targeting: Prioritizes optimization efforts on high-impact methods
Visual Indicators: Hot methods marked with ๐ฅ in flow trees
๐ Flow Tree Annotations
Individual Flows: Shows hot methods in each execution path
Unified Trees: Aggregates CPU data across all flows
Visual Clarity:
CPU: X.XX% ๐ฅannotations in tree outputContext Aware: Matches methods by className + methodName
โก Production Insights
Real-time Data: Live production metrics from Nexus
HTTP Endpoints: Shows which endpoints trigger hot methods
Error Correlation: Combines CPU usage with error rates
Throughput Analysis: QPS/QPM data alongside CPU metrics
๐๏ธ Architecture
Components:
NexusClient: Async HTTP client for Nexus API calls
Hot Methods Engine: CPU threshold detection and annotation
Tree Builders: Flow tree construction and visualization
Analysis Functions: Production usage insights and recommendations
๐งช Testing
Local Testing
What Gets Tested:
โ All 4 MCP tools (service discovery, usage analysis, call flows, hot methods)
โ Raw Nexus API connectivity (find-service-name, mpks, flows, flow-details, hot-methods)
โ Service discovery from class names
โ Hot method detection and annotation
โ Real production data integration
Sample Test Output:
๐ Project Structure
Key Configuration Files:
mcp-config.json: For local server (Claude Desktop) - setsCK_NEXUS_ENDPOINTenv vargenerate-config.sh: Interactive script to generate remote MCP client configs.env: Docker Compose environment variables
๐ง Configuration
Logging Level
Control the verbosity of server logs using the LOG_LEVEL environment variable:
Available Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL
Default: INFO (shows INFO, WARNING, ERROR, CRITICAL)
To see debug logs:
What each level shows:
DEBUG: All logs including debug messages (most verbose)INFO: Informational messages and above (default)WARNING: Warning messages and aboveERROR: Error messages onlyCRITICAL: Critical errors only
Domain-Based Routing
The server uses the ck-domain header to determine which Nexus API path to use:
Generate MCP Client Configuration:
Domain โ API Path Mapping:
ck-domain: "test"โ Nexus calls to/test/api/method-graph-paths/...ck-domain: "production"โ Nexus calls to/production/api/method-graph-paths/...ck-domain: "staging"โ Nexus calls to/staging/api/method-graph-paths/...
Nexus Connection
Default: AWS ELB endpoint (see server.py)
Recommended: Set via environment variable:
Docker/Kubernetes:
Alternative: Modify directly in server.py:
CPU Threshold
Default: 1.0% for hot method detection
To change, modify in server.py:
๐ Troubleshooting
Connection Issues
Solution: Ensure Nexus is running on localhost:8081
No Hot Methods Found
Solution: Check that your application has CPU-intensive operations or lower the threshold
Empty Flow Trees
Solution: Verify class name exists and has production traffic
Missing CPU Annotations
Solution: Ensure hot methods API is working: curl http://localhost:8081/{domain}/api/method-graph-paths/hot-methods?serviceName=yourservice&cpuThreshold=1
๐ Next Steps
Deploy to Production: Use with your production Nexus instance
Custom Thresholds: Adjust CPU thresholds for your environment
Integration: Add to CI/CD pipelines for performance monitoring
Optimization: Use hot method data to prioritize performance improvements
Monitoring: Set up alerts for new hot methods in production
๐ค Contributing
Add New Tools: Extend
handle_list_tools()andhandle_call_tool()Enhance Analysis: Add new metrics and insights to existing tools
Improve Visualization: Enhance tree rendering and annotations
Testing: Add test cases to
quick_test.py
๐ API Endpoints Used
The server integrates with these Nexus endpoints (domain dynamically set via ck-domain header):
POST /{domain}/api/method-graph-paths/find-service-name- Service discovery from class namesGET /{domain}/api/method-graph-paths/mpks- Method summary with profiling infoGET /{domain}/api/method-graph-paths/flows- Flow IDs for methodsGET /{domain}/api/method-graph-paths/flow-details- Detailed flow treesGET /{domain}/api/method-graph-paths/hot-methods- CPU-intensive methods
Examples:
With
ck-domain: testโ/test/api/method-graph-paths/mpksWith
ck-domain: productionโ/production/api/method-graph-paths/mpks
๐ฅ Ready to optimize your production code with data-driven insights!
Start by running ./setup.sh and then python3 quick_test.py to see your hot methods in action.