bt-mcp-server

liangchaaaaa/bt-mcp-server

3.2

If you are the rightful owner of bt-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The BT MCP Server is a robust system designed to execute behavior trees using a model context protocol, integrating seamlessly with ROS2 and supporting dynamic plugin development.

Tools
2
Resources
0
Prompts
0

BT MCP Server

Project Structure

bt_mcp_server/
├── bt_engine.cpp          # Behavior tree execution engine
├── server.py              # MCP server
├── CMakeLists.txt         # Build configuration
├── plugins/               # Custom behavior tree node plugins
│   ├── dummy_nodes_dyn.cpp    # Example node: PrintMessage
│   └── custom_counter_dyn.cpp # Stateful node: CustomCounter
└── build/                 # Build output directory

Main Features

1. Behavior Tree Execution Engine

  • Support for XML-defined behavior trees
  • Plugin auto-loading
  • Blackboard initialization support
  • Real-time execution state monitoring

2. MCP Protocol Integration

  • Standard MCP tool interface based on FastMCP SDK
  • Asynchronous execution support
  • Health check endpoints
  • Error handling and status feedback

3. Plugin System

  • Dynamic library (.so) auto-loading
  • Standard plugin registration interface
  • Type-safe node registration

Quick Start

Build the Project

mkdir build && cd build
cmake ..
make -j$(nproc)

Start Services

# Start behavior tree engine
source /opt/ros/jazzy/setup.bash # Running in jazzy version ROS2 system environment
./bt_engine

# Start MCP server
python3 -m venv bt_mcp_env # bt_mcp_env already contains required packages
python server.py

API Documentation

MCP Tools

execute_xml

Execute behavior tree defined in XML format.

Parameters:

  • xml (str): Behavior tree XML definition
  • tree_id (str, optional): Tree identifier
  • blackboard_init (dict, optional): Blackboard initialization values

Returns:

{
    "status": "SUCCESS|ERROR",
    "message": "Execution result description",
    "elapsed_ms": "Execution time in milliseconds",
    "tree_id": "Tree identifier"
}
engine_health

Check engine health status.

Returns:

{
    "ok": true|false,
    "engine_response": "Engine response details"
}

Protocol

The engine provides JSON-RPC style service via TCP port 8080:

{
    "command": "EXECUTE_XML|PING|SHUTDOWN",
    "xml": "Behavior tree XML",
    "tree_id": "Identifier",
    "blackboard_init": {}
}

Plugin Development

Creating Custom Nodes

#include "behaviortree_cpp/bt_factory.h"

class MyCustomNode : public BT::SyncActionNode {
public:
    MyCustomNode(const std::string& name, const BT::NodeConfig& config)
        : BT::SyncActionNode(name, config) {}

    BT::NodeStatus tick() override {
        // Node logic implementation...
        return BT::NodeStatus::SUCCESS;
    }

    static BT::PortsList providedPorts() {
        return { BT::InputPort<std::string>("input_param") };
    }
};

// Registration function
extern "C" void BT_RegisterNodesFromPlugin(BT::BehaviorTreeFactory& factory) {
    factory.registerNodeType<MyCustomNode>("MyCustomNode");
}

Compiling Plugins

g++ -shared -fPIC -o my_plugin.so my_plugin.cpp \
    -IBehaviorTree.CPP-master/include \
    -Lbuild -lbehaviortree_cpp

Configuration

Environment Variables

  • BT_PLUGIN_PATH: Specify plugin loading path

Build Options

  • CMAKE_CXX_STANDARD: C++17
  • Compiler warnings: -Wall -Wextra -Werror=return-type

Extension Integration

ROS2 Integration

Project integrates ROS2 rclcpp, supporting:

  • ROS2 node lifecycle management
  • Collaboration with ROS2 systems
  • Future extensibility for ROS2 custom nodes

Development Guidelines

Code Standards

  • C++17 standard
  • Google C++ Style Guide

License

This project code uses

Third-party Libraries