Skip to main content
Glama
BlackUppsss

cx-programmer-mcp

by BlackUppsss

cx-programmer-mcp

一个用于以编程方式编辑欧姆龙 CX-Programmer 梯形图逻辑程序的 MCP(模型上下文协议)服务器 —— 无需打开图形界面。

适用于 OMRON CJ/CP/CS 系列 PLC.CXP / .CXT 文件。

适用范围:仅包括程序、段(Section)、梯形图助记符、梯级注释和符号表。
不涉及 PLC 设置、I/O 表、网络配置、密码或传输到 PLC。


工作原理

OMRON 将 .CXP 定义为 .CXT 的压缩版本。.CXT 是 CX-Programmer 可以导入/导出的基于文本的格式。该服务器读取 .CXP.CXT,在内存中编辑程序,然后将结果保存为 .CXT / .CXP,以便在部署到真实 PLC 之前在 CX-Programmer 中进行审查。

使用 Python MCP SDK v2(MCPServer),采用 stdio 传输。


Related MCP server: TwinCAT Validator MCP Server

系统要求

  • Python >= 3.10

  • uv 包管理器

  • 已安装 CX-Programmer(用于打开 .cxp 输出并下载到 PLC)


安装

cd cx-programmer-mcp
uv sync
uv run cx-programmer-mcp

项目模板设置

内置模板(CJ2M CPU11)

已包含原生 CJ2M CPU11 模板。生成空白项目:

uv run python make_template.py

其他 PLC 型号

每种 PLC 型号都有不同的二进制配置。对于 CJ2M CPU11 以外的型号:

  1. 在您的机器上打开 CX-Programmer

  2. 为您的 PLC 型号(CP1L、CS1G 等)创建一个新的空项目

  3. 将其保存为 .CXP.CXT

  4. 将文件放入 project/ 文件夹

  5. 更新 make_template.py 以指向您的文件:

SRC = Path(__file__).parent / "project" / "your_blank_template.cxp"
  1. 运行 make_template.py 一次


示例程序

附带一个示例梯形图程序:project/example_basic_io.cxp

它演示了一个简单的传送带/IO 控制器,具有以下功能:

  • 手动输出控制(保持运行)

  • 通过 RTC 定时自动运行(可通过 DM 配置)

  • 基于定时器的持续时间

  • SET/RSET 锁存

  • 紧急复位

要从源码重新构建:

uv run python make_template.py
uv run python build_program.py

输出:project/example_basic_io.cxp —— 在 CX-Programmer 中打开以进行审查和下载。


审查程序

uv run python review_program.py

MCP 客户端配置

添加到您的 MCP 客户端配置(Claude Desktop、Kiro、Cline 等):

{
  "mcpServers": {
    "cx-programmer": {
      "command": "uv",
      "args": ["run", "cx-programmer-mcp"],
      "cwd": "ABSOLUTE_PATH_TO_THIS_FOLDER"
    }
  }
}

Windows 示例:

"cwd": "C:\\Users\\yourname\\cx-programmer-mcp"

可选 —— 将文件访问限制到特定文件夹:

CX_MCP_ALLOWED_ROOTS=C:\PLC_Projects

运行时计划更改

使用 CX-Programmer 在线模式 → PLC 内存 → DM 区

DM

功能

默认值

D0

计划 1 —— 小时

6

D1

计划 1 —— 分钟

0

D2

计划 2 —— 小时

16

D3

计划 2 —— 分钟

0

D4

运行持续时间 x100ms

300(=30 秒)

更改立即生效,无需 PLC 重启。


运行测试

uv run pytest -q

可用的 MCP 工具

工具

描述

load_project

将会话中加载 .cxp.cxt 文件

list_programs

列出项目中的所有程序

list_sections

列出程序中的区段

get_program_context

获取程序的完整梯形图内容

get_rungs

获取某区段中的梯级

replace_rung

替换梯级的指令

insert_rung

插入新梯级

delete_rung

删除梯级

set_rung_comment

设置梯级注释

patch_program

以原子方式批量编辑多个梯级

create_section

添加新区段

rename_section

重命名现有区段

upsert_symbol

添加或更新符号

clear_symbols

清除某作用域中的所有符号

list_symbols

列出所有符号

validate_program

校验 XML 结构

save_cxt

保存为 .cxt

save_cxp

重新编码并保存为 .cxp

list_project_templates

列出可用的内置模板

create_project_from_template

从模板创建新的空白项目

compile_rung

校验助记符指令

simulate_rung

梯级布尔仿真

analyze_rung

分析梯级结构

program_diagnostics

完整的程序诊断

semantic_snapshot

用于 AI 审查的语义快照

launch_in_cx_programmer

保存并在 CX-Programmer 中打开(Windows)


项目结构

cx-programmer-mcp/
├── src/cx_programmer_mcp/     # MCP server and CXT library
│   ├── server.py              # MCP tool definitions
│   ├── cxt.py                 # CXT/CXP parser and editor
│   ├── ladder.py              # Mnemonic compiler and simulator
│   ├── diagnostics.py         # Program diagnostics
│   ├── recipes.py             # Reusable ladder patterns
│   ├── templates/             # Built-in PLC templates
│   │   └── CJ2M_CPU11.cxt     # Native CJ2M CPU11 template
│   └── ...
├── tests/                     # Test suite (16 tests)
├── project/                   # Output folder
│   └── example_basic_io.cxp   # Example ladder program
├── build_program.py           # Builds the example ladder program
├── write_build.py             # Regenerates build_program.py
├── make_template.py           # Generates blank template from base
├── review_program.py          # Prints program content to console
└── pyproject.toml

注意事项

  • 在下载到真实 PLC 之前,请务必在 CX-Programmer 中运行程序检查

  • 此工具仅编辑程序逻辑 —— I/O 表、单元设置和 PLC 配置保持模板原样不变。

  • 输出 .CXP 与 CX-Programmer 9.x 二进制兼容。

  • 对于其他 PLC 型号,请提供您自己的空白 .CXP 模板(参见项目模板设置)。

Install Server
F
license - not found
B
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    C
    maintenance
    An MCP server for validating, auto-fixing, and scaffolding TwinCAT 3 XML files using deterministic code quality tools and IEC 61131-3 OOP checks. It enables AI assistants to perform structural validation, apply safe fixes, and generate canonical code skeletons for industrial automation projects.
    16
    33
    MIT
  • F
    license
    Not graded
    quality
    A
    maintenance
    MCP server that connects AI assistants to Siemens TIA Portal via the Openness API. AI-assisted PLC programming, project management, hardware configuration, cross-reference analysis, and deployment. 16 tools, 166 actions.
    27

View all related MCP servers

Related MCP Connectors

  • MCP Server for Slima - AI Writing IDE for Novel Authors with AI Beta Reader.

  • MCP server for generating rough-draft project plans from natural-language prompts.

  • 2,000+ MCP servers read at source level. Know what one does before you connect. Free, no key.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BlackUppsss/Cx-Proggrammer-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server