西门子PLC通信服务

MCP服务器实现Python与西门子PLC的交互,支持连接、读写数据块、内存字节、定时器、计数器等操作。

  • by daedalus
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 daedalus/mcp-snap7

使用说明

mcp-snap7

用于python-snap7的MCP服务器,使MCP客户端能够与西门子PLC交互

安装

pip install mcp-snap7

需求

  • python-snap7要求在您的系统上安装libsnap7库。 看 python-snap7文档 有关安装说明。

用法

作为MCP服务器

配置您的MCP客户端以使用 mcp-snap7 作为stdio服务器:

{
  "mcpServers": {
    "mcp-snap7": {
      "command": "mcp-snap7"
    }
  }
}

可用工具

  • connect_plc -连接到西门子PLC
  • disconnect_plc -断开与PLC的连接
  • get_connected -检查连接状态
  • db_read / db_write -读/写数据块
  • mb_read / mb_write -读/写内存字节
  • tm_read / tm_write -读/写定时器
  • ct_read / ct_write -读/写计数器
  • eb_read / eb_write -读/写边缘输入
  • ab_read / ab_write -读/写绝对字节数
  • get_cpu_info -获取CPU信息
  • get_cpu_state -获取CPU状态
  • get_protection -获取PLC保护级别
  • plc_cold_start -触发冷启动
  • plc_hot_start -触发热启动
  • plc_stop -停止PLC
  • get_error_text -获取错误描述

发展

git clone https://github.com/daedalus/mcp-snap7.git
cd mcp-snap7
pip install -e ".[test]"

# run tests
pytest

# format
ruff format src/ tests/

# lint
ruff check src/ tests/

# type check
mypy src/