Sponsored by Deepsite.site

Mbotmcp

Created By
deemkeen10 months ago
Content

MBotMcp

https://github.com/user-attachments/assets/a11d68c5-dc52-4dab-9741-bc1cf47e2ec9

This project demonstrates how to control an mBot2 robot using Spring AI and Model Context Protocol (MCP). With this setup, AI models can control a physical robot through simple natural language commands like "explore" or "turn left".

Overview

The system consists of:

  1. A Spring Boot application that implements the Model Context Protocol
  2. An MQTT broker for message passing
  3. Python code running on the mBot2 robot
  4. AI client integration capabilities

The Spring application exposes robot control commands as AI-callable functions, allowing AI models to control the physical robot through natural language.

Prerequisites

  • Java 21
  • Maven
  • mBot2 robot and mBlock IDE
  • MQTT broker (can run in Docker)
  • Basic Java knowledge

Setup Instructions

1. MQTT Broker Setup (Optional, if you don't have one)

Run the included Docker Compose file to set up the MQTT broker:

cd mbotmcp/assets
docker-compose up -d

This creates a message queue that will relay commands between your app and robot.

2. Configure Spring Boot Application

Set the following environment variables:

MQTT_USERNAME=your_username # leave blank if not configured
MQTT_PASSWORD=your_password # leave blank if not configured
MQTT_SERVER_URI=tcp://your_server:1883

These tell your app how to connect to the MQTT broker.

3. mBot2 Setup

To upload the Python script to your mBot2:

  1. Connect your mBot2 to your computer via USB
  2. Open the mBlock IDE on your computer
  3. Click on the "File" menu and select "Open"
  4. Navigate to the /assets directory in the repository
  5. Open the mbot-mqtt.py file
  6. Modify the script to include your personal WiFi and MQTT configurations:
    ssid = "<your wifi ssid>"
    ssid_password = "<your wifi password>"
    mqtt_ip = "<ip of the mqtt broker>"
    mqtt_port = 1883
    mqtt_user = "<your mqtt username>"
    mqtt_password = "<your mqtt password>"
    
  7. Upload the script to your mBot2
  8. Power on your mBot2

4. Build the Spring Boot App

mvn clean package

Testing the Setup

  1. Ensure your MQTT broker is running
  2. Power on your mBot2 and ensure it's connected to WiFi
  3. Run the test client:
    mvn test -Dtest=ClientStdioTest
    
  4. Watch your robot perform the "beep" command with blue LED lights!

Available Robot Commands

The BotService class defines all the MCP tools, your robot can understand:

  • mbotExplore() - Execute the 'explore' routine
  • mbotStop() - Stop the robot
  • mbotBeep() - Make the robot beep
  • mbotLeft() - Turn the robot left
  • mbotRight() - Turn the robot right
  • mbotForward() - Move the robot forward
  • mbotBackward() - Move the robot backward

Integration with AI Models

Once everything is working, you can integrate with LLM clients that support MCP. Personally, I would recommend Goose for this purpose. Just point these clients to your server, and they can autonomously control your robot based on natural language requests.

Example natural language commands:

  • "Explore the room"
  • "Turn right and go forward"
  • "Make a beep sound"

How It Works

  1. The Spring application exposes robot commands as tools using the @Tool annotation
  2. The MCP server in Spring connects these tools to the outside world
  3. When an AI wants to control your robot, it calls these methods through the protocol
  4. Commands are sent via MQTT to the robot
  5. The robot executes the commands based on the received message

Disclaimer

If your robot starts planning world domination, the author accepts no responsibility. Just unplug it and run! 😂

License

MIT License

Server Config

{
  "mcpServers": {
    "mbotmcp": {
      "command": "path-to-java-executable",
      "args": [
        "-jar",
        "/path-to-repo/mbotmcp/target/mbotmcp-0.0.1-SNAPSHOT.jar"
      ],
      "env": {
        "MQTT_USERNAME": "<mqtt server username>",
        "MQTT_PASSWORD": "<mqtt server password>",
        "MQTT_SERVER_URI": "mqtt server url"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Tavily Mcp
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Playwright McpPlaywright MCP server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
CursorThe AI Code Editor
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Serper MCP ServerA Serper MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Amap Maps高德地图官方 MCP Server
ChatWiseThe second fastest AI chatbot™