使用说明
OpenACR MCP服务器
MCP(模型上下文协议)服务器,用于封装 OpenACR CLI工具,让AI代理查询模式,编写新类型/字段/枚举,生成C++代码,并发现生成的API。45个工具,165个测试。
先决条件
- Python 3.11+
- OpenACR 建造和安装(与
bin/acr,bin/acr_ed,bin/amc,bin/abt)
设置
git clone https://github.com/aaslyan/openacr-mcp.git
cd openacr-mcp
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
配置Claude代码
复制示例配置并编辑路径:
cp .mcp.json.example .mcp.json
编辑 .mcp.json 指向您的本地路径:
{
"mcpServers": {
"openacr": {
"command": "/path/to/openacr-mcp/venv/bin/python",
"args": ["-m", "openacr_mcp", "--openacr-dir", "/path/to/openacr"],
"cwd": "/path/to/openacr-mcp"
}
}
}
这 --openacr-dir 标志默认为 ~/openacr 如果省略。
独立运行
python -m openacr_mcp --openacr-dir /path/to/openacr
运行测试
PYTHONPATH=. pytest -v
测试套件包括单元测试(始终运行)和集成测试(需要在以下位置安装OpenACR ~/openacr,否则跳过)。
工具
模式查询与探索(17个工具)
| 工具 | 说明 |
|---|---|
list_namespaces |
列出所有命名空间 |
get_namespace_tree |
命名空间的完整树视图(ctypes、字段、fconsts、ssimfiles) |
list_ctypes |
列出命名空间中的所有ctypes(结构体) |
get_ctype |
通过交叉引用获取ctype的完整细节 |
list_fields |
列出ctype的所有字段 |
list_fconsts |
列出命名空间或ctype的枚举常量 |
list_ssimfiles |
列出命名空间中的数据表 |
list_finputs |
列出exe目标的运行时表输入 |
query |
运行原始acr查询模式 |
search |
按文本搜索ctypes、字段和注释 |
get_downstream |
向下遍历FK依赖关系(acr-ndown) |
get_upstream |
向上遍历FK参考(acr-nup) |
find_unused |
查找未引用的记录进行清理(acr-未使用) |
get_record_meta |
获取记录的模式元数据(acr-meta) |
select_fields |
带列投影的查询(acr-field) |
get_input_tables |
列出目标读取的所有ssimfiles(acr_in) |
visualize_ctype |
ASCII艺术类型结构图(amc_vis) |
模式创作(21个工具)
| 工具 | 说明 |
|---|---|
create_target |
创建新的命名空间(ssimdb、exe、lib、protocol) |
create_ctype |
创建新的ctype(自动为ssimdb创建ssimfile+cfmt) |
create_field |
向ctype添加字段(支持xref、hashfld、sortfld、cascdel之前) |
create_fconst |
向字段添加枚举常量(自动从ctype派生pkey) |
create_enum |
在一次调用中创建包含所有常量的枚举类型 |
create_finput |
为exe目标添加运行时表加载 |
create_gstatic |
添加编译时静态表(烘焙成二进制) |
create_foutput |
为exe目标声明输出表 |
create_substr_field |
为复合密钥提取创建子字符串字段 |
create_bitfield |
创建打包成整数的位字段 |
create_cppfunc |
创建计算字段(C++表达式,不存储) |
create_srcfile |
创建向生成目标注册的源文件 |
create_unittest |
为单元测试功能搭建脚手架 |
create_citest |
构建CI集成测试 |
update_record |
更新记录(如果存在则更新,如果不存在则插入) |
delete_record |
按模式删除ssim记录 |
delete_ctype |
删除带有完整级联的ctype(字段、ssimfile、cfmt) |
delete_field |
使用级联(fconsts、外部参照)删除字段 |
delete_target |
使用级联删除整个命名空间 |
rename_record |
重命名记录,传播引用 |
validate_schema |
运行引用完整性检查(acr-check) |
代码生成和发现(5个工具)
| 工具 | 说明 |
|---|---|
run_amc |
从模式生成C++代码 |
run_abt |
构建/编译目标 |
list_generated_headers |
列出为命名空间生成的.h文件 |
get_generated_code |
读取生成的头文件 |
get_functions |
从生成的标头中提取结构、枚举和函数签名 |
帮助和示例(2个工具)
| 工具 | 说明 |
|---|---|
get_workflow_guide |
12个常见工作流的分步示例 |
get_usage_examples |
为命名空间的类型生成C++使用示例 |
什么 create_ctype 自动创建
对于ssimdb命名空间, create_ctype 自动插入:
dmmeta.ssimfile--支持数据存储的ssimfiledmmeta.cfmt随着read:Y print:Y--生成ReadStrptrMaybe/Printfinput将数据加载到exe目标中所需的函数
无需手动接线。
典型工作流程
1. create_target("mydb", "ssimdb") -- create namespace
2. create_ctype("mydb", "Status") -- create enum type
3. create_fconst("mydb.Status", "active") -- add enum values (auto-derives pkey)
4. create_ctype("mydb", "Record") -- create struct
5. create_field("mydb.Record", "status", "mydb.Status", "Pkey") -- add FK field
6. run_amc() -- generate C++
7. get_functions("mydb") -- discover generated API
8. get_usage_examples("mydb") -- C++ code examples for each type
建筑
openacr-mcp/
├── openacr_mcp/
│ ├── __init__.py
│ ├── __main__.py
│ ├── server.py # MCP server — 45 tools + embedded workflow knowledge
│ ├── acr_client.py # Subprocess wrapper for acr/acr_ed/amc/abt/acr_in/amc_vis
│ └── header_parser.py # C++ header parser for generated code discovery
├── tests/
│ ├── test_server.py # 128 tests (unit + integration)
│ ├── test_acr_client.py # 20 tests
│ └── test_header_parser.py # 17 tests
├── .mcp.json.example # Template MCP config (copy to .mcp.json)
└── pyproject.toml
