AutoCAD MCP服务器v0.1
模型上下文协议(MCP)服务器,使AI代理能够通过Python自动化与AutoCAD交互。此服务器提供用于在AutoCAD中创建几何形状和元素的基本绘图工具。
🚀 特性
- 基本绘图工具:直线、折线、矩形、圆、椭圆和圆弧
- AI代理集成:与启用MCP的AI助手兼容
- 实时AutoCAD控件:与正在运行的AutoCAD实例直接集成
- 简单设置:易于配置和部署
📋 可用工具
| 工具 | 说明 | 参数 |
|---|---|---|
draw_line | 在两点之间画一条线 | x1, y1, x2, y2 |
draw_polyline | 通过多个点绘制折线 | points (\[x,y\]对列表) |
draw_rectangle | 画一个对角矩形 | x1, y1, x2, y2 |
draw_circle | 画一个有圆心和半径的圆 | x, y, radius |
draw_ellipse | 画一个有中心和轴的椭圆 | x, y, major, minor |
draw_arc | 画一条有圆心、半径和角度的弧 | x, y, radius, start_angle, end_angle |
🛠️ 先决条件
- AutoCAD:必须在Windows上安装并运行
- python:3.8或更高
- 紫外线:Python包管理器(推荐)
📦 安装
- 克隆此存储库:
git clone https://github.com/vigneshpbmenon/autocad-mcp-server.git
cd autocad-mcp-server- 安装依赖项:
uv sync或者使用pip:
pip install -r requirements.txt⚙️ 配置
- 确保AutoCAD在您的系统上运行
- 将服务器配置添加到MCP客户端:
{
"mcpServers": {
"autocad": {
"command": "uv",
"args": ["run", "python", "server.py"]
}
}
}🚀 用法
启动服务器
uv run python server.pyAI代理命令示例
一旦连接到启用MCP的AI助手,您就可以使用自然语言命令:
- 从(0,0)到(10,10)画一条线
- 创建一个在(5,5)和(15,15)处有角的矩形
- “在原点画一个半径为5的圆”
- “以(10,10)为中心,在0°至90°之间画一条半径为8的弧”
API直接使用
from mcp.client import Client
# Connect to the server
client = Client()
# Draw a line
result = client.call_tool("draw_line", {
"x1": 0, "y1": 0,
"x2": 10, "y2": 10
})
# Draw a circle
result = client.call_tool("draw_circle", {
"x": 5, "y": 5,
"radius": 3
})🔧 发展
项目结构
autocad-mcp-server/
├── server.py # Main MCP server implementation
├── server_config.json # Server configuration
├── requirements.txt # Python dependencies
├── README.md # This file
└── LICENSE # MIT License添加新工具
要添加新的绘图工具,请执行以下操作:
- 使用定义工具功能
@mcp.tool装饰器 - 使用
pyautocad与AutoCAD交互的库 - 返回关于所执行操作的描述性字符串
例子:
@mcp.tool(
name="draw_polygon",
description="Draw a regular polygon with n sides."
)
def draw_polygon(x: float, y: float, radius: float, sides: int) -> str:
# Implementation here
return f"Drew {sides}-sided polygon at ({x}, {y})"🤝 贡献
欢迎投稿!请随时提交拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
📝 版本历史记录
- v0.1 -带有基本绘图工具的初始版本
- 直线、折线、矩形、圆、椭圆和圆弧 - 基本MCP服务器实现 - 通过pyautocad集成AutoCAD
🔮 路线图
- 高级绘图工具(样条曲线、图案填充、尺寸)
- 分层管理
- 块插入和操作
- 3D绘图功能
- 图形修改工具(移动、复制、旋转、缩放)
- 文件操作(打开、保存、导入、导出)
⚠️ 已知限制
- 仅限Windows(由于AutoCAD COM接口要求)
- 需要运行AutoCAD
- 基本错误处理(计划在v0.2中进行改进)
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
📞 支持
如果您遇到任何问题或有疑问:
- 检查 问题 页
- 创建包含详细信息的新问题
- 加入MCP社区的讨论
______________________________________________________________________
备注:这是版本0.1-一个基础版本。更高级的功能和工具正在开发中,并将在未来的版本中发布。
