QR Scanner MCP
Enables AI assistants to generate QR codes from text and scan QR codes from images, supporting multiple codes per image and customizable output paths.
README
QR Scanner MCP
A Model Context Protocol (MCP) server that provides QR code generation and scanning capabilities. Built with Python and optimized for performance, this server allows AI assistants to create and read QR codes seamlessly.
Features
- QR Code Generation: Create QR codes from any text data with customizable output paths
- QR Code Scanning: Extract text and data from QR code images with position information
- High Performance: Built with OpenCV and pyzbar for fast image processing
- MCP Compatible: Full integration with Claude and other MCP-compatible AI assistants
- Error Handling: Robust error handling for missing files, invalid images, and malformed data
- Multiple QR Codes: Support for scanning multiple QR codes in a single image
Installation
This project uses UV for fast Python package management.
Prerequisites
- Python 3.11 or higher
- UV package manager
Install UV
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Install Dependencies
# Clone the repository
git clone <repository-url>
cd qrscanner-mcp
# Install dependencies
uv sync
Usage
Running the MCP Server
# Start the MCP server
uv run python main.py
The server communicates via stdin/stdout following the MCP protocol.
Available Tools
1. Generate QR Code
Creates a QR code image from text data.
Parameters:
data(string, required): The text data to encode in the QR codefile_path(string, optional): Path where to save the QR code image (default: "qr_code.png")
Example:
{
"name": "generate_qr_code",
"arguments": {
"data": "Hello, World!",
"file_path": "hello_world_qr.png"
}
}
2. Scan QR Code
Scans and decodes QR codes from an image file.
Parameters:
image_path(string, required): Path to the image file containing QR codes
Returns:
- QR code data/text
- QR code type (e.g., "QRCODE")
- Bounding rectangle coordinates (x, y, width, height)
Example:
{
"name": "scan_qr_code",
"arguments": {
"image_path": "qr_code.png"
}
}
Sample Response:
{
"type": "QRCODE",
"data": "Hello, World!",
"rect": {
"x": 50,
"y": 50,
"width": 200,
"height": 200
}
}
Development
Project Structure
qrscanner-mcp/
├── main.py # MCP server implementation
├── pyproject.toml # Project configuration and dependencies
├── README.md # This file
├── UV_REFERENCE.md # UV package manager reference
├── tests/
│ └── test_main.py # Test suite
├── qrcodes/ # Sample QR code images
│ ├── qr_code.png
│ ├── with_logo.png
│ └── ...
└── uv.lock # Dependency lock file
Running Tests
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test
uv run pytest tests/test_main.py::test_generate_qr_code_tool
Code Quality
# Format code
uv run ruff format
# Lint code
uv run ruff check
# Type checking (if mypy is added)
uv run mypy main.py
Dependencies
- mcp: Model Context Protocol implementation
- qrcode: QR code generation
- pillow: Image processing library
- pyzbar: QR code and barcode decoding
- opencv-python: Computer vision and image processing
- pytest: Testing framework (dev dependency)
Configuration
pyproject.toml
The project is configured as an MCP server with the following key settings:
[project]
name = "qrscanner-mcp"
version = "0.1.0"
dependencies = [
"mcp",
"qrcode",
"pillow",
"pyzbar",
"opencv-python",
]
[project.scripts]
qrscanner-mcp = "main:main"
Integration with Claude
To use this MCP server with Claude, add it to your Claude configuration:
Claude Desktop Configuration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"qrscanner-mcp": {
"command": "uv",
"args": ["run", "python", "/path/to/qrscanner-mcp/main.py"],
"cwd": "/path/to/qrscanner-mcp"
}
}
}
Claude Code Configuration
The server can be used directly with Claude Code by running it as a subprocess and communicating via the MCP protocol.
Example Workflows
1. Create a QR Code for a URL
# Generate QR code for a website
result = await handle_call_tool("generate_qr_code", {
"data": "https://github.com/astral-sh/uv",
"file_path": "uv_website_qr.png"
})
2. Scan QR Codes from Camera Image
# Scan QR codes from a photo
result = await handle_call_tool("scan_qr_code", {
"image_path": "camera_image.jpg"
})
3. Process Multiple QR Codes
The scanner automatically detects and processes multiple QR codes in a single image:
# Image with multiple QR codes
result = await handle_call_tool("scan_qr_code", {
"image_path": "multiple_qr_codes.png"
})
# Returns array with all detected QR codes
Error Handling
The server provides comprehensive error handling:
- File Not Found: Clear error messages when image files don't exist
- Invalid Images: Graceful handling of corrupted or unsupported image formats
- No QR Codes: Informative response when no QR codes are detected
- Decoding Errors: Proper error reporting for malformed QR codes
Performance
- Fast Scanning: Optimized with OpenCV and pyzbar for quick QR code detection
- Memory Efficient: Minimal memory footprint using efficient image processing
- Batch Processing: Can handle multiple QR codes in a single operation
- UV Package Management: Ultra-fast dependency resolution and installation
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests:
uv run pytest - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- For UV package manager documentation, see UV_REFERENCE.md
- For MCP protocol documentation, visit MCP Documentation
- For issues and feature requests, please open a GitHub issue
Changelog
v0.1.0
- Initial release
- QR code generation and scanning capabilities
- MCP server implementation
- UV package management integration
- Comprehensive test suite
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。