二维码生成器MCP服务器
MCP(模型上下文协议)服务器,从URL生成二维码,与Q CLI和cao主管工作流集成。
特性
- 从任何URL生成二维码
- 返回base64编码的PNG图像
- 可配置的二维码大小和边框
- 与Q CLI代理无缝集成
- 通过Q CLI实现自动流程管理
先决条件
- Linux/WSL环境
- Python 3.12+
- Q CLI已安装并配置
- 曹主管工作流程设置
安装和设置
1.安装系统依赖项
sudo apt update
sudo apt install -y python3-pip python3.12-venv build-essential2.设置虚拟环境
# Navigate to the qrcode_mcp_server directory
cd qrcode_mcp_server
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt3.测试安装
# Test the QR code generation
python test_mcp.py
# Should output:
# ✓ URL: https://wikipedia.org
# ✓ Base64 length: 764 characters
# ✓ QR code saved to 'test_qr_mcp.png'
# ✓ Test completed successfully!4.配置Q CLI代理
添加到您的主管代理配置(supervisor.md):
mcpServers:
qrcode-mcp-server:
type: stdio
command: /absolute/path/to/qrcode_mcp_server/venv/bin/python
args:
- "/absolute/path/to/qrcode_mcp_server/server.py"
allowedTools: ["@qrcode-mcp-server", "other-tools..."]重要:替换 /absolute/path/to/ 使用您的实际工作空间路径。
可用工具
@qrcode-mcp-server/generate_qr_code
参数:
url(必填):要在二维码中编码的URLsize(可选):二维码的盒子大小,默认为10border(可选):框中的边框大小,默认值为4
Agent中的示例用法
# Agent can call:
generate_qr_code(
url="https://github.com/your-repo",
size=10,
border=4
)与曹主管整合
二维码MCP服务器作为cao主管工作流程的第一步进行集成:
- 项目初始化和二维码生成
- 创建项目目录 - 为GitHub仓库生成二维码 - 将二维码保存为PNG文件
文件结构
qrcode_mcp_server/
├── server.py # Main MCP server
├── test_mcp.py # Test script
├── requirements.txt # Python dependencies
├── README.md # This file
├── venv/ # Virtual environment
└── qr-code/test_qr_mcp.png # Test output (generated)输出文件
在项目中使用时,生成:
qr-code.png-二维码图像文件
故障排除
权限问题
chmod +x server.py路径问题
- 在代理配置中始终使用绝对路径
- 验证虚拟环境路径是否存在
依赖关系检查
source venv/bin/activate
pip list | grep -E "(mcp|qrcode|Pillow)"直接测试MCP服务器
source venv/bin/activate
python server.py
# Should start without errors技术细节
- 协议:模型上下文协议(MCP)v2024-11-05
- 沟通:stdin/stdout JSON-RPC
- 图像格式:采用base64编码的PNG
- 二维码库:枕式qrcode\[pil\]
- 错误纠正:L级(低)
依赖项
mcp>=1.0.0-模型上下文协议框架qrcode[pil]>=7.4.2-支持PIL的二维码生成Pillow>=10.4.0-图像处理库
许可证
echo架构师编排器项目的一部分。
