loading…
Search for a command to run...
loading…
Provides production insights and code analysis by leveraging Nexus instrumentation data to identify CPU-intensive methods and visualize execution flow trees. It
Provides production insights and code analysis by leveraging Nexus instrumentation data to identify CPU-intensive methods and visualize execution flow trees. It enables developers to make data-driven decisions through real-time performance metrics and automated service discovery from Java class names.
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.
🏠 Local Setup (Development)
./setup.sh # Install dependencies & setup venv
python3 quick_test.py # Test all tools with real data
./run_server.sh # Start local server (stdio)
🌐 Remote Setup (Docker)
cp env-example .env # Copy environment template
./restart-server.sh # Build & start Docker container
./generate-config.sh # Generate client config (interactive)
./test-mcp-server.sh # Test remote server via HTTP
🔧 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 healthhttp://localhost:8081git clone <your-repo>
cd ck-mcp-server
./setup.sh
python3 quick_test.py
Add this to your Claude Desktop claude_desktop_config.json:
{
"mcpServers": {
"nexus": {
"command": "python3",
"args": ["/absolute/path/to/ck-mcp-server/server.py"],
"env": {}
}
}
}
./run_server.sh
# Copy environment template
cp env-example .env
# Edit .env with your Nexus endpoint if needed
# Start the server
docker-compose up -d --build
# Or use the simple restart script
./restart-server.sh
# Interactive configuration generator
./generate-config.sh
Two Connection Models:
Options:
Script will output ready-to-use JSON config for your specific deployment!
# Health check
curl http://localhost:8547/health
# Test with domain header
curl -X POST http://localhost:8547/mcp \
-H "Content-Type: application/json" \
-H "ck-domain: test" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}'
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:
Example Workflows:
Single Service Found:
1. "Find services for these classes: com.example.UserService, com.example.OrderController"
2. → Returns: ["my-microservice"]
3. "Analyze production usage for my-microservice"
Multiple Services Found:
1. "Find services for these classes: com.example.UserService, com.example.OrderController"
2. → Returns: ["my-microservice", "order-service", "user-service"]
3. → LLM asks: "I found 3 services... Which service would you like to analyze?"
4. User responds: "Let's analyze my-microservice"
5. "Analyze production usage for my-microservice"
get_production_usageGet 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')get_production_call_flowsAnalyze 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')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')"I can see these classes in my IDE: UserService, OrderController, PaymentService, DatabaseUtil. Which services do they belong to?"
1. "Find services for: com.example.UserService, com.example.OrderController"
2. "Analyze production usage for [discovered-service] UserService class"
3. "Show hot methods in [discovered-service]"
"Show me all hot methods in the codetrails service"
"Analyze the production usage for OrderUtil class in codetrails service"
"Show me the call flows for OrderController in codetrails"
"Get the call flows for OrderUtil and highlight any hot methods"
CPU: X.XX% 🔥 annotations in tree output┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Claude UI │────│ MCP Server │────│ Nexus API │
│ │ │ │ │ │
│ Natural Lang │ │ - Tool Handlers │ │ - Flow Data │
│ Queries │ │ - Hot Methods │ │ - CPU Metrics │
│ │ │ - Tree Builders │ │ - Production │
└─────────────────┘ └──────────────────┘ └─────────────────┘
Components:
# Test all tools with real API
python3 quick_test.py
# Test raw APIs only
python3 quick_test.py --raw
🚀 Quick MCP Tools Test
==========================================
0️⃣ SERVICE DISCOVERY TOOL
------------------------------
# Service Name Discovery
## Input Classes (4)
1. `OrderUtil` (Full: `com.example.codetrails.orders.util.OrderUtil`)
2. `OrderServiceImpl` (Full: `com.example.codetrails.orders.service.impl.OrderServiceImpl`)
3. `OrderController` (Full: `com.example.codetrails.orders.controller.OrderController`)
4. `RequestLogFilter` (Full: `com.example.codetrails.config.RequestLogFilter`)
## Discovery Results
✅ **Service Names Found:** 1 matching service(s)
**Domain:** test
### Matching Services:
1. `codetrails`
### Next Steps
You can now use these service name(s) with other production analysis tools:
- `get_production_usage(service_name="codetrails", class_name="...")`
- `get_production_call_flows(service_name="codetrails", class_name="...")`
- `get_hot_methods(service_name="codetrails")`
==================================================
3️⃣ HOT METHODS TOOL
------------------------------
# Hot Methods Report
**Service:** codetrails
**CPU Threshold:** ≥ 1.0%
## Hot Methods Found (1)
### 1. `OrderServiceImpl.compareCharactersExpensively` 🔥
**CPU Utilization:** 1.611%
**Throughput (QPS):** 1,723,283.72
**Optimization Target:** Primary candidate for performance improvement
ck-mcp-server/
├── server.py # Local MCP server (stdio)
├── remote_server.py # Remote MCP server (HTTP/JSON-RPC)
├── quick_test.py # Comprehensive testing script
├── setup.sh # One-command local setup
├── restart-server.sh # Simple Docker container restart
├── test-mcp-server.sh # Remote server testing script
├── run_server.sh # Local server runner
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image configuration
├── docker-compose.yml # Docker Compose setup
├── .dockerignore # Docker build exclusions
├── env-example # Environment variables template
├── mcp-config.json # Local MCP configuration (uses env vars)
├── generate-config.sh # Interactive MCP client config generator
├── README.md # This documentation
└── nexus-api.md # API reference
Key Configuration Files:
mcp-config.json: For local server (Claude Desktop) - sets CK_NEXUS_ENDPOINT env vargenerate-config.sh: Interactive script to generate remote MCP client configs.env: Docker Compose environment variablesControl 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:
# For Docker/remote server - add to .env file:
LOG_LEVEL=DEBUG
# For local server:
export LOG_LEVEL=DEBUG
./run_server.sh
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 onlyThe server uses the ck-domain header to determine which Nexus API path to use:
Generate MCP Client Configuration:
# Use the interactive generator
./generate-config.sh
# Example output for direct connection:
{
"mcpServers": {
"codekarma-insights": {
"url": "http://localhost:8547/mcp",
"headers": {
"ck-domain": "production" // ← Direct to MCP server
}
}
}
}
# Example output for nginx proxy:
{
"mcpServers": {
"codekarma-insights": {
"url": "https://nginx-proxy.com/mcp",
"headers": {
"Authorization": "Bearer mcp_xxx" // ← nginx validates this
}
}
}
}
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/...Default: AWS ELB endpoint (see server.py)
Recommended: Set via environment variable:
export CK_NEXUS_ENDPOINT="http://your-nexus-server:8081"
Docker/Kubernetes:
# In your .env file or Helm values
CK_NEXUS_ENDPOINT=http://your-nexus-server:8081
Alternative: Modify directly in server.py:
class NexusClient:
def __init__(self, base_url: str = "http://your-nexus:8081"):
Default: 1.0% for hot method detection
To change, modify in server.py:
hot_methods = await client.get_hot_methods(service_name, cpu_threshold=2.0)
❌ Error: Connection refused
Solution: Ensure Nexus is running on localhost:8081
No hot methods found (no methods exceed 1% CPU utilization threshold)
Solution: Check that your application has CPU-intensive operations or lower the threshold
No production data found for ClassName
Solution: Verify class name exists and has production traffic
Flow trees show but no 🔥 indicators
Solution: Ensure hot methods API is working: curl http://localhost:8081/{domain}/api/method-graph-paths/hot-methods?serviceName=yourservice&cpuThreshold=1
handle_list_tools() and handle_call_tool()quick_test.pyThe 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 methods GET /{domain}/api/method-graph-paths/flow-details - Detailed flow treesGET /{domain}/api/method-graph-paths/hot-methods - CPU-intensive methodsExamples:
ck-domain: test → /test/api/method-graph-paths/mpksck-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.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"codekarma-mcp-server": {
"command": "npx",
"args": []
}
}
}