Build an agent with the Claude API
Write an agent in your own code that works in heycreo on its own: it chooses a template, fills it with a text you hand it and exports it. The agent is Claude, called through the Claude API. Claude uses heycreo's MCP server; the Claude API connects to it for you, so your code needs no MCP client of its own.
You need:
- A heycreo API key of a service account, from Settings → Developers → Service accounts. Claude acts with the service account's permissions, in its workspace. MCP must be allowed for it (it is by default), with the toolsets this agent uses: Lesen, Designs aus Vorlagen and Export.
- A Claude API key from the Claude Console, in
ANTHROPIC_API_KEY. - Node.js 20 or later.
1. Install the SDK
npm install @anthropic-ai/sdk
2. Hand Claude the task
make-design.ts
import Anthropic from '@anthropic-ai/sdk'
const client = new Anthropic() // reads ANTHROPIC_API_KEY
const stream = client.beta.messages.stream({
model: 'claude-opus-5-5',
max_tokens: 64000,
output_config: { effort: 'high' },
betas: ['mcp-client-2025-11-20', 'server-side-fallback-2026-07-01'],
// If the model declines a request, the API retries it on a suitable model by itself.
fallbacks: 'default',
mcp_servers: [
{
type: 'url',
url: 'https://app.heycreo.io/api/mcp',
name: 'heycreo',
authorization_token: process.env.HEYCREO_API_KEY,
},
],
tools: [
{
type: 'mcp_toolset',
mcp_server_name: 'heycreo',
// Only these tools: read templates, create and fill a design, export it.
// Claude cannot delete, publish or change settings in this run.
default_config: { enabled: false },
configs: {
'get-templates': { enabled: true },
'create-template-design': { enabled: true },
'set-template-design-controls': { enabled: true },
'get-template-design': { enabled: true },
'studio-export': { enabled: true },
'get-exports': { enabled: true },
},
},
],
messages: [
{
role: 'user',
content:
'Create an Instagram post from our template "Summer sale". ' +
'Headline: "20 % off everything". Subline: "This weekend only". ' +
'Export it and give me the link to the file.',
},
],
})
const message = await stream.finalMessage()
if (message.stop_reason === 'refusal') {
console.error('Claude declined the request.')
} else {
for (const block of message.content) {
if (block.type === 'mcp_tool_use') console.log(`→ ${block.name}`)
if (block.type === 'text') console.log(block.text)
}
}
HEYCREO_API_KEY=heycreo_… npx tsx make-design.ts
The output shows each tool Claude called, then its answer with the link:
→ get-templates
→ create-template-design
→ studio-export
The post is ready: https://…
How it works
mcp_serverstells the Claude API where heycreo's MCP server is and which key to send. The API connects, lists the tools and runs every tool call Claude makes. Your code sends one request and receives the result.mcp_toolsetdecides which of heycreo's tools Claude may use.default_config: { enabled: false }switches all of them off;configsswitches on the ones the task needs. Start narrow and add tools when a task needs them:get-assetsto use an image from the media library,create-publicationto schedule the post.- The service account limits what any tool can do: to its own permissions and, on MCP, to its toolsets — not to what the person who created it may do. A design Claude creates is an ordinary design that people in the workspace see and can change in heycreo.
studio-exportwaits up to 25 seconds for the file. A longer video comes back as still rendering; Claude then checks withget-exports, or you leave the waiting to a webhook.
See also
- MCP server and its tool reference
- MCP connector in the Claude documentation