| Crates.io | bevy_debugger_mcp |
| lib.rs | bevy_debugger_mcp |
| version | 0.1.8 |
| created_at | 2025-08-18 11:50:36.621057+00 |
| updated_at | 2025-08-23 11:47:02.707758+00 |
| description | AI-assisted debugging for Bevy games through Claude Code using Model Context Protocol |
| homepage | https://github.com/ladvien/bevy_debugger_mcp |
| repository | https://github.com/ladvien/bevy_debugger_mcp |
| max_upload_size | |
| id | 1800361 |
| size | 2,284,686 |
A powerful Model Context Protocol (MCP) server that enables AI-assisted debugging of Bevy games through Claude Code. Debug your game state, analyze performance, and test hypotheses with natural language commands.
# 1. Install the debugger
cargo install bevy_debugger_mcp
# 2. Add RemotePlugin to your Bevy game
# In your game's main.rs:
# .add_plugins(RemotePlugin::default())
# 3. Configure Claude Code (add to ~/.config/claude/claude_code_config.json)
echo '{
"mcpServers": {
"bevy-debugger": {
"command": "bevy-debugger-mcp",
"args": []
}
}
}' >> ~/.config/claude/claude_code_config.json
# 4. Run your game and start debugging!
cargo run # In your game directory
# Then open Claude Code and say: "Help me debug my Bevy game"
The Bevy Debugger MCP creates a bridge between Claude Code and your Bevy game:
โโโโโโโโโโโโโโโ MCP Protocol โโโโโโโโโโโโโโโโโโโโ BRP Protocol โโโโโโโโโโโโโโโ
โ Claude Code โ โโโโโโโโโโโโโโโโโโโโบ โ bevy-debugger-mcp โ โโโโโโโโโโโโโโโโโโโบ โ Your Bevy โ
โ (AI) โ stdio/TCP โ (Server) โ WebSocket โ Game โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ โ
โ "Find memory leaks" โ โ
โโโโโโโโโโโโโโโโโโโโโโบ โ โ
โ Query entities & components โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโบโ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Entity data & metrics โ
โโโโโโโโโโโโโโโโโโโโโโ โ โ
โ "Found 500 orphaned โ โ
โ bullet entities" โ โ
# Install from crates.io (recommended)
cargo install bevy_debugger_mcp
# Or clone and build from source
git clone https://github.com/ladvien/bevy_debugger_mcp.git
cd bevy_debugger_mcp
cargo build --release
# Install (macOS/Linux)
./scripts/install.sh
# Setup Claude Code integration
./scripts/setup-claude.sh
bevy-debugger-controlThe bevy-debugger-control script is automatically installed with the package and provides complete lifecycle management for the MCP server. This solves the common issue of the server hanging when run directly.
# Start the server in the background
bevy-debugger-control start
# Stop the server gracefully
bevy-debugger-control stop
# Restart the server (useful after configuration changes)
bevy-debugger-control restart
# Check if the server is running and view details
bevy-debugger-control status
# View server logs
bevy-debugger-control logs
# Follow logs in real-time (like tail -f)
bevy-debugger-control logs -f
# Clean up old log files
bevy-debugger-control clean
# Show help and all available commands
bevy-debugger-control help
# Start server on a different port
BEVY_DEBUGGER_PORT=3002 bevy-debugger-control start
# Start with custom Bevy host/port
BEVY_BRP_HOST=192.168.1.100 BEVY_BRP_PORT=15703 bevy-debugger-control start
# Clean all logs including current
bevy-debugger-control clean --all
# Check server status with process details
bevy-debugger-control status
# Output shows:
# - PID of running process
# - CPU and memory usage
# - Port binding status
# - Recent log entries
The control script manages the following files:
~/.bevy-debugger/bevy-debugger.log~/.bevy-debugger/bevy-debugger.pid~/.bevy-debugger/bevy-debugger.log.*If the server fails to start:
# Check the logs for errors
bevy-debugger-control logs
# Ensure no other instance is running
bevy-debugger-control stop
bevy-debugger-control start
# Verify the binary is installed
which bevy-debugger-mcp
# Check if port is already in use
lsof -i :3001 # or your configured port
Add the RemotePlugin to your Bevy app:
use bevy::prelude::*;
use bevy::remote::{RemotePlugin, BrpResult};
use bevy::render::view::screenshot::{save_to_disk, Screenshot};
use serde_json::Value;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(
RemotePlugin::default()
.with_method("bevy_debugger/screenshot", screenshot_handler)
)
.run();
}
// Enable screenshot functionality
fn screenshot_handler(
In(params): In<Option<Value>>,
mut commands: Commands,
) -> BrpResult {
let path = params
.as_ref()
.and_then(|p| p.get("path"))
.and_then(|p| p.as_str())
.unwrap_or("./screenshot.png")
.to_string();
commands
.spawn(Screenshot::primary_window())
.observe(save_to_disk(path.clone()));
Ok(serde_json::json!({
"path": path,
"success": true
}))
}
# Cargo.toml
[dependencies]
bevy = { version = "0.16", features = ["default", "bevy_remote"] }
cargo runcargo install bevy_debugger_mcp
macOS/Linux: ~/.config/claude/claude_code_config.json
Windows: %APPDATA%\claude\claude_code_config.json
{
"mcpServers": {
"bevy-debugger": {
"command": "bevy-debugger-mcp",
"args": ["--stdio"],
"type": "stdio",
"env": {
"BEVY_BRP_HOST": "localhost",
"BEVY_BRP_PORT": "15702",
"RUST_LOG": "info"
}
}
}
}
# Check version
bevy-debugger-mcp --help
# Test the MCP server responds correctly
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {"capabilities": {}}, "id": 1}' | bevy-debugger-mcp --stdio
# Should return: {"id":1,"jsonrpc":"2.0","result":{"capabilities":...}}
# Verify tools are available
echo '{"jsonrpc": "2.0", "method": "tools/list", "id": 2}' | bevy-debugger-mcp --stdio
# Should list: observe, experiment, stress, anomaly, replay, hypothesis, screenshot
When you ask Claude to debug your Bevy game, it has access to powerful MCP tools that communicate with your running game:
Claude can monitor your game state in real-time:
You: "Show me all enemies in the game"
Claude: [Uses observe tool to query entities with Enemy component]
"I found 5 enemies. Here are their positions and health values..."
You: "Track the player's velocity over time"
Claude: [Uses observe tool with continuous monitoring]
"The player's velocity spikes to 500 units when jumping, which seems abnormal..."
Claude can test hypotheses by modifying game state:
You: "Test what happens if we spawn 100 enemies at once"
Claude: [Uses experiment tool to spawn entities and measure performance]
"Spawning 100 enemies causes frame rate to drop to 15 FPS. The bottleneck is..."
You: "Try doubling the player's speed and see if collision still works"
Claude: [Uses experiment tool to modify components with automatic rollback]
"At 2x speed, the player clips through thin walls. The physics system needs..."
Claude can identify unusual patterns:
You: "Something is causing random lag spikes"
Claude: [Uses anomaly tool to monitor performance metrics]
"I detected memory allocations spike every 5 seconds, coinciding with..."
You: "Find any entities behaving strangely"
Claude: [Uses anomaly tool with pattern matching]
"Entity #42 is teleporting between positions, likely due to..."
Claude can profile and optimize:
You: "Why is my game running slowly?"
Claude: [Uses stress tool to identify bottlenecks]
"The render system is taking 45ms per frame. The main issue is..."
You: "Optimize the enemy AI system"
Claude: [Uses performance profiling tools]
"The pathfinding is recalculating every frame. We can cache results..."
Human: My character falls through the floor randomly
Claude: I'll investigate this physics issue. Let me start by observing the player's Transform and Collider components.
[Uses observe tool to monitor player entity]
I'm tracking the player's Y position... I notice it suddenly changes from 0.0 to -100.0 without intermediate values.
[Uses experiment tool to test collision]
Let me test the collision system by spawning a test entity at the player's position...
The collision detection is failing when the player's velocity exceeds 1000 units/frame.
Solution: Add a velocity cap or use continuous collision detection for high-speed entities.
Human: The game freezes every few seconds
Claude: I'll analyze the performance patterns to identify the cause of these freezes.
[Uses anomaly detection on frame times]
I've detected periodic spikes in frame time every 3.2 seconds, lasting about 200ms.
[Uses observe tool on system metrics]
Monitoring system activity... The "EnemySpawnSystem" is creating 50 entities at once every 3 seconds.
[Uses experiment tool to test optimization]
Let me test spreading the spawning over multiple frames...
Spawning 5 entities per frame over 10 frames eliminates the freezes.
Solution: Implement batched spawning to distribute the load across frames.
Human: Can you show me what the AI sees?
Claude: I'll visualize the AI's perception system for you.
[Uses visual overlay tools]
I'm enabling debug overlays for:
- AI vision cones (showing field of view)
- Pathfinding waypoints (showing planned routes)
- Detection ranges (showing awareness zones)
[Takes screenshot]
Here's a screenshot showing the AI's perception. The red cones are vision, blue lines are paths.
The AI at position (100, 50) can't see the player because there's an obstacle blocking line of sight.
Human: Monitor the game for any issues while I playtest
Claude: I'll set up continuous monitoring for common issues.
[Sets up multiple observe and anomaly detection tasks]
Monitoring:
- Memory usage (alerting if >2GB)
- Frame time (alerting if >16ms)
- Entity count (alerting if >10000)
- Error patterns in components
[After 5 minutes]
Alert: Memory usage increased by 500MB in the last minute.
Investigating... Found 5000 orphaned bullet entities not being destroyed.
Human: Test if my save system works correctly
Claude: I'll test the save/load system comprehensively.
[Uses orchestration tool to chain operations]
1. Capturing current game state...
2. Modifying player position, inventory, and score...
3. Triggering save...
4. Resetting game...
5. Triggering load...
6. Comparing states...
Results: Save system works correctly for position and score, but inventory items are duplicated on load.
If Claude can't connect to your game:
# 1. Ensure your Bevy game is running with RemotePlugin
# Check if Bevy is listening on the correct port:
lsof -i :15702 # Should show your Bevy game process
# 2. Test the MCP server standalone:
bevy-debugger-mcp --help # Should show version 0.1.6
bevy-debugger-mcp --stdio # Should wait for input (Ctrl+C to exit)
# 3. Verify Claude Code configuration:
cat ~/.config/claude/claude_code_config.json
# Should contain the bevy-debugger configuration
# 4. Test manual MCP connection:
echo '{"jsonrpc": "2.0", "method": "tools/list", "id": 2}' | bevy-debugger-mcp --stdio
# Should return list of available tools
# 5. Check direct Bevy connection:
curl -X POST http://localhost:15702/query \
-H "Content-Type: application/json" \
-d '{"method": "bevy/list", "params": {}}'
# Should return Bevy data
# 6. Enable debug logging:
RUST_LOG=debug bevy-debugger-mcp --stdio
# 7. Common issues:
# - Port 15702 blocked by firewall
# - Bevy game not compiled with bevy_remote feature
# - Multiple MCP servers running on same port
# - Claude Code needs restart after config changes
The debugger is designed for minimal impact on your game:
| Metric | Target | Actual | Notes |
|---|---|---|---|
| Idle Overhead | <5% | <3% | When connected but not actively debugging |
| Active Overhead | <10% | <7% | During active debugging operations |
| Memory Usage | <50MB | ~30MB | Includes caching and session data |
| Startup Time | <1s | ~500ms | With lazy initialization |
| Command Latency | <200ms | <50ms | For simple queries |
| Complex Query | <1s | ~200ms | For queries returning 1000+ entities |
| Issue | Solution |
|---|---|
| "Failed to connect to BRP" | Ensure your Bevy game is running with RemotePlugin enabled |
| "No tools available" | Update to v0.1.6: cargo install bevy_debugger_mcp --force |
| High CPU usage | Reduce monitoring frequency or use --tcp mode instead of stdio |
| Screenshot not working | Add screenshot handler to your Bevy game (see setup example) |
| Memory leak detection false positives | Adjust detection thresholds in anomaly tool |
| Claude not responding | Restart Claude Code after configuration changes |
The server uses environment variables for configuration:
export BEVY_BRP_HOST=localhost # Bevy Remote Protocol host
export BEVY_BRP_PORT=15702 # Bevy Remote Protocol port
export MCP_PORT=3000 # MCP server port (not used in stdio mode)
export RUST_LOG=info # Logging level
bevy_debugger_mcp/
โโโ src/
โ โโโ main.rs # Entry point with stdio/TCP transport
โ โโโ mcp_server.rs # MCP protocol implementation
โ โโโ brp_client.rs # Bevy Remote Protocol client
โ โโโ tools/ # Debugging tool implementations
โ โ โโโ observe.rs # Entity/component observation
โ โ โโโ experiment.rs # Game state experimentation
โ โ โโโ stress.rs # Performance stress testing
โ โ โโโ ...
โ โโโ ...
โโโ scripts/ # Installation and management scripts
โโโ docs/ # Documentation
โโโ tests/ # Integration tests
โโโ README.md
// In your main.rs or lib.rs
use bevy::prelude::*;
use bevy::remote::RemotePlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(RemotePlugin::default()) // Essential for debugging
.add_systems(Update, your_game_systems)
.run();
}
# Install the debugger
cargo install bevy_debugger_mcp
# Add to Claude Code config (~/.config/claude/claude_code_config.json)
{
"mcpServers": {
"bevy-debugger": {
"command": "bevy-debugger-mcp",
"args": []
}
}
}
cargo run| Tool | Description | Example Usage |
|---|---|---|
observe |
Monitor game entities, components, and resources in real-time | "Show me all entities with Health component" |
experiment |
Test changes to game state with automatic rollback | "Set player speed to 2x and test collision" |
stress |
Performance testing and bottleneck identification | "Stress test the physics system with 500 objects" |
anomaly |
Detect unusual patterns in game behavior | "Find any entities with abnormal velocities" |
replay |
Record and replay debugging sessions | "Record the next 30 seconds of gameplay" |
hypothesis |
Test specific assumptions about game behavior | "Test if framerate drops when spawning > 100 enemies" |
screenshot |
Capture game window visuals with timing control | "Take a screenshot after 2 seconds warmup" |
The debugger provides 11 specialized debugging tools accessible through the MCP protocol:
| Tool | Purpose | Key Features |
|---|---|---|
| EntityInspector | Deep entity analysis | โข Component inspection โข Relationship tracking โข Change detection |
| SystemProfiler | System performance analysis | โข Microsecond precision โข Dependency tracking โข <3% overhead |
| VisualDebugOverlay | In-game debug visualization | โข Entity highlights โข Collider visualization โข Performance metrics |
| QueryBuilder | Type-safe ECS queries | โข Natural language queries โข Query validation โข Result caching |
| MemoryProfiler | Memory usage tracking | โข Allocation tracking โข Leak detection โข Usage patterns |
| SessionManager | Debug session management | โข Session recording โข Checkpoint creation โข State comparison |
| IssueDetector | Automated issue detection | โข 17 detection patterns โข Real-time monitoring โข Auto-diagnostics |
| PerformanceBudgetMonitor | Performance budget enforcement | โข Frame time budgets โข Memory limits โข Violation tracking |
| PatternLearningSystem | ML-based pattern recognition | โข Privacy-preserving (k=5) โข Pattern mining โข Suggestion generation |
| SuggestionEngine | Context-aware suggestions | โข Based on learned patterns โข Confidence scoring โข Action recommendations |
| WorkflowAutomation | Automated debug workflows | โข Common task automation โข Safety checkpoints โข Rollback support |
| Platform | Installation | Status |
|---|---|---|
| macOS | ./scripts/install.sh |
โ Full support with LaunchAgent service |
| Linux | ./scripts/install.sh |
โ Full support |
| Windows | Manual build | โ ๏ธ Basic support (help wanted) |
On macOS, the debugger can run as a background service:
# Service management
./scripts/service.sh start # Start background service
./scripts/service.sh stop # Stop service
./scripts/service.sh status # Check status
./scripts/service.sh logs # View logs
We welcome contributions! Please see our contribution guidelines.
# Development setup
git clone https://github.com/ladvien/bevy_debugger_mcp.git
cd bevy_debugger_mcp
cargo test # Run basic tests
cargo test --ignored # Run full integration tests
cargo test screenshot_integration_wrapper::test_screenshot_ci_suite # Fast screenshot tests
cargo fmt # Format code
cargo clippy # Lint code
The screenshot functionality has comprehensive test coverage:
# Fast screenshot tests (suitable for CI/development)
cargo test screenshot_integration_wrapper::test_screenshot_ci_suite
# Full screenshot integration suite
cargo test screenshot_integration_wrapper::test_screenshot_integration_suite -- --ignored
# Individual test categories
cargo test screenshot_integration_wrapper::test_screenshot_utilities
cargo test screenshot_integration_wrapper::test_screenshot_basic_functionality
cargo test screenshot_integration_wrapper::test_screenshot_parameter_validation
cargo test screenshot_integration_wrapper::test_screenshot_timing_controls
# Performance testing
cargo test screenshot_integration_wrapper::test_screenshot_performance
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Questions? Open an issue or join the discussion in Bevy's Discord.