Bevy Debugger MCP Server
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.
๐ฏ Quick Start (5 minutes)
# 1. Install the debugger
# 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)
# 4. Run your game and start debugging!
# Then open Claude Code and say: "Help me debug my Bevy game"
โจ Features
- ๐ Real-time Observation: Monitor entities, components, and resources as your game runs
- ๐งช Smart Experimentation: Test game behavior changes with automatic rollback
- ๐ Performance Analysis: Identify bottlenecks and optimize game performance
- ๐จ Anomaly Detection: Automatically spot unusual patterns in game behavior
- ๐น Session Recording: Record and replay debugging sessions for analysis
- ๐ธ Screenshot Capture: Take window-specific screenshots of your game for visual debugging
- ๐ก๏ธ Error Recovery: Robust error handling with automatic diagnostics
- ๐ค ML-Powered Suggestions: Learn from debugging patterns to provide better recommendations
- ๐ Performance Budgets: Set and monitor performance targets with automatic alerts
- ๐ Workflow Automation: Automate common debugging tasks with safety checkpoints
๐๏ธ How It Works
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" โ โ
Architecture Components
- Claude Code (AI Agent): Natural language interface for debugging commands
- MCP Server: Translates AI requests into game debugging operations
- BRP Client: Communicates with your Bevy game via WebSocket
- RemotePlugin: Bevy plugin that exposes game internals for debugging
- Debug Tools: 11 specialized tools for different debugging tasks
๐ Quick Start
Prerequisites
- Rust 1.70+ and Cargo
- Claude Code CLI
- A Bevy game with RemotePlugin enabled
Installation
# Install from crates.io (recommended)
# Or clone and build from source
# Install (macOS/Linux)
# Setup Claude Code integration
Server Management with bevy-debugger-control
The 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.
Basic Commands
# Start the server in the background
# Stop the server gracefully
# Restart the server (useful after configuration changes)
# Check if the server is running and view details
# View server logs
# Follow logs in real-time (like tail -f)
# Clean up old log files
# Show help and all available commands
Advanced Usage
# Start server on a different port
BEVY_DEBUGGER_PORT=3002
# Start with custom Bevy host/port
BEVY_BRP_HOST=192.168.1.100 BEVY_BRP_PORT=15703
# Clean all logs including current
# Check server status with process details
# Output shows:
# - PID of running process
# - CPU and memory usage
# - Port binding status
# - Recent log entries
File Locations
The control script manages the following files:
- Logs:
~/.bevy-debugger/bevy-debugger.log - PID file:
~/.bevy-debugger/bevy-debugger.pid - Rotated logs:
~/.bevy-debugger/bevy-debugger.log.*
Troubleshooting
If the server fails to start:
# Check the logs for errors
# Ensure no other instance is running
# Verify the binary is installed
# Check if port is already in use
Setup Your Bevy Game
Add the RemotePlugin to your Bevy app:
use *;
use ;
use ;
use Value;
// Enable screenshot functionality
# Cargo.toml
[]
= { = "0.16", = ["default", "bevy_remote"] }
Start Debugging
- Run your Bevy game:
cargo run - Open Claude Code in your project directory
- Start debugging: Try commands like:
- "Show me all entities in the game"
- "Monitor the player's health component"
- "Test what happens when I spawn 100 enemies"
- "Take a screenshot of the current game state"
- "Record this gameplay session for analysis"
๐ค Claude Code Integration Guide
Setting Up Claude Code
- Install the MCP Server (v0.1.6 or later):
- Configure Claude Code - Add to your Claude Code settings:
macOS/Linux: ~/.config/claude/claude_code_config.json
Windows: %APPDATA%\claude\claude_code_config.json
- Verify Installation:
# Check version
# Test the MCP server responds correctly
|
# Should return: {"id":1,"jsonrpc":"2.0","result":{"capabilities":...}}
# Verify tools are available
|
# Should list: observe, experiment, stress, anomaly, replay, hypothesis, screenshot
How Claude Uses the MCP Tools
When you ask Claude to debug your Bevy game, it has access to powerful MCP tools that communicate with your running game:
๐ Observation Tools
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]
You: "Track the player's velocity over time"
Claude: [Uses observe tool with continuous monitoring]
๐งช Experimentation Tools
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]
You: "Try doubling the player's speed and see if collision still works"
Claude: [Uses experiment tool to modify components with automatic rollback]
๐จ Anomaly Detection
Claude can identify unusual patterns:
You: "Something is causing random lag spikes"
Claude: [Uses anomaly tool to monitor performance metrics]
You: "Find any entities behaving strangely"
Claude: [Uses anomaly tool with pattern matching]
๐ Performance Analysis
Claude can profile and optimize:
You: "Why is my game running slowly?"
Claude: [Uses stress tool to identify bottlenecks]
You: "Optimize the enemy AI system"
Claude: [Uses performance profiling tools]
Real-World Debugging Sessions
Example 1: Physics Bug
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.
Example 2: Performance Investigation
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.
Example 3: Visual Debugging
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:
- --
[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.
Advanced Usage Patterns
Continuous Monitoring
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:
- ---
[After 5 minutes]
Alert: Memory usage increased by 500MB in the last minute.
Investigating... Found 5000 orphaned bullet entities not being destroyed.
Automated Testing
Human: Test if my save system works correctly
Claude: I'll test the save/load system comprehensively.
[Uses orchestration tool to chain operations]
1. 2.3.4.5.6.
Results: Save system works correctly for position and score, but inventory items are duplicated on load.
Troubleshooting Claude Code Connection
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:
# 2. Test the MCP server standalone:
# 3. Verify Claude Code configuration:
# Should contain the bevy-debugger configuration
# 4. Test manual MCP connection:
|
# Should return list of available tools
# 5. Check direct Bevy connection:
# Should return Bevy data
# 6. Enable debug logging:
RUST_LOG=debug
# 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
Performance Characteristics
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 |
Common Issues and Solutions
| 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 |
๐ ๏ธ Configuration
The server uses environment variables for configuration:
# Bevy Remote Protocol host
# Bevy Remote Protocol port
# MCP server port (not used in stdio mode)
# Logging level
๐ Project Structure
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
๐ Complete Developer Workflow
Step 1: Prepare Your Bevy Game
// In your main.rs or lib.rs
use *;
use RemotePlugin;
Step 2: Install and Configure
# Install the debugger
# Add to Claude Code config (~/.config/claude/claude_code_config.json)
{
}
Step 3: Start Debugging Session
- Run your Bevy game:
cargo run - Open Claude Code in your project
- Start debugging with natural language:
- "What entities are in my game?"
- "Why is performance dropping?"
- "Monitor the player's health"
- "Test spawning 1000 enemies"
๐งช Complete Debugging Toolkit (v0.1.6)
Core MCP Tools
| 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" |
Internal Debug Commands (11 Integrated Tools)
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 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) |
macOS Service Management
On macOS, the debugger can run as a background service:
# Service management
๐ค Contributing
We welcome contributions! Please see our contribution guidelines.
# Development setup
Running Screenshot Tests
The screenshot functionality has comprehensive test coverage:
# Fast screenshot tests (suitable for CI/development)
# Full screenshot integration suite
# Individual test categories
# Performance testing
๐ Documentation
- Usage Guide - Detailed feature documentation
- Claude Prompts - Effective prompting strategies
- macOS Service Setup - Background service configuration
๐ Security & Privacy
- All communication happens locally between your game and Claude Code
- No game data is transmitted externally
- Sensitive information is automatically redacted from logs
- Debug recordings are stored locally and encrypted
๐ฆ Changelog
v0.1.6 (Latest) - Production Ready
- โ All 11 debugging tools fully integrated and operational
- โ Fixed critical async initialization issues
- โ Enhanced error handling and sensitive data sanitization
- โ Performance optimizations with lazy initialization
- โ Comprehensive test coverage (232+ tests)
- โ Machine learning pattern recognition with privacy preservation
- โ Workflow automation for common debugging tasks
- โ Production-ready with <3% performance overhead
v0.1.5
- Added GPL-3.0 license compliance
- Initial pattern learning system
- Enhanced error context
v0.1.4
- Improved Claude Code integration
- Added suggestion engine
- Bug fixes
๐ License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
๐ Acknowledgments
- Built for the Bevy Engine community
- Powered by Anthropic's MCP
- Inspired by the need for better game debugging tools
Questions? Open an issue or join the discussion in Bevy's Discord.