二维码生成服务

一个基于Node.js和TypeScript的MCP服务器,用于从文本或URL生成多种格式的二维码,支持批量处理和高级自定义选项。

  • by antoBrugnot
  • TypeScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 antoBrugnot/qrcode-mcp

使用说明

二维码MCP服务器

一个MCP(模型上下文协议)服务器,用于使用Node.js和TypeScript从文本或URL生成二维码。

🚀 功能

  • 生成多种格式的二维码 DataURL(base64)、SVG和终端显示
  • 高级个性化选项 纠错级别、大小、边距、颜色
  • 批量生成 在单个命令中处理多个文本/URL
  • 标准化MCP接口 与所有MCP客户端兼容
  • 全面支持 TypeScript 安全类型和自动完成

📦 安装

选项1:Docker/Podman(推荐)🐳

先决条件在您的系统上安装了Docker或Podman

# Avec Docker
docker pull antobrugnot/qrcode-mcp-server:latest

# Ou avec Podman (plus sécurisé, rootless)
podman pull antobrugnot/qrcode-mcp-server:latest

# Build local avec Docker
docker build -t qrcode-mcp-server .

# Build local avec Podman
podman build -t qrcode-mcp-server .

选项2:本地安装

先决条件:

  • Node.js 18.0.0 或更高版本
  • npm 或 yarn
# Cloner le projet
git clone <votre-repo>
cd qrcode-mcp

# Installer les dépendances
npm install

# Builder le projet
npm run build

🛠️ 使用

使用 Docker/Podman(推荐)

# Avec Docker
docker run -i --rm antobrugnot/qrcode-mcp-server:latest

# Avec Podman (plus sécurisé)
podman run -i --rm antobrugnot/qrcode-mcp-server:latest

# Avec Docker Compose
docker-compose up qrcode-mcp-server

# Avec Podman Compose
podman-compose up qrcode-mcp-server

# Mode développement
docker-compose --profile dev up qrcode-mcp-dev
# ou
podman-compose --profile dev up qrcode-mcp-dev

地方发展

# Mode développement avec rechargement automatique
npm run dev

# Ou en mode watch
npm run watch

# Builder pour la production
npm run build

# Lancer la version buildée
npm start

🔧 可用的MCP工具

1. generate-qrcode-dataurl

生成一个二维码并以Data URL(base64)的形式返回。

参数:

  • text (字符串,必需):要编码的文本或URL
  • options (对象,可选):生成选项
    • errorCorrectionLevel 'L'、'M'、'Q' 或 'H'(默认:'M')
    • width 像素宽度(50-2000)
    • margin 模块边距(0-10,默认:4)
    • color.dark 深色模块的颜色(默认:'#000000')
    • color.light 背景颜色(默认:'#FFFFFF')
    • type MIME 类型('image/png','image/jpeg','image/webp')

使用示例:

{
  "text": "https://github.com",
  "options": {
    "width": 300,
    "errorCorrectionLevel": "H",
    "color": {
      "dark": "#1f2937",
      "light": "#f3f4f6"
    }
  }
}

2. generate-qrcode-svg

生成一个SVG格式的二维码。

参数:

  • text (字符串,必需):要编码的文本或URL
  • options (object, 可选):生成选项(类似于dataurl)

使用示例:

{
  "text": "Hello, World!",
  "options": {
    "width": 200,
    "margin": 2
  }
}

3. generate-qrcode-terminal

生成一个二维码以在终端上显示。

参数:

  • text (字符串,必需):要编码的文本或URL
  • options (对象,可选):
    • small (boolean):使用紧凑格式(默认:false)

使用示例:

{
  "text": "Terminal QR Code",
  "options": {
    "small": true
  }
}

4. generate-qrcode-batch

一次操作生成多个(最多10个)二维码。

参数:

  • texts (array[string], 必填):要编码的文本/URL数组(最多10个)
  • format (字符串,可选):输出格式('dataurl','svg','terminal',默认:'dataurl')
  • options (对象,可选):生成选项

使用示例:

{
  "texts": [
    "https://github.com",
    "https://www.google.com",
    "Hello World"
  ],
  "format": "dataurl",
  "options": {
    "width": 200
  }
}

🎯 与MCP客户一起使用

Claude Desktop(或Github Copilot)

ℹ️(这个符号本身在中文中没有直接对应的翻译,它通常用于表示信息或说明,可以翻译为“信息”或“说明”,但具体翻译需根据上下文来确定。) GitHub Copilot 小窍门 :
对于GitHub Copilot来说,关键在于 mcpServers 在配置中就变得简单了 servers.

选项1:使用Docker/Podman(推荐)

将此配置添加到您的 claude_desktop_config.json :

{
  "mcpServers": {
    "qrcode-generator": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "antobrugnot/qrcode-mcp-server:latest"]
    }
  }
}

或者使用 Podman (更安全,无root):

{
  "mcpServers": {
    "qrcode-generator": {
      "command": "podman",
      "args": ["run", "-i", "--rm", "antobrugnot/qrcode-mcp-server:latest"]
    }
  }
}

选项2:本地安装

{
  "mcpServers": {
    "qrcode-generator": {
      "command": "node",
      "args": ["/chemin/vers/qrcode-mcp/dist/index.js"]
    }
  }
}

其他MCP客户

服务器使用标准stdio传输,可与任何兼容的MCP客户端一起使用。

📋 使用示例

生成一个简单的二维码

Générez un QR code pour "https://github.com"

自定义二维码

Générez un QR code pour "Mon site web" avec une largeur de 400px et des couleurs personnalisées (sombre: #2563eb, clair: #eff6ff)

批量生成二维码

Générez des QR codes pour ces URLs : https://github.com, https://stackoverflow.com, https://nodejs.org

终端二维码

Générez un QR code terminal pour "Test terminal" en format compact

🔒 安全

已实施的安全措施

  • 安全容器 使用非root用户(UID 1001)
  • 阿尔卑斯山景象 最小化基础镜像以减少攻击面
  • 能力有限 删除所有不必要的Linux功能
  • 只读文件系统 只读容器以防止修改
  • 资源限制 CPU和内存限制以防止DoS攻击
  • 安全扫描 使用Trivy自动扫描漏洞
  • 依赖项审计 npm依赖项自动检查
  • 多阶段构建 在生产环境中,使用无开发工具的优化构建

良好做法

  • 始终使用标记的最新版本
  • 定期检查安全更新
  • 监控 GitHub 安全警报
  • 使用GitHub密钥来存储DockerHub令牌

🔄 持续集成/持续交付 (CI/CD)

自动化流程

  • 自动测试 TypeScript,构建与安全审计
  • 构建多架构 支持AMD64和ARM64
  • 自动推送 带有适当标签的 DockerHub
  • 安全扫描 使用Trivy检测漏洞
  • 自动发布 GitHub 发布版,附带自动生成的发行说明

需要配置的环境变量

# Dans GitHub Secrets
DOCKERHUB_TOKEN=your_dockerhub_token

🏗️ 建筑学

qrcode-mcp/
├── .github/
│   └── workflows/        # GitHub Actions CI/CD
├── scripts/
│   └── release.sh        # Script de release
├── src/
│   └── index.ts          # Serveur MCP principal
├── dist/                 # Fichiers compilés
├── Dockerfile            # Configuration Docker
├── docker-compose.yml    # Orchestration Docker
├── .dockerignore         # Exclusions Docker
├── package.json          # Dépendances et scripts
├── tsconfig.json         # Configuration TypeScript
├── CONFIGURATION.md      # Guide de configuration
└── README.md            # Documentation

🔧 使用的技术

  • Node.js 运行时JavaScript
  • TypeScript 静态类型化
  • @modelcontextprotocol/sdk(注:此翻译保留了原英文形式,因为“@modelcontextprotocol/sdk”可能是一个特定项目或库的名称,在中文中通常不直接翻译,而是保留原样以指代特定的软件开发工具包或框架。如果这是一个需要具体解释或命名的项目,可以根据实际情况进行适当翻译或命名。) 官方SDK MCP
  • 二维码 二维码生成库
  • zod 模式验证

📝 错误纠正级别

  • L(低) 约7%的错误恢复率
  • M(中号) :约15%的错误恢复(推荐)
  • Q(四分位数) 约25%的错误恢复率
  • H(高) 约30%的错误恢复率

🐛 故障排除

错误:“模块未找到”

确保已安装依赖项:

npm install

TypeScript 编译错误

检查以下配置 tsconfig.json 并重建:

npm run build

服务器无法启动

检查是否已安装 Node.js 18+:

node --version

🚀 发布与部署

创建新版本

# Utiliser le script de release
./scripts/release.sh v1.0.0

# Ou déclencher manuellement via GitHub Actions
# GitHub → Actions → Release → Run workflow

自动化发布流程

  1. 验证 测试、构建和验证
  2. 版本控制 更新 package.json 并创建标签
  3. Docker 构建 构建并推送多架构镜像
  4. 安全扫描 使用Trivy进行安全分析
  5. GitHub 发布版 自动音符创作
  6. 通知 确认成功

可用的 Docker 镜像

# Dernière version stable
docker pull antobrugnot/qrcode-mcp-server:latest

# Version spécifique
docker pull antobrugnot/qrcode-mcp-server:v1.0.0

# Version de développement (branch develop)
docker pull antobrugnot/qrcode-mcp-server:develop

🤝 贡献

欢迎贡献!请随时提交问题或拉取请求。

贡献流程

  1. 叉子 项目
  2. 创造 一个特性分支(git checkout -b feature/amazing-feature)
  3. 提交者(或译为“提交人”) 你的变化(git commit -m 'Add amazing feature')
  4. 推动;推进 朝树枝方向(git push origin feature/amazing-feature)
  5. 打开 一个拉取请求(Pull Request)

代码标准

  • 使用严格模式的TypeScript
  • 遵循 ESLint/Prettier 规范
  • 为新功能添加测试
  • 如有必要,请更新文档

📄 许可证

MIT 许可证 - 详见 LICENSE 文件以了解更多信息。

🔗 有用链接