The Model Context Protocol (MCP) is an open standard that lets AI assistants call external tools mid-conversation. By exposing SwarmGen as an MCP tool, you can give Claude — or any compatible agent — the ability to generate a rendered image at any point in a workflow. The agent extracts the relevant data, selects the right template, and triggers a render without leaving the conversation.
How to set it up
- 1
Create a SwarmGen MCP server
Build a lightweight MCP server (Node.js or Python) that exposes a render_image tool. The tool accepts merge field values and calls the SwarmGen render API internally.
- 2
Register the tool definition
Define the tool schema: name, description, and input parameters (templateId + a fields object). A clear description helps the AI know when to invoke it.
- 3
Connect to Claude Desktop or your agent
Add your MCP server to claude_desktop_config.json or your agent runner. The AI will discover the tool and can call it in any conversation where image generation is relevant.
- 4
Receive rendered images in context
The MCP tool returns the image URL and job ID. The AI can include the URL in its response, pass it to another tool, or write it to an external system.
Code example
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { z } from 'zod'
const server = new McpServer({ name: 'swarmgen', version: '1.0.0' })
server.tool(
'render_image',
'Render a branded image from a SwarmGen template with merge field data',
{
templateId: z.string().describe('SwarmGen template ID'),
fields: z.record(z.string()).describe('Merge field values to inject'),
},
async ({ templateId, fields }) => {
const res = await fetch(`https://swarmgen.io/api/templates/${templateId}/render`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${process.env.SWARMGEN_API_KEY}` },
body: JSON.stringify({ data: fields, returnUrl: true }),
})
const { url, jobId } = await res.json()
return { content: [{ type: 'text', text: `Render complete — URL: ${url} (jobId: ${jobId})` }] }
}
)Bespoke integrations are not supported by our team. The sample code here is for guidance and you will need technical knowledge or a developer to implement it. We plan to release dedicated plugins for key tools as demand grows.
Ready to connect MCP?
Create a free account, build a template, and start generating images from your MCP workflows in minutes.
Get started free