YOLO MCP 服务
强大的 YOLO(You Only Look Once)计算机视觉服务,通过模型上下文协议 (MCP) 与 Claude AI 集成。该服务使 Claude 能够使用最先进的 YOLO 模型执行对象检测、分割、分类和实时摄像头分析。
特征
物体检测、分割、分类和姿势估计
实时摄像头集成,用于活体物体检测
支持模型训练、验证和导出
结合多种模型的综合图像分析
支持文件路径和 base64 编码图像
与 Claude AI 无缝集成
Related MCP server: MCP Code Analyzer
设置说明
先决条件
Python 3.10 或更高版本
Git(可选,用于克隆存储库)
环境设置
为项目创建一个目录并导航到该目录:
mkdir yolo-mcp-service cd yolo-mcp-service下载项目文件或从存储库克隆:
# If you have the files, copy them to this directory # If using git: git clone https://github.com/GongRzhe/YOLO-MCP-Server.git .创建虚拟环境:
# On Windows python -m venv .venv # On macOS/Linux python3 -m venv .venv激活虚拟环境:
# On Windows .venv\Scripts\activate # On macOS/Linux source .venv/bin/activate运行安装脚本:
python setup.py安装脚本将:
检查你的 Python 版本
创建虚拟环境(如果尚未创建)
安装所需的依赖项
生成 MCP 配置文件 (mcp-config.json)
输出包括 Claude 在内的不同 MCP 客户端的配置信息
请注意安装脚本的输出,它类似于:
MCP configuration has been written to: /path/to/mcp-config.json MCP configuration for Cursor: /path/to/.venv/bin/python /path/to/server.py MCP configuration for Windsurf/Claude Desktop: { "mcpServers": { "yolo-service": { "command": "/path/to/.venv/bin/python", "args": [ "/path/to/server.py" ], "env": { "PYTHONPATH": "/path/to" } } } } To use with Claude Desktop, merge this configuration into: /path/to/claude_desktop_config.json
下载 YOLO 模型
在使用该服务之前,您需要下载 YOLO 模型。该服务会在以下目录中查找模型:
服务运行的当前目录
models子目录server.py 中的
CONFIG["model_dirs"]变量配置的任何其他目录
创建models目录,下载一些常用的模型:
# Create models directory
mkdir models
# Download YOLOv8n for basic object detection
curl -L https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt -o models/yolov8n.pt
# Download YOLOv8n-seg for segmentation
curl -L https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-seg.pt -o models/yolov8n-seg.pt
# Download YOLOv8n-cls for classification
curl -L https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-cls.pt -o models/yolov8n-cls.pt
# Download YOLOv8n-pose for pose estimation
curl -L https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-pose.pt -o models/yolov8n-pose.pt对于 Windows PowerShell 用户:
# Create models directory
mkdir models
# Download models using Invoke-WebRequest
Invoke-WebRequest -Uri "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt" -OutFile "models/yolov8n.pt"
Invoke-WebRequest -Uri "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-seg.pt" -OutFile "models/yolov8n-seg.pt"
Invoke-WebRequest -Uri "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-cls.pt" -OutFile "models/yolov8n-cls.pt"
Invoke-WebRequest -Uri "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-pose.pt" -OutFile "models/yolov8n-pose.pt"配置 Claude
要与 Claude 一起使用此服务:
对于 Claude web:在本地机器上设置服务并使用 MCP 客户端中的安装脚本提供的配置。
对于 Claude 桌面:
运行安装脚本并记下配置输出
找到您的 Claude Desktop 配置文件(路径在安装脚本输出中提供)
将配置添加或合并到您的 Claude Desktop 配置文件中
重启Claude桌面
在 Claude 中使用 YOLO 工具
1. 首先检查可用的模型
请务必先检查您的系统上有哪些型号可用:
I'd like to use the YOLO tools. Can you first check which models are available on my system?
<function_calls>
<invoke name="list_available_models">
</invoke>
</function_calls>2. 检测图像中的物体
要分析计算机上的图像文件:
Can you analyze this image file for objects?
<function_calls>
<invoke name="analyze_image_from_path">
<parameter name="image_path">/path/to/your/image.jpg</parameter>
<parameter name="confidence">0.3</parameter>
</invoke>
</function_calls>您还可以指定不同的模型:
Can you analyze this image using a different model?
<function_calls>
<invoke name="analyze_image_from_path">
<parameter name="image_path">/path/to/your/image.jpg</parameter>
<parameter name="model_name">yolov8n.pt</parameter>
<parameter name="confidence">0.4</parameter>
</invoke>
</function_calls>3. 运行综合图像分析
对于结合对象检测、分类等的更详细分析:
Can you perform a comprehensive analysis on this image?
<function_calls>
<invoke name="comprehensive_image_analysis">
<parameter name="image_path">/path/to/your/image.jpg</parameter>
<parameter name="confidence">0.3</parameter>
</invoke>
</function_calls>4.图像分割
用于识别对象边界和创建分割蒙版:
Can you perform image segmentation on this photo?
<function_calls>
<invoke name="segment_objects">
<parameter name="image_data">/path/to/your/image.jpg</parameter>
<parameter name="is_path">true</parameter>
<parameter name="model_name">yolov8n-seg.pt</parameter>
</invoke>
</function_calls>5.图像分类
对整个图像内容进行分类:
What does this image show? Can you classify it?
<function_calls>
<invoke name="classify_image">
<parameter name="image_data">/path/to/your/image.jpg</parameter>
<parameter name="is_path">true</parameter>
<parameter name="model_name">yolov8n-cls.pt</parameter>
<parameter name="top_k">5</parameter>
</invoke>
</function_calls>6. 使用电脑的摄像头
使用计算机的摄像头开始实时物体检测:
Can you turn on my camera and detect objects in real-time?
<function_calls>
<invoke name="start_camera_detection">
<parameter name="model_name">yolov8n.pt</parameter>
<parameter name="confidence">0.3</parameter>
</invoke>
</function_calls>获取最新的相机检测结果:
What are you seeing through my camera right now?
<function_calls>
<invoke name="get_camera_detections">
</invoke>
</function_calls>完成后停止相机:
Please turn off the camera.
<function_calls>
<invoke name="stop_camera_detection">
</invoke>
</function_calls>7. 高级模型操作
训练自定义模型
I want to train a custom object detection model on my dataset.
<function_calls>
<invoke name="train_model">
<parameter name="dataset_path">/path/to/your/dataset</parameter>
<parameter name="model_name">yolov8n.pt</parameter>
<parameter name="epochs">50</parameter>
</invoke>
</function_calls>验证模型
Can you validate the performance of my model on a test dataset?
<function_calls>
<invoke name="validate_model">
<parameter name="model_path">/path/to/your/trained/model.pt</parameter>
<parameter name="data_path">/path/to/validation/dataset</parameter>
</invoke>
</function_calls>将模型导出为不同格式
I need to export my YOLO model to ONNX format.
<function_calls>
<invoke name="export_model">
<parameter name="model_path">/path/to/your/model.pt</parameter>
<parameter name="format">onnx</parameter>
</invoke>
</function_calls>8.测试连接
检查YOLO服务是否正常运行:
Is the YOLO service running correctly?
<function_calls>
<invoke name="test_connection">
</invoke>
</function_calls>故障排除
相机问题
如果相机不工作,请尝试不同的相机 ID:
<function_calls>
<invoke name="start_camera_detection">
<parameter name="camera_id">1</parameter> <!-- Try 0, 1, or 2 -->
</invoke>
</function_calls>未找到模型
如果未找到模型,请确保已将其下载到配置的目录之一:
<function_calls>
<invoke name="get_model_directories">
</invoke>
</function_calls>性能问题
为了在有限的资源下获得更好的性能,请使用较小的模型(例如,yolov8n.pt 而不是 yolov8x.pt)