Bevy引擎远程调试MCP服务

将模型上下文协议(MCP)客户端桥接到运行中的Bevy游戏引擎实例,使AI助手能够通过Bevy远程协议实时查看和操作实体、组件与资源。

  • by Nub
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 Nub/bevy_mcp

使用说明

bevy_mcp

MCP server that bridges Model Context Protocol clients to running Bevy game engine instances via the Bevy Remote Protocol (BRP).

This lets AI assistants (Claude, etc.) inspect and manipulate entities, components, and resources in a live Bevy application.

Requirements

  • Rust 1.85+
  • A running Bevy 0.18 app with RemotePlugin and RemoteHttpPlugin enabled

Installation

cargo install --path .

Usage

# Connect to default Bevy instance at localhost:15702
bevy_mcp

# Connect to a specific instance
bevy_mcp --target myapp=192.168.1.50:15702

# Multiple targets
bevy_mcp --target game=localhost:15702 --target editor=localhost:15703

The server communicates over stdio using the MCP protocol. Configure it in your MCP client (e.g. Claude Code, Claude Desktop) as a stdio transport.

Claude Code

claude mcp add bevy -- cargo run --manifest-path /path/to/bevy_mcp/Cargo.toml

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "bevy": {
      "command": "bevy_mcp",
      "args": []
    }
  }
}

Tools

Tool Description
world_query Query entities with component filters
world_get_components Get specific components from an entity by ID
world_spawn_entity Spawn a new entity with components
world_insert_components Insert or update components on an entity
world_remove_components Remove components from an entity
world_despawn_entity Delete an entity
world_reparent_entities Reparent entities (or unparent)
world_get_resources Get a resource by type path
world_insert_resources Insert or update a resource
world_list_components List component types (all or per-entity)
registry_schema Get the type registry schema
rpc_discover Discover available BRP methods
manage_targets Add, remove, list, or switch Bevy targets

Bevy App Setup

Your Bevy app needs the remote plugins enabled:

use bevy::prelude::*;
use bevy::remote::{RemotePlugin, http::RemoteHttpPlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(RemotePlugin::default())
        .add_plugins(RemoteHttpPlugin::default())
        // your systems...
        .run();
}

This starts a BRP HTTP endpoint on port 15702 (default).

Example App & Tests

An example Bevy app and integration test script are included:

# Run the example app (5 colored cubes with a camera and light)
cargo run --manifest-path example_app/Cargo.toml

# Run integration tests (builds and launches the example app automatically)
bash test.sh

The test script exercises rpc.discover, world.query, world.spawn_entity, world.get_components, world.insert_components, world.despawn_entity, and transform manipulation on existing entities.

License

MIT