
Mbotmcp
deemkeen
README
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:
- A Spring Boot application that implements the Model Context Protocol
- An MQTT broker for message passing
- Python code running on the mBot2 robot
- 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:
- Connect your mBot2 to your computer via USB
- Open the mBlock IDE on your computer
- Click on the "File" menu and select "Open"
- Navigate to the
/assets
directory in the repository - Open the
mbot-mqtt.py
file - 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>"
- Upload the script to your mBot2
- Power on your mBot2
4. Build the Spring Boot App
mvn clean package
Testing the Setup
- Ensure your MQTT broker is running
- Power on your mBot2 and ensure it's connected to WiFi
- Run the test client:
mvn test -Dtest=ClientStdioTest
- 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' routinembotStop()
- Stop the robotmbotBeep()
- Make the robot beepmbotLeft()
- Turn the robot leftmbotRight()
- Turn the robot rightmbotForward()
- Move the robot forwardmbotBackward()
- 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
- The Spring application exposes robot commands as tools using the
@Tool
annotation - The MCP server in Spring connects these tools to the outside world
- When an AI wants to control your robot, it calls these methods through the protocol
- Commands are sent via MQTT to the robot
- 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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
MCP Package Docs Server
Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.
Claude Code MCP
An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.
@kazuph/mcp-taskmanager
Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.
Linear MCP Server
Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.
mermaid-mcp-server
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.
Jira-Context-MCP
MCP server to provide Jira Tickets information to AI coding agents like Cursor

Linear MCP Server
A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.