Skip to main content

An MCP server that executes ROS 2 (ros2) CLI commands

Project description

English | 日本語 | README

ROS2 Exec MCP Server

A Model Context Protocol (MCP) server that executes ROS 2 (ros2) CLI 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

Below are examples for both stdio and streamable-http.

Stdio (default)

MCP client example:

{
  "mcpServers": {
    "ros2": {
      "command": "uvx",
      "args": ["takanarishimbo-ros2-exec-mcp"]
    }
  }
}

You can also configure timeout, 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": "true",
        "MCP_TRANSPORT": "stdio"
      }
    }
  }
}

streamable-http

Start the MCP server on the robot side first:

MCP_TRANSPORT=streamable-http uv run takanarishimbo-ros2-exec-mcp

MCP client example:

{
  "mcpServers": {
    "ros2": {
      "url": "http://xxx.xxx.xxx.xxx:8000",
      "env": {
        "MCP_TRANSPORT": "streamable-http"
      }
    }
  }
}

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 to true, allows executing non-ros2 commands (default: false)
  • MCP_TRANSPORT: Transport mode. stdio (default) or streamable-http

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 (overrides ROS2_EXEC_TIMEOUT)
  • cwd (optional): Working directory (overrides DEFAULT_CWD)

Returns combined stdout/stderr and exit code.

Development

  1. Clone and install dependencies with uv:

    uv sync
    
  2. Run the server:

    uv run takanarishimbo-ros2-exec-mcp
    
  3. 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

  1. Log in to PyPI (create account if needed)

  2. Navigate to Publishing Settings

  3. 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)
    • Click "Add"

2. Configure GitHub Environment (Recommended)

  1. Navigate to Repository Settings

    • Go to your GitHub repository
    • Click "Settings" → "Environments"
  2. 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:

  1. 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_)
  2. 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

  1. Check GitHub Actions

    • Go to "Actions" tab in your repository
    • Verify the "Publish to PyPI" workflow completed successfully
  2. Verify PyPI Package

Release Process Flow

  1. release.sh script updates version in all files
  2. Creates git commit and tag
  3. Pushes to GitHub
  4. GitHub Actions workflow triggers on new tag
  5. Workflow uses OIDC to authenticate with PyPI (no tokens needed!)
  6. Workflow builds project and publishes to PyPI
  7. Package becomes available globally via pip install or uvx

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

takanarishimbo_ros2_exec_mcp-0.2.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

takanarishimbo_ros2_exec_mcp-0.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file takanarishimbo_ros2_exec_mcp-0.2.0.tar.gz.

File metadata

File hashes

Hashes for takanarishimbo_ros2_exec_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 41ff044af96958b6ffdb9f4b9d8c303d8b76b1dad64ff46d44caf40c3d126e7b
MD5 f3349f7012a4445a9f925df027f5ce85
BLAKE2b-256 c9c39464461e4f808ab2f237efc4832d8c6fb0c1008da3b7c787e78b0b6eabed

See more details on using hashes here.

File details

Details for the file takanarishimbo_ros2_exec_mcp-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for takanarishimbo_ros2_exec_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24bbe52a0d0002cde7a2b32a2f5ce5693c15ce8d9e2f5afdb4d4b65551fa7512
MD5 976384775263dc2e9fd9c1bcff68ba6a
BLAKE2b-256 c23e57619751884983d0df95dfcce4c101629a66568d384fd70e89ef70f69363

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page