MCP Server Monitoring Proxy for Debugging and Development
Kilometers CLI is a command-line tool that acts as a transparent proxy for Model Context Protocol (MCP) servers, capturing and logging JSON-RPC communication for debugging, analysis, and development purposes.
# Install and configure
go build -o build/km cmd/main.go
./build/km init --api-key YOUR_API_KEY
# Monitor any MCP server
./build/km monitor --server -- npx -y @modelcontextprotocol/server-github
- Go 1.21 or later
- Access to a Kilometers API endpoint
git clone https://github.com/kilometers-ai/kilometers-cli.git
cd kilometers-cli
go build -o build/km cmd/main.go
./build/km --version
./build/km --help
# Interactive configuration
./build/km init
# Direct configuration
./build/km init --api-key km_live_your_api_key_here
# Force overwrite existing config
./build/km init --api-key km_live_your_api_key_here --force
The CLI supports these environment variables (precedence: env > config file > defaults):
KILOMETERS_API_KEY
: Your Kilometers API keyKILOMETERS_API_ENDPOINT
: API endpoint (default:http://localhost:5194
)
# Monitor any MCP server command
./build/km monitor --server -- [server-command]
# GitHub MCP Server
./build/km monitor --server -- npx -y @modelcontextprotocol/server-github
# Linear MCP Server
./build/km monitor --server -- npx -y @tacticlaunch/mcp-linear
# Python MCP Server
./build/km monitor --server -- python -m my_mcp_server
# Docker MCP Server
./build/km monitor --server -- docker run my-mcp-server
# Custom executable
./build/km monitor --server -- /path/to/custom-mcp-server
# Enable detailed debug output
./build/km monitor --debug --server -- npx -y @modelcontextprotocol/server-github
# JSON output format
./build/km monitor --output-format json --server -- npx -y @modelcontextprotocol/server-linear
# Console output (default)
./build/km monitor --output-format console --server -- python -m my_server
To use the Kilometers CLI with Cursor's MCP system, add the following configuration to your ~/.cursor/mcp.json
file:
{
"mcpServers": {
"km-linear": {
"command": "/path/to/kilometers-cli/build/km",
"args": [
"monitor",
"--server",
"--",
"npx",
"-y",
"@tacticlaunch/mcp-linear"
],
"env": {
"KILOMETERS_API_KEY": "km_live_your_api_key_here",
"KILOMETERS_API_ENDPOINT": "http://localhost:5194",
"LINEAR_API_TOKEN": "lin_api_your_linear_token_here"
}
}
}
}
{
"mcpServers": {
"km-linear": {
"command": "/path/to/kilometers-cli/build/km",
"args": ["monitor", "--server", "--", "npx", "-y", "@tacticlaunch/mcp-linear"],
"env": {
"KILOMETERS_API_KEY": "km_live_your_api_key_here",
"KILOMETERS_API_ENDPOINT": "http://localhost:5194",
"LINEAR_API_TOKEN": "lin_api_your_linear_token_here"
}
},
"km-github": {
"command": "/path/to/kilometers-cli/build/km",
"args": ["monitor", "--server", "--", "npx", "-y", "@modelcontextprotocol/server-github"],
"env": {
"KILOMETERS_API_KEY": "km_live_your_api_key_here",
"KILOMETERS_API_ENDPOINT": "http://localhost:5194",
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_your_github_token_here"
}
},
"km-playwright": {
"command": "/path/to/kilometers-cli/build/km",
"args": ["monitor", "--server", "--", "npx", "@playwright/mcp@latest"],
"env": {
"KILOMETERS_API_KEY": "km_live_your_api_key_here",
"KILOMETERS_API_ENDPOINT": "http://localhost:5194"
}
}
}
}
-
Build the CLI tool (see Installation)
-
Get your Kilometers API key:
- Contact your Kilometers administrator or
- Generate one from your Kilometers dashboard
-
Update the command path in mcp.json:
- Replace
/path/to/kilometers-cli/build/km
with your actual build path - Example:
/Users/yourusername/Source/kilometers-cli/build/km
- Replace
-
Configure environment variables:
KILOMETERS_API_KEY
: Your Kilometers API key (required)KILOMETERS_API_ENDPOINT
: Your Kilometers API endpoint (required)- Additional tokens for specific MCP servers (LINEAR_API_TOKEN, GITHUB_PERSONAL_ACCESS_TOKEN, etc.)
-
Restart Cursor to load the new MCP configuration
- Command not found: Verify the
command
path points to your built km binary - Permission denied: Ensure the km binary has execute permissions (
chmod +x build/km
) - API connection failed: Check your
KILOMETERS_API_KEY
andKILOMETERS_API_ENDPOINT
- MCP server fails: Verify the underlying MCP server works without km first
# Large message support (for 1MB+ payloads)
./build/km monitor --buffer-size 2MB --server -- python -m large_mcp_server
# Batch processing
./build/km monitor --batch-size 50 --server -- npx -y @modelcontextprotocol/server-github
# Custom output directory
./build/km monitor --output-dir ./logs --server -- docker run my-mcp-server
./build/km monitor --help
Flags:
--batch-size int Batch size for processing messages (default 10)
--buffer-size string Buffer size for large messages (default "1MB")
--debug Enable debug output
-h, --help help for monitor
--output-dir string Output directory for logs (default "./")
--output-format string Output format: console, json (default "console")
--server Indicates server command follows
The CLI automatically handles large JSON-RPC messages (1MB+) that can cause "token too long" errors in other tools:
# Configure larger buffer for very large messages
./build/km monitor --buffer-size 5MB --server -- python -m large_data_server
"Command not found" error
# Ensure km is built and executable
go build -o build/km cmd/main.go
chmod +x build/km
./build/km --version
"API key not configured" error
# Configure your API key
./build/km init --api-key km_live_your_api_key_here
"Connection refused" to Kilometers API
- Verify
KILOMETERS_API_ENDPOINT
is correct - Ensure the Kilometers API server is running
- Check network connectivity and firewall settings
MCP server fails to start
- Test the MCP server command directly without km first
- Check that all required environment variables are set
- Verify the MCP server binary/package is installed
"Token too long" errors
# Increase buffer size for large messages
./build/km monitor --buffer-size 2MB --server -- your-mcp-server
Enable debug mode for detailed troubleshooting:
./build/km monitor --debug --server -- npx -y @modelcontextprotocol/server-github
This will show:
- Process execution details
- Stream handling information
- JSON-RPC message parsing
- Error details and stack traces
The CLI follows Domain-Driven Design (DDD) and Clean Architecture principles:
- Domain Layer: Core business logic (JSONRPCMessage, Command, MonitorConfig)
- Application Layer: Use cases and services (MonitoringService, StreamProxy)
- Infrastructure Layer: External concerns (ProcessExecutor, Logging, HTTP Client)
- Interface Layer: CLI commands and user interaction (Cobra CLI)
# Development build
go build -o build/km cmd/main.go
# Cross-platform builds (see build-releases.sh)
./build-releases.sh
# Run unit tests
go test ./...
# Integration tests
./test-mcp-monitoring.sh
# Test with mock MCP server
echo '{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{}},"id":1}' | \
./build/km monitor --debug --server -- cat
βββ cmd/main.go # CLI entry point
βββ internal/
β βββ core/domain/ # Domain models and business logic
β βββ core/ports/ # Interface definitions
β βββ application/services/ # Application services
β βββ infrastructure/ # External adapters
β βββ interfaces/cli/ # CLI commands and parsing
βββ memory-bank/ # Project documentation
βββ scripts/ # Build and install scripts
[Add your license information here]
[Add contributing guidelines here]
For support and questions:
- [Add support contact information]
- [Add issue tracker link]
- [Add documentation links]
Kilometers CLI - Transparent MCP server monitoring for better debugging and development.