WinCC OA MCP服务器
A. 模型上下文协议 (MCP)服务器,将WinCC OA数据点操作作为LLM可调用工具公开。它运行在一个 WinCC OA Node.js管理器 并使用本地 winccoa-manager 与WinCC OA运行时交互的插件。
特性
| 工具 | 描述 | 提示 |
|---|---|---|
winccoa_dp_get | 读取一个或多个数据点元素值 | 只读 |
winccoa_dp_set | 写入值(即发即弃或确认) | 写入 |
winccoa_dp_create | 创建新数据点 | 写入 |
winccoa_dp_delete | 删除数据点 | 破坏性的 |
winccoa_dp_copy | 将数据点复制到新名称 | 写入 |
winccoa_dp_names | 列出与模式匹配的DP | 只读 |
winccoa_dp_exists | 检查DP标识符是否存在 | 只读 |
winccoa_dp_query | 运行类似WinCC OA SQL的查询 | 只读 |
winccoa_dp_types | 列出与模式匹配的数据点类型 | 只读 |
先决条件
- WinCC OA 3.20 (或兼容)已启用Node.js管理器
- Node.js 18+ (与WinCC OA捆绑或安装系统)
- 这
winccoa-manager本机插件(由WinCC OA运行时提供) 不在npm上)
安装
cd winccoa-mcp-server
npm install
npm run build这将编译来自以下位置的TypeScript源代码 src/ 进入 dist/.
配置
由于WinCC OA Node.js管理器不支持命令行参数,所有配置都是通过 .env 文件 放置在构建的入口点旁边(或工作目录中)。
默认值 .env 文件包含在存储库中:
# Transport mode: "stdio" or "http"
MCP_TRANSPORT=stdio
# Port for the HTTP transport (only used when MCP_TRANSPORT=http)
MCP_HTTP_PORT=47899
# Maximum response size in characters to prevent overwhelming the LLM context
MCP_CHARACTER_LIMIT=25000| 变量 | 描述 | 默认值 |
|---|---|---|
MCP_TRANSPORT | "stdio" 或 "http" | stdio |
MCP_HTTP_PORT | HTTP传输端口 | 47899 |
MCP_CHARACTER_LIMIT | 最大响应长度(个字符) | 25000 |
用法
stdio传输(默认)
服务器通过stdin/stdout进行通信。当MCP客户端(例如Claude Desktop、VS Code)直接启动流程或使用MCP Inspector进行测试时,请使用此选项。
node dist/index.jsHTTP传输
集 MCP_TRANSPORT=http 在你的 .env 文件,然后启动服务器。它将在指定的端口上侦听 MCP_HTTP_PORT.
node dist/index.js与WinCC OA集成
此服务器设计为按以下方式运行 客户代码 在WinCC OA Node.js管理器中。典型设置:
- 放置已建
dist/WinCC OA项目脚本目录中的文件夹(或整个项目)。 - 在WinCC OA控制台中配置一个Node.js管理器,将此服务器作为入口脚本。
- WinCC OA引导程序将加载本机
winccoa-manager加载项,然后执行dist/index.js.
MCP客户端配置
克劳德桌面(claude_desktop_config.json)
{
"mcpServers": {
"winccoa": {
"command": "node",
"args": ["C:/path/to/winccoa-mcp-server/dist/index.js"]
}
}
}VS代码(.vscode/mcp.json)
{
"servers": {
"winccoa": {
"type": "stdio",
"command": "node",
"args": ["C:/path/to/winccoa-mcp-server/dist/index.js"]
}
}
}对于HTTP传输,将客户端指向 http://localhost:47899/mcp (或您配置的端口)。
发展
# Run in development mode (tsx, no build step)
npm run dev
# Test with MCP Inspector
npm run inspect要在开发过程中切换传输,请编辑 .env 文件。
项目结构
src/
├── index.ts # Entry point – transport setup
├── server.ts # McpServer creation
├── constants.ts # Shared constants
├── winccoa-client.ts # WinccoaManager singleton
├── types/
│ └── winccoa-manager.d.ts # Type declarations for native add-on
├── tools/
│ ├── register-all.ts # Tool registration orchestrator
│ ├── dp-get.ts # winccoa_dp_get
│ ├── dp-set.ts # winccoa_dp_set
│ ├── dp-create.ts # winccoa_dp_create
│ ├── dp-delete.ts # winccoa_dp_delete
│ ├── dp-copy.ts # winccoa_dp_copy
│ ├── dp-names.ts # winccoa_dp_names
│ ├── dp-exists.ts # winccoa_dp_exists
│ ├── dp-query.ts # winccoa_dp_query
│ └── dp-types.ts # winccoa_dp_types
└── utils/
├── error-handler.ts # WinCC OA error handling
└── formatters.ts # Response formatting helpers添加新工具
- 创建
src/tools/your-tool.ts遵循现有模式(Zod模式+registerTool()). - 导入并调用您的注册功能
src/tools/register-all.ts. - 重建与
npm run build.
许可证
麻省理工学院
