CEDARScript MCP服务器
通过模型上下文协议进行人工智能辅助代码转换
 
概述
CEDARScript MCP服务器展示了强大的 CEDARScript编辑器 通过模型上下文协议(MCP),使像Claude这样的AI代理能够执行智能、语义感知的代码转换。
主要特点
- 🔒 缺省巩固安全:路径验证、沙盒、只读模式
- 🎯 干运行模式:应用前预览更改
- 🌲 树保姆供电:语言感知代码分析
- 📡 STDIO传输:简单的子流程集成(无HTTP开销)
- 🛠️ 生产准备就绪:全面的日志记录、错误处理、测试
快速开始
安装
pip install cedarscript-mcp-server使用Claude Desktop
- 打开克劳德桌面配置(通常
~/.config/Claude/claude_desktop_config.json)
- 添加CEDARScript MCP服务器:
{
"mcpServers": {
"cedarscript": {
"command": "python",
"args": [
"-m",
"cedarscript_mcp.server",
"--root",
"/path/to/your/project"
]
}
}
}- 重新启动克劳德桌面
- 让Claude使用CEDARScript:
- “解析此CEDARScript命令: UPDATE myfile.py SET imports.append('import os')" - “应用此转换(先预览): UPDATE calculator.py SET function:calculate REPLACE 'x + 1' WITH 'x + 2'"
命令行用法
# Start server (STDIO mode)
python -m cedarscript_mcp.server --root /path/to/project
# With custom options
python -m cedarscript_mcp.server \
--root /path/to/project \
--read-only \
--log-level DEBUG \
--max-file-size 10485760建筑
CEDARScript MCP服务器是一个精简的适配器层,它:
- 通过STDIO接受JSON-RPC请求
- 验证路径和安全约束
- 代表们 CEDARScript编辑器 执行
- 返回结构化结果或错误消息
┌─────────────────────────────────┐
│ Claude Desktop / VS Code │
│ (MCP Client) │
└────────────┬────────────────────┘
│ JSON-RPC over STDIO
┌────────────▼────────────────────┐
│ CEDARScript MCP Server │
│ • Security (path validation) │
│ • Tools (parse, apply, list) │
│ • Adapters (protocol mapping) │
└────────────┬────────────────────┘
│
┌────────────▼────────────────────┐
│ CEDARScript Editor (core) │
│ • AST parsing │
│ • Tree-sitter analysis │
│ • File transformations │
└─────────────────────────────────┘可用工具
parse_cedarscript
无需执行即可解析和验证CEDARScript命令。
参数:
content(字符串):CEDARScript命令
退货: 解析的AST命令
例子:
{
"content": "UPDATE myfile.py SET imports.append('import os')"
}apply_cedarscript
将CEDARScript转换应用于代码文件。
参数:
commands(字符串):CEDARScript命令root(string):项目根目录路径dry_run(boolean,默认值:true):预览更改而不写入
退货: 结果、差异(如果dry_run)、受影响的文件
例子:
{
"commands": "UPDATE calculator.py SET function:add REPLACE 'x + y' WITH 'x + y + 1'",
"root": "/path/to/project",
"dry_run": true
}list_capabilities
列出服务器功能和支持的功能。
退货: 服务器版本、功能、安全设置
配置
环境变量
CEDARSCRIPT_ROOT:默认项目根目录(默认:当前目录)CEDARSCRIPT_LOG_LEVEL:日志记录级别(调试、信息、警告、错误)CEDARSCRIPT_LOG_FORMAT:日志格式(文本、json)CEDARSCRIPT_READ_ONLY:强制只读模式(真/假)CEDARSCRIPT_MAX_FILE_SIZE:最大文件大小(以字节为单位)(默认值:10485760)
CLI参数
python -m cedarscript_mcp.server \
--root /path/to/project \ # Project root directory
--read-only \ # Enable read-only mode
--log-level DEBUG \ # Logging level
--max-file-size 10485760 # Max file size (bytes)安全
路径验证
- 所有文件路径都会根据指定的根目录进行验证
- 路径遍历攻击(
../../../etc/passwd)被封锁 - Symlinks已解析并验证
Denylist图案
与这些模式匹配的文件将被自动拒绝:
.git/**,node_modules/**,__pycache__/**.env,*.env,.env.*credentials.json,*.key,*.pem
只读模式
启用后,将拒绝所有写入操作(仅解析/分析)。
文件大小限制
可配置的最大文件大小(默认值:10MB),以防止资源耗尽。
发展
设置
# Clone repository
git clone https://github.com/CEDARScript/cedarscript-mcp-server.git
cd cedarscript-mcp-server
# Install development dependencies
make install
# Run tests
make test
# Run with coverage
make test-cov
# Format and lint
make check生成文件目标
make help # Show all available targets
make install # Install with dev dependencies
make test # Run full test suite
make test-fast # Run tests (skip integration)
make check # Format, lint, security checks
make run # Launch server (demo mode)
make build # Build distribution packages看 planning/MAKEFILE_DESIGN.md 获取完整的目标文档。
测试
# Run all tests
make test
# With coverage report
make test-cov
# Watch mode (auto-rerun on changes)
make test-watch
# Test against multiple cedarscript-editor versions
make test-matrix文档
- 建筑.md:系统设计、协议映射、安全模型
- 实施.md:分步实施指南
- MAKEFILE_DESIGN.md:Makefile目标和自动化
- 示例:Claude Desktop、VS Code、快速入门指南
示例
Claude桌面配置
看 examples/claude_desktop.json 用于插入式配置。
VS代码MCP客户端
看 examples/vscode_mcp.json 用于VS代码设置。
程序化使用
from cedarscript_mcp import PathValidator, apply_cedarscript_tool
# Create validator
validator = PathValidator(Path("/path/to/project"))
# Apply transformation (dry-run)
result = apply_cedarscript_tool(
commands="UPDATE myfile.py SET imports.append('import os')",
root="/path/to/project",
dry_run=True,
validator=validator
)
print(result)故障排除
服务器未启动
问题: ModuleNotFoundError: No module named 'mcp'
解决方案:安装MCP SDK: pip install mcp>=1.0.0
路径验证错误
问题: SecurityError: Path escape attempt
解决方案:确保文件路径在指定的根目录内。
只读模式阻止写入
问题: SecurityError: Write operation rejected
解决方案:删除 --read-only 标志或集合 CEDARSCRIPT_READ_ONLY=false.
贡献
欢迎投稿!拜托:
- 分叉存储库
- 创建要素分支
- 跑
make check test在承诺之前 - 提交拉取请求
许可证
Apache许可证2.0-请参阅 许可证 了解详情。
相关项目
- CEDARScript编辑器 -核心转型库
- CEDARScript AST解析器 -语言分析器
- 模型上下文协议 -MCP规范
支持
- 问题:
- 文档:
- 电子邮件: cedarscript@orgecc.com
______________________________________________________________________
由以下材料制成❤️ CEDARScript团队
