An MCP server that executes ROS 2 (ros2) CLI commands
Project description
ROS2 Exec MCP Server
A Model Context Protocol (MCP) server that executes ROS 2 (ros2) CLI commands via stdio. This follows the same structure and coding rules as the reference uvx datetime MCP server, but provides a single tool to run ros2 commands.
Features
- Execute ROS 2 CLI commands (e.g.,
ros2 topic list,ros2 node list) - Configurable default timeout via environment variable
- Optional working directory control
- Secure by default: only allows commands starting with
ros2(overridable)
Usage
Configure your MCP client to launch this server with uvx:
{
"mcpServers": {
"ros2": {
"command": "uvx",
"args": ["takanarishimbo-ros2-exec-mcp"],
"env": {
"ROS2_EXEC_TIMEOUT": "30"
}
}
}
}
You can also set a default working directory or allow non-ros2 commands:
{
"mcpServers": {
"ros2": {
"command": "uvx",
"args": ["takanarishimbo-ros2-exec-mcp"],
"env": {
"ROS2_EXEC_TIMEOUT": "60",
"DEFAULT_CWD": "/your/ros2/ws",
"ALLOW_NON_ROS2": "false"
}
}
}
}
Environment Variables
ROS2_EXEC_TIMEOUT: Default timeout seconds for command execution (default:30)DEFAULT_CWD: Default working directory for command execution (optional)ALLOW_NON_ROS2: If set totrue, allows executing non-ros2commands (default:false)
Available Tools
ros2_exec
Execute a ROS 2 CLI command.
Parameters:
command(required): Full command string, e.g.,"ros2 topic list"timeout(optional): Timeout seconds (overridesROS2_EXEC_TIMEOUT)cwd(optional): Working directory (overridesDEFAULT_CWD)
Returns combined stdout/stderr and exit code.
Development
-
Clone and install dependencies with
uv:uv sync -
Run the server:
uv run takanarishimbo-ros2-exec-mcp
-
Test with MCP Inspector (optional):
npx @modelcontextprotocol/inspector uv run takanarishimbo-ros2-exec-mcp
Publishing to PyPI
This project uses PyPI's Trusted Publishers feature for secure, token-less publishing via GitHub Actions.
1. Configure PyPI Trusted Publisher
-
Log in to PyPI (create account if needed)
- Go to https://pypi.org/
-
Navigate to Publishing Settings
- Go to your account settings
- Click on "Publishing" or go to https://pypi.org/manage/account/publishing/
-
Add GitHub Publisher
- Click "Add a new publisher"
- Select "GitHub" as the publisher
- Fill in:
- Owner:
TakanariShimbo(your GitHub username/org) - Repository:
ros2-exec-mcp - Workflow name:
pypi-publish.yml - Environment:
pypi(optional but recommended)
- Owner:
- Click "Add"
2. Configure GitHub Environment (Recommended)
-
Navigate to Repository Settings
- Go to your GitHub repository
- Click "Settings" → "Environments"
-
Create PyPI Environment
- Click "New environment"
- Name:
pypi - Configure protection rules (optional):
- Add required reviewers
- Restrict to specific branches/tags
3. Setup GitHub Personal Access Token (for release script)
The release script needs to push to GitHub, so you'll need a GitHub token:
-
Create GitHub Personal Access Token
- Go to https://github.com/settings/tokens
- Click "Generate new token" → "Generate new token (classic)"
- Set expiration (recommended: 90 days or custom)
- Select scopes:
- ✅
repo(Full control of private repositories)
- ✅
- Click "Generate token"
- Copy the generated token (starts with
ghp_)
-
Configure Git with Token
# Option 1: Use GitHub CLI (recommended) gh auth login # Option 2: Configure git to use token git config --global credential.helper store # Then when prompted for password, use your token instead
4. Release New Version
Use the release script to automatically version, tag, and trigger publishing:
# First time setup
chmod +x scripts/release.sh
# Increment patch version (0.1.0 → 0.1.1)
./scripts/release.sh patch
# Increment minor version (0.1.0 → 0.2.0)
./scripts/release.sh minor
# Increment major version (0.1.0 → 1.0.0)
./scripts/release.sh major
# Set specific version
./scripts/release.sh 1.2.3
5. Verify Publication
-
Check GitHub Actions
- Go to "Actions" tab in your repository
- Verify the "Publish to PyPI" workflow completed successfully
-
Verify PyPI Package
- Visit: https://pypi.org/project/takanarishimbo-ros2-exec-mcp/
- Or run:
pip show takanarishimbo-ros2-exec-mcp
Release Process Flow
release.shscript updates version in all files- Creates git commit and tag
- Pushes to GitHub
- GitHub Actions workflow triggers on new tag
- Workflow uses OIDC to authenticate with PyPI (no tokens needed!)
- Workflow builds project and publishes to PyPI
- Package becomes available globally via
pip installoruvx
Code Quality
Uses ruff for linting and formatting:
uv run ruff check
uv run ruff check --fix
uv run ruff format
Project Structure
ros2-exec-mcp/
├── src/
│ ├── __init__.py
│ ├── __main__.py
│ └── server.py
├── pyproject.toml
├── uv.lock
├── .github/
│ └── workflows/
│ └── pypi-publish.yml
├── scripts/
│ └── release.sh
├── docs/
│ ├── README.md
│ └── README_ja.md
└── .gitignore
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file takanarishimbo_ros2_exec_mcp-0.1.0.tar.gz.
File metadata
- Download URL: takanarishimbo_ros2_exec_mcp-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13d1c8800200717c0fb60c95465441e292d79f557eb07727c7e943b9275d99a5
|
|
| MD5 |
078c0974c914756c791c7c8c52bf5d8f
|
|
| BLAKE2b-256 |
5381a1b21019fae07f4f503f87fa80c8464eb02161fd99295c1404158ea36a29
|
File details
Details for the file takanarishimbo_ros2_exec_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: takanarishimbo_ros2_exec_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed90bb3cdccd0e83eb8db456cf467b2e0665e990219733f3f1190e5f30d0a347
|
|
| MD5 |
3f373fc56a541ce6a647f69a18367f26
|
|
| BLAKE2b-256 |
963fb6f745dde1aca97a90bb6f7c1eff8cd689176d3507e9318ed45bc837621c
|