# OPC UA LinkAI

> Empowering OPC UA as the Model Context Protocol (MCP) for industrial intelligence. It enables AI Agents to seamlessly discover, connect, and intelligently control automation hardware.

- **Type:** MCP server
- **Install:** `agentstack add mcp-zhongriqian-opc-ua-linkai`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [zhongriqian](https://agentstack.voostack.com/s/zhongriqian)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [zhongriqian](https://github.com/zhongriqian)
- **Source:** https://github.com/zhongriqian/OPC_UA_LinkAI

## Install

```sh
agentstack add mcp-zhongriqian-opc-ua-linkai
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# OPC UA LinkAI 项目

## 项目简介

OPC UA LinkAI 是一个为 OPC UA 协议提供功能扩展的框架，使 OPC UA 成为工业自动化领域的 MCP（模型上下文协议），让 AI Agent 能够便捷使用 OPC UA 连接工业自动化设备并进行智能操控。

## 项目文件结构

```
opcua_linkai/
├── src/
│   └── opcua_linkai/         # 核心源代码
│       ├── __init__.py       # 包初始化文件
│       ├── caller.py         # 工具调用路由
│       ├── context.py        # 上下文管理
│       ├── linkai_client.py  # 异步 OPC UA 客户端（核心）
│       ├── linkai_syncclient.py  # 同步 OPC UA 客户端
│       ├── registry.py       # 工具注册表
│       ├── scanner.py        # 信息模型扫描器
│       ├── tools.py          # 核心工具实现
│       └── utils.py          # 工具函数
├── examples/
│   ├── client/               # 客户端示例
│   │   ├── .env              # 环境变量配置
│   │   ├── agent_test.py     # 智能代理测试
│   │   ├── client_function_test.py  # 客户端功能测试
│   │   ├── dynamic_information_model_127.0.0.1_4840.json  # 动态信息模型
│   │   └── information_model_127.0.0.1_4840.json  # 静态信息模型
│   ├── coppeliasim_scene/    # 测试仿真环境
│   │   ├── UR5_Grip_Scene.ttt  # UR5 机器人仿真场景文件
│   │   ├── connection_manager.py  # 连接管理器
│   │   ├── scene_manager.py     # 场景管理器
│   │   ├── ur5.py               # UR5 机器人控制类
│   │   ├── utils.py             # 工具函数
│   │   └── vision_system.py     # 视觉系统
│   └── server/               # 服务器示例
│       ├── test.py            # 测试服务器
│       └── ur5_vision_server.py  # UR5 视觉服务器
└── README.md                 # 项目说明文档
```

## 项目主要功能

### 1. LinkAI 客户端核心功能

- **异步客户端实现**：`LinkAI_Client` 提供基于 asyncio 的异步操作，支持高并发场景
- **同步客户端封装**：`LinkAI_SyncClient` 提供同步接口，便于在传统同步代码中使用
- **信息模型扫描**：自动扫描 OPC UA 服务器的信息模型，并以 JSON 格式保存，为 AI Agent 提供结构化的设备模型
- **智能工具调用**：将 OPC UA 操作封装为标准工具，支持 AI Agent 通过自然语言调用
- **服务器摘要获取**：快速获取服务器的基本信息，用于 AI Agent 快速了解设备状态
- **线程安全操作**：支持在多线程环境中安全操作 OPC UA 客户端

### 2. 核心工具集

- **read_value**：读取指定路径节点的当前实时数值
- **write_value**：向指定路径节点写入数值
- **call_method**：调用指定路径节点的方法
- **processive_scan_information_model**：渐进式扫描信息模型结构，获取设备的详细能力描述

### 3. 技术特点

- **MCP 协议实现**：将 OPC UA 扩展为工业自动化领域的模型上下文协议
- **AI Agent 友好**：提供标准工具接口，便于 AI Agent 理解和使用
- **模块化设计**：易于扩展和定制，支持添加新的工具和功能
- **异步编程**：使用 asyncio 实现高效的异步操作

## 快速开始

### 1. 安装依赖

```bash
# 安装项目依赖
pip install -r requirements.txt
```

### 2. 运行服务器示例

```bash
# 运行 UR5 视觉服务器（用于测试）
python examples/server/ur5_vision_server.py
```

### 3. 运行客户端示例

```bash
# 运行客户端功能测试
python examples/client/client_function_test.py

# 运行智能代理测试（需要配置 .env 文件中的 API 密钥）
python examples/client/agent_test.py
```

### 4. 基本使用示例

```python
from opcua_linkai.linkai_syncclient import LinkAI_SyncClient

# 初始化客户端
client = LinkAI_SyncClient("opc.tcp://127.0.0.1:4840/opcua/linkai/")

# 获取服务器摘要
summary = client.get_summary()
print(f"Server summary: {summary}")

# 扫描信息模型
client.scan_information_model()

# 获取工具列表
tools = client.get_tools()
print(f"Available tools: {[tool['name'] for tool in tools]}")

# 读取变量值
result = client.handle_tool_request(
    "read_value", 
    {"path_list": ["Objects", "UR5RobotArm", "Status", "IsHomed"]}
)
print(f"Read value result: {result}")

# 调用方法
result = client.handle_tool_request(
    "call_method", 
    {"path_list": ["Objects", "VisionSystem", "Function", "DetectObjects"], "args": []}
)
print(f"Call method result: {result}")

# 断开连接
client.disconnect()
```

## 注意事项

- **CoppeliaSim 说明**：CoppeliaSim 是用于测试的仿真环境
- **智能代理测试**：需要配置 `.env` 文件中的 API 密钥
- **实际应用**：在实际工业环境中，可直接连接真实的 OPC UA 服务器
- **扩展性**：可通过扩展 `tools.py` 添加新的工具，或通过修改 `scanner.py` 定制信息模型扫描行为

## 许可证

本项目采用 MIT 许可证，详见 LICENSE 文件。

## Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [zhongriqian](https://github.com/zhongriqian)
- **Source:** [zhongriqian/OPC_UA_LinkAI](https://github.com/zhongriqian/OPC_UA_LinkAI)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** yes
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/mcp-zhongriqian-opc-ua-linkai
- Seller: https://agentstack.voostack.com/s/zhongriqian
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
