QR code generation
for AI agents
Add QR code generation to any AI agent or assistant. Works via MCP, function calling, LangChain, or direct REST — no auth required.
Pick your integration method
MCP (recommended)
Claude · Cursor · any MCP clientZero code required. Add the server URL to your MCP client config — the AI calls the tool automatically when asked.
Integration effort: Config change only
OpenAI function calling
GPT-4 · GPT-4o · compatible modelsDefine the function schema, implement the handler to call the REST API, and pass it in the tools array.
Integration effort: ~20 lines
LangChain / LlamaIndex
Python · TypeScriptWrap the REST API as a @tool or Tool object and add it to your agent's tool list.
Integration effort: ~10 lines
Direct REST API
Any stackCall the endpoint directly from your agent's action handler. No schema or framework needed.
Integration effort: 1 fetch call
MCP
RecommendedThe fastest path. Claude, Cursor, and other MCP clients pick up the tool automatically — no code required.
{
"mcpServers": {
"theqrcode": {
"url": "https://mcp.theqrcode.io/mcp"
}
}
}After adding the config, restart your client and ask: "Generate a QR code for https://example.com" — the tool fires automatically.
OpenAI function calling
Works with GPT-4, GPT-4o, and any model that supports the tools API.
1. Function schema
{
"name": "generate_qr_code",
"description": "Generate a QR code image for a URL, WiFi network, contact card, or text. Returns a hosted image URL and a base64 PNG.",
"parameters": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["url", "wifi", "contact", "text"],
"description": "QR code type"
},
"content": {
"type": "string",
"description": "Data to encode. For wifi use format: WIFI:T:WPA;S:<ssid>;P:<password>;;"
},
"size": {
"type": "integer",
"minimum": 64,
"maximum": 1024,
"description": "Output size in pixels. Defaults to 256."
}
},
"required": ["type", "content"]
}
}2. Implementation
async function generate_qr_code({ type, content, size = 256 }) {
const res = await fetch('https://theqrcode.io/api/public/qr-codes', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ type, content, settings: { size } }),
});
const data = await res.json();
return {
imageUrl: data.imageUrl, // shareable hosted URL, valid 24h
qrImage: data.qrImage, // base64 PNG for inline display
};
}3. Full example with OpenAI client
import OpenAI from 'openai';
const client = new OpenAI();
const tools = [{
type: 'function',
function: {
name: 'generate_qr_code',
description: 'Generate a QR code image for a URL, WiFi network, contact card, or text.',
parameters: {
type: 'object',
properties: {
type: { type: 'string', enum: ['url', 'wifi', 'contact', 'text'] },
content: { type: 'string' },
size: { type: 'integer', minimum: 64, maximum: 1024 },
},
required: ['type', 'content'],
},
},
}];
// When the model calls generate_qr_code, execute it:
async function handleToolCall(toolCall) {
const args = JSON.parse(toolCall.function.arguments);
const res = await fetch('https://theqrcode.io/api/public/qr-codes', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ type: args.type, content: args.content }),
});
return res.json();
}LangChain / LlamaIndex
Wrap the REST API as a tool and add it to your agent.
from langchain.tools import tool
import requests
@tool
def generate_qr_code(type: str, content: str, size: int = 256) -> dict:
"""Generate a QR code. type: url|wifi|contact|text. content: data to encode."""
res = requests.post(
'https://theqrcode.io/api/public/qr-codes',
json={'type': type, 'content': content, 'settings': {'size': size}},
)
data = res.json()
return {'imageUrl': data['imageUrl'], 'qrImage': data['qrImage']}What the tool returns
Two formats — use whichever fits your agent's output channel.
Hosted image URL
A shareable imageUrl pointing to a hosted PNG. Valid for 24 hours. Best for: sharing in chat, embedding in markdown, returning as a link.
data.imageUrlBase64 PNG
A qrImage data URL for inline rendering. Best for: displaying in UI, passing to vision models, saving locally.
data.qrImageAdd QR codes to your agent
Free, no auth, works today. Start with the REST API or connect via MCP in 60 seconds.