返回市场
MCP桥服务器

MCP桥服务器

作者:cadugrillo4 星标更新:2025-11-15

项目介绍

<p align="left"> <img title="s7-mcp-bridge" src='https://raw.githubusercontent.com/cadugrillo/s7-mcp-bridge/main/logo.png' width="110" height="110"/> </p>

S7 MCP Bridge

S7 MCP Bridge 是一个连接AI代理到西门子工业PLC(特别是S7-1500和S7-1200型号)的MCP服务器。这使得AI代理能够通过发送命令和接收数据来自动监控和控制工业设备。


🔧 可用工具

  • 用户认证 (Api-Login, Api-Logout, Api-ChangePassword)
  • 检查PLC连接性 (Api-Ping)
  • 获取用户权限 (Api-GetPermissions)
  • 获取API版本 (Api-Version)
  • 列出可用的API方法 (Api-Browse)
  • 获取结构信息 (Api-GetQuantityStructures)
  • 获取密码安全策略 (Api-GetPasswordPolicy)
  • 浏览标签和元数据 (PlcProgram-Browse)
  • 读取单个变量 (PlcProgram-Read)
  • 写入布尔值、数字或字符串标签 (PlcProgram-Write)
  • 读取当前CPU操作模式 (Plc-ReadOperatingMode)
  • 请求更改操作模式 (Plc-RequestChangeOperatingMode)
  • 读取CPU系统时间 (Plc-ReadSystemTime)
  • 设置CPU系统时间 (Plc-SetSystemTime)
  • 读取可用项目语言 (Project-ReadLanguages)
  • 浏览活动警报 (Alarms-Browse)
  • 确认警报 (Alarms-Acknowledge)
  • 浏览诊断缓冲区条目 (DiagnosticBuffer-Browse)
  • 列出所有已配置的PLC(通过环境变量)(List-AvailablePlcs)
  • 创建CPU备份文件 (Plc-CreateBackup)
  • 删除由系统提供的票据 (Api-CloseTicket)

⚙️ 先决条件

  • Node.js(推荐使用v18.x或更高版本)
  • npm(与Node.js捆绑提供)
  • 访问正在运行的SIEMENS PLC API(Webserver)

⚙️ 配置

此服务器使用环境变量进行配置。

示例 env variables

export PLC_IP_ADDRESSES="192.168.2.200, 192.168.2.201, 192.168.2.202"
export PLC_NAMES="PLC1, PLC2, PLC3" //可选
export MCP_SERVER_PORT=57001 //可选
export TRANSPORT="http-stream" //可选

🚀 开始使用(开发)

  1. 使用Git克隆此仓库:https://github.com/cadugrillo/s7-mcp-bridge.git

  2. 导航到项目文件夹:

cd s7-mcp-bridge
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build
  1. 如上所示编辑环境变量。

  2. 启动服务器

npm run start

🐳 Docker容器

可以在https://hub.docker.com/r/cadugrillo/s7-mcp-bridge/tags找到Docker容器镜像。

  • 运行方式
docker run -d -p 57001:57001 -p 57002:57002 -m 512m --memory-swap=512m \
--name s7McpBridge \
-e MCP_SERVER_PORT=57001 \
-e PLC_IP_ADDRESSES="192.168.2.200, 192.168.2.201, 192.168.2.202" \
-e PLC_NAMES="PLC1, PLC2, PLC3" \
cadugrillo/s7-mcp-bridge:latest

请根据您的部署更改端口。 当TRANSPORT设置为“http-stream”时,在http://<server-ip-address>:[MCP_SERVER_PORT +1]/status有一个状态页面。

  • 可用环境变量
PLC_IP_ADDRESSES必需以逗号分隔的可用PLC的IP地址,例如:"192.168.1.10, 192.168.1.20"
PLC_NAMES可选以逗号分隔的可用PLC的名称,例如:"Machine1, Machine2"
MCP_SERVER_PORT可选如果未设置,默认为57001,状态页面在http://<server-ip-address>:57002/status
TRANSPORT可选可以是"http-stream"或"stdio"。如果未设置,默认为http-stream

🖥️ 与Claude Desktop连接

  1. https://github.com/cadugrillo/s7-mcp-bridge/tree/main/claude_extension安装Claude扩展(s7-mcp-bridge-vx.x.x.mcpb)。

  2. 或者作为Docker容器运行,选择其中一个选项(stdio或http-stream):

  • (stdio)查找或创建claude_desktop_config.json文件(通常在Claude应用配置文件夹中),并添加以下内容:
{
    "mcpServers": {
        "S7-MCP-Bridge": {
            "command": "docker",
            "args": [
                "run",
                "-i",
                "--rm",
                "-e",
                "PLC_IP_ADDRESSES=192.168.2.200, 192.168.2.201, 192.168.2.202",
                "-e",
                "PLC_NAMES=PLC1, PLC2, PLC3",
                "-e",
                "TRANSPORT=stdio",
                "cadugrillo/s7-mcp-bridge:latest"
            ]
        }
    }
}
  • (http-stream)或者运行Docker容器(如上所述),并添加以下内容(记得根据您的部署更改端口):
{
  "mcpServers": {
    "S7-MCP-Bridge": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:57001/mcp"]
    }
  }
}
  1. 或者,如果您本地运行用于开发(stdio):
{
  "mcpServers": {
    "S7-MCP-Bridge": {
      "command": "node",
      "args": ["path/to/your/index.js"], //对于Windows用户,请正确转义路径(例如:C:\\path\\to\\your\\index.js)
      "env": {
        "PLC_IP_ADDRESSES":"192.168.2.200, 192.168.2.201, 192.168.2.202",
        "PLC_NAMES":"PLC1, PLC2, PLC3",
        "TRANSPORT": "stdio"
      }
    }
  }
}

🪲 报告错误和贡献

  • 想要报告错误或请求功能?请打开一个问题