Modbus MCP Server

Modbus MCP Server

Standardizes Modbus data for seamless AI integration via the Model Context Protocol.

18
Stars
7
Forks
18
Watchers
0
Issues
Modbus MCP Server provides an MCP-compliant interface that standardizes and contextualizes Modbus device data for use with AI agents and industrial IoT systems. It supports flexible Modbus connections over TCP, UDP, or serial interfaces and offers a range of Modbus tools for reading and writing registers and coils. With customizable prompts and structured tool definitions, it enables natural language-driven interactions and analysis of Modbus data within AI workflows. The solution is designed to ensure interoperability and easy configuration within MCP-compatible environments.

Key Features

Standardizes and contextualizes Modbus device data for AI use
Supports Modbus over TCP, UDP, and serial connections
Read and write holding registers and coils
Customizable prompts for analyzing register values
Tool-based structured interaction using JSON
Environment variable-based configuration
Active compatibility with Claude Desktop and MCP Inspector
Flexibility for different industrial Modbus setups
Easy dependency management with uv
Integration-ready for AI agent workflows

Use Cases

Integrating industrial Modbus devices with AI agents for automation
Aggregating and contextualizing real-time data from industrial sensors
Providing a standardized entry point for AI-driven industrial IoT management
Enabling natural language queries and control of Modbus hardware
Facilitating predictive maintenance using AI on Modbus-connected equipment
Remote monitoring and control of factory devices via an MCP-compatible server
Seamless Modbus operations within AI-driven digital twins
Streamlining configuration and communication with legacy industrial systems
Prototyping and developing new AI-powered solutions for OT environments
Secure, tool-based access to Modbus operations for advanced analytics

README

Modbus MCP Server

An MCP server that standardizes and contextualizes Modbus data, enabling seamless integration of AI agents with industrial IoT systems.

GitHub License Python Version Status

Features

  • Modbus Tools:
    • Read/write holding registers (read_register, write_register).
    • Read/write coils (read_coils, write_coil).
    • Read input registers (read_input_registers).
    • Read multiple holding registers (read_multiple_holding_registers).
  • Prompt: Analyze Modbus register values with a customizable prompt (analyze_register).
  • Flexible Connections: Supports Modbus over TCP, UDP, or serial, configured via environment variables.

Requirements

  • Python: 3.10
  • uv for dependency and virtual environment management.

Installation

  1. Install uv:

    bash
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone the Repository:

    bash
    git clone https://github.com/kukapay/modbus-mcp.git
    cd modbus-mcp
    
  3. Install Dependencies:

    bash
    uv sync
    

Configuration

The server connects to a Modbus device using parameters specified via environment variables. Set these variables in a .env file or your shell environment.

Environment Variables

Variable Description Default Required
MODBUS_TYPE Connection type: tcp, udp, or serial tcp Yes
MODBUS_HOST Host address for TCP/UDP 127.0.0.1 For TCP/UDP
MODBUS_PORT Port for TCP/UDP 502 For TCP/UDP
MODBUS_DEFAULT_SLAVE_ID Slave ID 1 For TCP/UDP
MODBUS_SERIAL_PORT Serial port (e.g., /dev/ttyUSB0, COM1) /dev/ttyUSB0 For serial
MODBUS_BAUDRATE Serial baud rate 9600 For serial
MODBUS_PARITY Serial parity: N (none), E (even), O (odd) N For serial
MODBUS_STOPBITS Serial stop bits 1 For serial
MODBUS_BYTESIZE Serial byte size 8 For serial
MODBUS_TIMEOUT Serial timeout (seconds) 1 For serial

Example .env File

For TCP:

MODBUS_TYPE=tcp
MODBUS_HOST=192.168.1.100
MODBUS_PORT=502
MODBUS_SLAVE_ID=1

For Serial:

MODBUS_TYPE=serial
MODBUS_SERIAL_PORT=/dev/ttyUSB0
MODBUS_BAUDRATE=9600
MODBUS_PARITY=N
MODBUS_STOPBITS=1
MODBUS_BYTESIZE=8
MODBUS_TIMEOUT=1

Usage

Installing for Claude Desktop

The configuration file:

json
{
   "mcpServers": {
       "Modbus MCP Server": {
           "command": "uv",
           "args": [ "--directory", "/path/to/modbus-mcp", "run", "modbus-mcp" ],
           "env": { "MODBUS_TYPE": "tcp", "MODBUS_HOST": "127.0.0.1", "MODBUS_PORT": 502 },
       }
   }
}

Using Tools

Note: Natural language support depends on the client’s ability to parse and map prompts to tools. The MCP Inspector requires structured JSON, but the examples below show how conversational inputs translate.

  1. Read a Holding Register:

    • Prompt:
      Please read the value of Modbus holding register 0.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "read_register",
        "parameters": {"address": 0, "slave_id": 1}
      }
      
    • Expected Output: Value: <register_value>
  2. Write to a Holding Register:

    • Prompt:
      Set Modbus holding register 10 to the value 100.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "write_register",
        "parameters": {"address": 10, "value": 100, "slave_id": 1}
      }
      
    • Expected Output: Successfully wrote 100 to register 10
  3. Read Coils:

    • Prompt:
      Check the status of the first 5 Modbus coils starting at address 0.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "read_coils",
        "parameters": {"address": 0, "count": 5, "slave_id": 1}
      }
      
    • Expected Output: Coils 0 to 4: [False, False, False, False, False]
  4. Write to a Coil:

    • Prompt:
      Turn on Modbus coil 5.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "write_coil",
        "parameters": {"address": 5, "value": true, "slave_id": 1}
      }
      
    • Expected Output: Successfully wrote True to coil 5
  5. Read Input Registers:

    • Prompt:
      Read the values of 3 Modbus input registers starting from address 2.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "read_input_registers",
        "parameters": {"address": 2, "count": 3, "slave_id": 1}
      }
      
    • Expected Output: Input Registers 2 to 4: [<value1>, <value2>, <value3>]
  6. Read Multiple Holding Registers:

    • Prompt:
      Get the values of Modbus holding registers 0 through 2.
      
    • MCP Inspector JSON:
      json
      {
        "tool": "read_multiple_holding_registers",
        "parameters": {"address": 0, "count": 3, "slave_id": 1}
      }
      
    • Expected Output: Holding Registers 0 to 2: [<value1>, <value2>, <value3>]

License

This project is licensed under the MIT License. See LICENSE for details.

Star History

Star History Chart

Repository Owner

kukapay
kukapay

User

Repository Details

Language Python
Default Branch main
Size 32 KB
Contributors 2
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

Python
100%

Tags

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • OPC UA MCP Server

    OPC UA MCP Server

    Bridge AI agents with OPC UA industrial systems in real time.

    OPC UA MCP Server enables seamless integration of AI agents with OPC UA-enabled industrial automation systems. It provides real-time monitoring, analysis, and control of operational data through a set of standardized tool APIs. Supporting both reading and writing of OPC UA nodes, the server facilitates natural language interaction by exposing tools for AI-driven automation and control workflows.

    • 20
    • MCP
    • kukapay/opcua-mcp
  • OpenAI MCP Server

    OpenAI MCP Server

    Bridge between Claude and OpenAI models using the MCP protocol.

    OpenAI MCP Server enables direct querying of OpenAI language models from Claude via the Model Context Protocol (MCP). It provides a configurable Python server that exposes OpenAI APIs as MCP endpoints. The server is designed for seamless integration, requiring simple configuration updates and environment variable setup. Automated testing is supported to verify connectivity and response from the OpenAI API.

    • 77
    • MCP
    • pierrebrunelle/mcp-server-openai
  • Codex MCP Server

    Codex MCP Server

    An MCP-compatible server delivering enriched blockchain data for AI models.

    Codex MCP Server implements the Model Context Protocol to provide enriched blockchain data from Codex. It is compatible with MCP clients such as Claude Desktop and Claude CLI, allowing seamless integration in AI workflows that require blockchain context. Users can run the server locally or via npx, and configure it for various MCP-compatible tools using their Codex API key.

    • 20
    • MCP
    • Codex-Data/codex-mcp
  • CipherTrust Manager MCP Server

    CipherTrust Manager MCP Server

    Enables AI assistants to access CipherTrust Manager securely via the Model Context Protocol.

    CipherTrust Manager MCP Server provides an implementation of the Model Context Protocol (MCP), offering AI assistants such as Claude and Cursor a unified interface to interact with CipherTrust Manager resources. Communication is facilitated through JSON-RPC over stdin/stdout, enabling key management, CTE client management, user management, and connection management functionalities. The tool is configurable via environment variables and integrates with existing CipherTrust Manager instances using the ksctl CLI for secure resource access.

    • 7
    • MCP
    • sanyambassi/ciphertrust-manager-mcp-server
  • Lucidity MCP

    Lucidity MCP

    Intelligent prompt-based code quality analysis for AI coding assistants.

    Lucidity MCP is a Model Context Protocol (MCP) server that empowers AI coding assistants to deliver high-quality code through intelligent, prompt-driven analysis. It offers comprehensive detection of code issues across multiple quality dimensions, providing structured and actionable feedback. With language-agnostic capabilities, extensible framework, and flexible transport options, Lucidity MCP seamlessly integrates into developer workflows and AI systems.

    • 72
    • MCP
    • hyperb1iss/lucidity-mcp
  • Unichat MCP Server

    Unichat MCP Server

    Universal MCP server providing context-aware AI chat and code tools across major model vendors.

    Unichat MCP Server enables sending standardized requests to leading AI model vendors, including OpenAI, MistralAI, Anthropic, xAI, Google AI, DeepSeek, Alibaba, and Inception, utilizing the Model Context Protocol. It features unified endpoints for chat interactions and provides specialized tools for code review, documentation generation, code explanation, and programmatic code reworking. The server is designed for seamless integration with platforms like Claude Desktop and installation via Smithery. Vendor API keys are required for secure access to supported providers.

    • 37
    • MCP
    • amidabuddha/unichat-mcp-server
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results