ROS2 MCP Server

Integrations

  • Uses NumPy for handling numerical operations required by ROS 2 message types.

  • Publishes geometry_msgs/Twist messages to the /cmd_vel topic to control robot movement, compatible with ROS 2 simulators and real robots.

ros2-mcp-サーバー

ros2-mcp-server 、Model Context Protocol(MCP)をROS 2に統合したPythonベースのサーバーです。これにより、AIアシスタントがROS 2トピックを介してロボットを制御できるようになります。FastMCPを介してコマンドを処理し、ROS 2ノードとして動作し、 geometry_msgs/Twistメッセージを/cmd_velトピックにパブリッシュしてロボットの動きを制御します。

この実装では、 pub_cmd_velという名前の/cmd_velパブリッシャーを使用して、「0.2 m/s で 5 秒間前進して停止する」などのコマンドをサポートします。

特徴

  • MCP 統合: FastMCP を使用して、MCP クライアント (例: Claude) からのコマンドを処理します。
  • ROS 2 ネイティブ: ROS 2 ノードとして動作し、 /cmd_velに直接公開します。
  • 時間ベースの制御: 期間ベースの移動コマンドをサポートします (例: 指定された時間移動して停止する)。
  • 非同期処理: FastMCP のasyncioと ROS 2 のイベント ループを組み合わせて効率的な操作を実現します。

前提条件

  • ROS 2 : Humble ディストリビューションをインストールしてソースしました。
  • Python : バージョン 3.10 (ROS 2 Humble との互換性のために必要)。
  • uv : 依存関係管理用の Python パッケージ マネージャー。
  • 依存関係:
    • rclpy : ROS 2 Python クライアント ライブラリ (ROS 2 とともにインストールされます)。
    • fastmcp : MCP サーバー実装用の FastMCP フレームワーク。
    • numpy : ROS 2 メッセージ タイプで必須。

インストール

  1. リポジトリのクローンを作成します:
    git clone https://github.com/kakimochi/ros2-mcp-server.git cd ros2-mcp-server
  2. Pythonバージョン設定:このプロジェクトでは、ROS 2 Humbleの要件に従い、Python 3.10を使用しています。.python .python-versionファイルは既に設定されています。
    # .python-version content 3.10
  3. プロジェクトの依存関係: pyproject.tomlファイルは必要な依存関係で構成されています。
    # pyproject.toml content [project] name = "ros2-mcp-server" version = "0.1.0" description = "ROS 2 MCP Server" readme = "README.md" requires-python = ">=3.10" dependencies = [ "fastmcp", "numpy", ]
  4. UV環境を作成:
    uv venv --python /usr/bin/python3.10
  5. 仮想環境をアクティブ化します:
    source .venv/bin/activate
    コマンド プロンプトの先頭に(.venv)が表示され、仮想環境がアクティブであることがわかります。
  6. 依存関係をインストール:
    uv pip install -e .

MCP サーバーの構成

このサーバーをClaudeや他のMCPクライアントで使用するには、MCPサーバーとして設定する必要があります。設定方法は次のとおりです。

クロードデスクトップ向け

  1. Claude Desktop の設定を開き、MCP サーバー セクションに移動します。
  2. 次の構成で新しい MCP サーバーを追加します。
    "ros2-mcp-server": { "autoApprove": [], "disabled": false, "timeout": 60, "command": "uv", "args": [ "--directory", "/path/to/ros2-mcp-server", "run", "bash", "-c", "export ROS_LOG_DIR=/tmp && source /opt/ros/humble/setup.bash && python3 /path/to/ros2-mcp-server/ros2-mcp-server.py" ], "transportType": "stdio" }
    重要/path/to/ros2-mcp-serverリポジトリの実際のパスに置き換えてください。例えば、リポジトリを/home/user/projects/ros2-mcp-serverにクローンした場合は、そのパスを使用してください。
  3. 設定を保存し、Claude を再起動します。

Cline(VSCode拡張機能)の場合

  1. VSCode で、サイドバーの Cline アイコンをクリックして、Cline 拡張機能の設定を開きます。
  2. MCP サーバーの構成セクションに移動します。
  3. 次の構成で新しい MCP サーバーを追加します。
    "ros2-mcp-server": { "autoApprove": [], "disabled": false, "timeout": 60, "command": "uv", "args": [ "--directory", "/path/to/ros2-mcp-server", "run", "bash", "-c", "export ROS_LOG_DIR=/tmp && source /opt/ros/humble/setup.bash && python3 /path/to/ros2-mcp-server/ros2-mcp-server.py" ], "transportType": "stdio" }
    重要: Claude Desktop の例のように/path/to/ros2-mcp-serverリポジトリへの実際のパスに置き換えます。
  4. VSCode を再起動したり拡張機能を再ロードしたりすることなく、Cline MCP 設定インターフェースから直接サーバーのオン/オフを切り替えて接続を確認できます。

使用法

MCP サーバーが設定されると、Claude を使用してロボットにコマンドを送信できるようになります。

  1. コマンド例: クロードにロボットを 0.2 m/s で 5 秒間前進させるように指示します。
    Please make the robot move forward at 0.2 m/s for 5 seconds.
  2. ツールの直接使用: move_robotツールを直接使用することもできます。
    { "linear": [0.2, 0.0, 0.0], "angular": [0.0, 0.0, 0.0], "duration": 5.0 }
  3. ROS 2 トピックの監視: /cmd_velトピックの出力を確認します。
    ros2 topic echo /cmd_vel

テスト

  1. シミュレーターの場合
    • ROS 2 互換シミュレータ (例: TurtleBot3 を搭載した Gazebo) を起動します。
      export TURTLEBOT3_MODEL=burger ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
    • クロードを使用して移動コマンドを送信します。
    • Gazebo でロボットが移動する様子を観察します。
  2. 本物のロボットと一緒に
    • ロボットが/cmd_velトピックにサブスクライブするように適切に設定されていることを確認します。
    • クロードを使用して移動コマンドを送信します。
    • ロボットはコマンドに従って動くはずです。
  3. 期待される出力:
    • サーバーは移動コマンドと停止コマンドを記録します。
    • クロードは次のような応答を受け取ります: "Successfully moved for 5.0 seconds and stopped"

トラブルシューティング

  • ROS 2 ログ エラー: ログ ディレクトリ エラーが発生した場合は、 ROS_LOG_DIR環境変数が書き込み可能なディレクトリ (例: /tmp ) に設定されていることを確認してください。
  • Python バージョンの不一致: ROS 2 Humble はこのバージョン用にビルドされているため、Python 3.10 を使用していることを確認してください。
  • 接続エラー: Claude が「接続が閉じられました」というエラーを報告する場合は、MCP サーバーの構成が正しいこと、およびすべての依存関係がインストールされていることを確認してください。

ディレクトリ構造

ros2-mcp-server/ ├── ros2-mcp-server.py # Main server script integrating FastMCP and ROS 2 ├── pyproject.toml # Project dependencies and metadata ├── .python-version # Python version specification ├── .gitignore # Git ignore file └── README.md # This file

制限事項

  • 単一トピック: 現在、 Twistメッセージで/cmd_velをサポートしています。他のトピックやサービスについては、 ros2-mcp-server.pyを拡張してください。
  • 基本コマンド: 現在はシンプルな移動コマンドをサポートしています。より複雑な動作には追加の実装が必要です。

ライセンス

MIT License Copyright (c) 2025 kakimochi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

このプロジェクトでは、Apache License 2.0に基づいてライセンスされているFastMCPを使用しています。FastMCPコンポーネントの使用にも、このライセンスの条項が適用されます。

謝辞

-
security - not tested
F
license - not found
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

モデル コンテキスト プロトコル (MCP) を ROS 2 と統合し、/cmd_vel トピックを介してロボットの動きに変換する自然言語コマンドを可能にすることで、AI アシスタントがロボットを制御できるようにする Python ベースのサーバーです。

  1. 特徴
    1. 前提条件
      1. インストール
        1. MCP サーバーの構成
          1. クロードデスクトップ向け
          2. Cline(VSCode拡張機能)の場合
        2. 使用法
          1. テスト
            1. トラブルシューティング
              1. ディレクトリ構造
                1. 制限事項
                  1. ライセンス
                    1. 謝辞

                      Related MCP Servers

                      • -
                        security
                        A
                        license
                        -
                        quality
                        A Model Context Protocol (MCP) integration that allows AI assistants to control Home Assistant devices by searching for entities and controlling devices through natural language commands.
                        Last updated -
                        10
                        Python
                        MIT License
                        • Linux
                        • Apple
                      • A
                        security
                        A
                        license
                        A
                        quality
                        An MCP (Model Context Protocol) server that integrates with the ArgoCD API, enabling AI assistants and large language models to manage ArgoCD applications and resources through natural language interactions.
                        Last updated -
                        10
                        6
                        Python
                        MIT License
                        • Linux
                        • Apple
                      • A
                        security
                        A
                        license
                        A
                        quality
                        A server that enables AI assistants to execute terminal commands and retrieve outputs via the Model Context Protocol (MCP).
                        Last updated -
                        3
                        6
                        Python
                        MIT License
                        • Apple
                        • Linux
                      • -
                        security
                        F
                        license
                        -
                        quality
                        A Model Context Protocol server that allows AI assistants to interact with Prefect's workflow automation platform through natural language, enabling users to manage flows, deployments, tasks, and other Prefect resources via conversational commands.
                        Last updated -
                        4
                        Python

                      View all related MCP servers

                      ID: 2itbnro6c4