Sponsored by Deepsite.site

Enhanced MCP QR Generator

Created By
zavora-ai7 months ago
A powerful and flexible MCP (Model Context Protocol) server for generating QR codes from URLs and text.
Content

Enhanced MCP QR Generator

A powerful and flexible MCP (Model Context Protocol) server for generating QR codes from URLs and text.

Developed by James Karanja at Zavora AI.

CI/CD Pipeline

Features

  • QR Code Generation: Create QR codes from any text or URL
  • Multiple Output Formats: Generate QR codes as PNG, SVG, base64, or terminal ASCII art
  • Customization Options: Control size, margins, colors, and error correction levels
  • Logo Integration: Add custom logos to the center of QR codes
  • File Saving: Save generated QR codes to files with custom or auto-generated names
  • MCP Integration: Full Model Context Protocol support for AI assistants
  • Docker Support: Easy deployment with Docker and Docker Compose
  • Health Monitoring: Built-in health check endpoint

Installation

npm install enhanced-mcp-qr-generator

Server Architecture

The Enhanced MCP QR Generator uses a single HTTP server that handles:

  1. JSON-RPC Requests: For MCP protocol communication
  2. Health Check Endpoint: Available at /health for monitoring

Port Configuration

The server uses port 9999 by default. You can change this by:

  1. Setting the PORT environment variable
  2. When using Docker, updating the PORT environment variable in docker-compose.yml
  3. When using Docker, updating the port mapping in docker-compose.yml

Example:

# Run with a custom port
PORT=8080 npx enhanced-mcp-qr-generator

Configuration Precedence

Configuration values are determined in the following order (highest priority first):

  1. Command line arguments
  2. Environment variables
  3. Default values from config.ts

As an MCP Server

# Run directly from command line
npx enhanced-mcp-qr-generator

# With custom options
npx enhanced-mcp-qr-generator --error-correction-level=H --format=svg --size=500

MCP Integration

The Enhanced MCP QR Generator implements the Model Context Protocol (MCP), allowing it to be used with various AI assistants and tools.

Available MCP Tools

  • generate_qr: Generate a QR code from text or URL
  • save_qr: Generate a QR code and save it to a file

Using with AI Assistants

Amazon Q CLI

To use with Amazon Q CLI, create an MCP configuration file:

# Create a configuration directory if it doesn't exist
mkdir -p ~/.aws/amazonq

# Create the MCP configuration file
cat > ~/.aws/amazonq/mcp.json << EOF
{
  "mcpServers": {
    "qr-generator": {
      "command": "npx",
      "args": ["-y", "enhanced-mcp-qr-generator"]
    }
  }
}
EOF

# Start Amazon Q with MCP support enabled
q chat

You can also place the configuration in your project directory at .amazonq/mcp.json to share it with your team.

Claude Desktop

To use with Claude Desktop, create an MCP configuration file:

{
  "mcpServers": {
    "qr-generator": {
      "command": "npx",
      "args": ["-y", "enhanced-mcp-qr-generator"]
    }
  }
}

Add this configuration to your Claude Desktop settings file.

You can then use the QR generator tools in your conversation:

> Can you generate a QR code for my website https://example.com?

Docker Configuration

You can also run the server using Docker:

{
  "mcpServers": {
    "qr-generator": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "zavorai/enhanced-mcp-qr-generator"]
    }
  }
}

Configuration

Create a custom configuration to control server behavior:

import { generateQR, ServerConfig } from 'enhanced-mcp-qr-generator';

const config: ServerConfig = {
  defaultErrorCorrectionLevel: 'H',
  defaultFormat: 'svg',
  defaultSize: 500,
  defaultMargin: 2,
  defaultColor: '#000000',
  defaultBackgroundColor: '#ffffff',
  maxQRCodeSize: 2000,
  maxLogoSize: 2 * 1024 * 1024, // 2MB
  // ... other options
};

// Use the configuration with any operation
const qrCode = await generateQR('https://example.com', {}, config);

Command Line Options

When running as an MCP server, the following command line options are available:

--error-correction-level=<L|M|Q|H>  Set error correction level
--format=<png|svg|base64|terminal>  Set output format
--size=<pixels>                     Set QR code size
--margin=<modules>                  Set margin size
--color=<color>                     Set QR code color
--background-color=<color>          Set background color

API Documentation

generateQR(text, options, config)

Generates a QR code from text or URL.

  • text: Text or URL to encode in the QR code
  • options: QR code generation options
    • errorCorrectionLevel: Error correction level ('L', 'M', 'Q', 'H')
    • format: Output format ('png', 'svg', 'base64', 'terminal')
    • size: Size of QR code in pixels
    • margin: Margin around the QR code in modules
    • color: Color of the QR code (dark modules)
    • backgroundColor: Background color of the QR code (light modules)
    • logo: Logo options
      • image: URL or base64 encoded image
      • size: Size of the logo as a percentage of the QR code size
  • config: Server configuration (optional)

Returns a QRCodeResult object:

  • data: Generated QR code data
  • mimeType: MIME type of the generated QR code
  • format: Format of the generated QR code
  • size: Size of the generated QR code in pixels
  • content: Original text or URL encoded in the QR code
  • timestamp: Timestamp when the QR code was generated

saveQRToFile(qrResult, outputPath)

Saves a QR code to a file.

  • qrResult: QR code result from generateQR
  • outputPath: Output file path

Returns the path to the saved file.

MCP Protocol Implementation

This project implements the Model Context Protocol (MCP) specification, providing a standardized way for AI assistants to generate QR codes. The implementation follows the JSON-RPC 2.0 format required by MCP.

Tool Specifications

The MCP server provides two tools:

  1. generate_qr: Generates a QR code and returns it in the specified format

    • Input: Text/URL, format options, styling options
    • Output: QR code data with metadata
  2. save_qr: Generates a QR code and saves it to a file

    • Input: Text/URL, output path, format options, styling options
    • Output: File path and metadata

JSON-RPC Format

All requests and responses follow the JSON-RPC 2.0 format:

// Example request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "generate_qr",
    "arguments": {
      "text": "https://example.com",
      "format": "png",
      "size": 300
    }
  }
}

// Example response
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "image",
        "data": "base64-encoded-data",
        "mimeType": "image/png"
      }
    ],
    "structuredContent": {
      "format": "png",
      "size": 300,
      "content": "https://example.com",
      "timestamp": "2025-05-30T21:00:00Z"
    }
  }
}

Development

Prerequisites

  • Node.js (v14 or later)
  • npm or yarn

Building

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

Permission Management

If you encounter permission issues with node_modules, use one of these solutions:

Option 1: Fix Permissions Script

Run the included script to fix permissions:

./fix-permissions.sh

This script will:

  1. Check current ownership of node_modules
  2. Create backups of package.json and package-lock.json
  3. Remove the node_modules directory
  4. Reinstall dependencies with correct permissions
  5. Verify the fix worked correctly

Option 2: Docker-based npm

Use the Docker-based npm script to avoid permission issues:

# Install dependencies
./docker-npm.sh install

# Or use npm ci for clean install
./docker-npm.sh ci

This runs npm commands in a Docker container with your user permissions, preventing any root-owned files.

Testing

The project includes both unit tests and integration tests:

# Run all tests
npm test

# Run only unit tests
npm run test:unit

# Run only integration tests
npm run test:integration

# Run tests with coverage
npm run test:coverage

License

MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Tavily Mcp
Amap Maps高德地图官方 MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Playwright McpPlaywright MCP server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server