Skip to main content

Code generation

Two MCP tools help agents and copilots produce integration code without guessing payload shapes: ductape_generate_payload and ductape_generate_snippet.

Both call the Ductape backend at POST /integrations/v1/payloads/generate, authenticated with x-access-key: <public_key>.


Feature​


Operation families​

The operation_family argument groups SDK calls by component type. Each family maps to a specific SDK module path in generated snippets.

operation_familySDK moduleTypical methods
actionactionsrun, dispatch, execute
featurefeaturerun, dispatch, execute
databasedatabasesdispatch, find, insert, update, delete, query, upsert, count, aggregate
graphgraphdispatch, find, insert, update, delete, query, execute
vectorvectorquery, find, findSimilar, upsert, insert, delete, dispatch
storagestoragedispatch, upload, download, remove, listFiles, getSignedUrl, stats
notificationnotificationsdispatch, send, email.send, push.send, sms.send, callback.send
messagingmessageBrokersdispatch, send, publish, produce, consume
brokermessageBrokersSame as messaging
quotaquotasrun, dispatch, check, consume
fallbackfallbackrun, dispatch
healthcheckhealthrun, check, status
healthhealthrun, check, status
sessionsessionsstart, verify, refresh, revoke, listActive
cachecachesget, set, clear, clearAll, dispatch, fetchValues

If you call ductape_generate_snippet with an unsupported operation_family.method pair, the server returns an error listing allowed methods for that family.


Supported snippet operations​

Only these method names are valid for ductape_generate_snippet:

action​

run, dispatch, execute

feature​

run, dispatch, execute

database​

dispatch, find, insert, update, delete, query, upsert, count, aggregate

graph​

dispatch, find, insert, update, delete, query, execute

vector​

query, find, findSimilar, upsert, insert, delete, dispatch

storage​

dispatch, upload, download, remove, listFiles, getSignedUrl, stats

notification​

dispatch, send, email.send, push.send, sms.send, callback.send

messaging / broker​

dispatch, send, publish, produce, consume

quota​

run, dispatch, check, consume

fallback​

run, dispatch

healthcheck / health​

run, check, status

session​

start, verify, refresh, revoke, listActive

cache​

get, set, clear, clearAll, dispatch, fetchValues


Schema modes​

ModeBehavior
best_effort (default)Infer schema from available metadata; fill gaps with sensible defaults
strictRequire complete schema information; fail if metadata is insufficient

Use strict when generating production code that must match exact component schemas. Use best_effort for exploration and prototyping.


Targets​

The optional targets object tells the payload API which component to target:

{
"targets": {
"app": "stripe",
"action": "create-customer"
}
}
{
"targets": {
"database": "main-db",
"entity": "orders"
}
}
{
"targets": {
"vector": "embeddings-index"
}
}

Input hints​

Pass partial input structure to guide payload generation:

{
"input_hint": {
"entity": "users",
"where": { "status": { "$eq": "active" } },
"limit": 25
}
}

The backend merges hints with component schema metadata to produce a canonical payload.


Generated snippet format​

TypeScript​

import Ductape from "@ductape/sdk";

const ductape = new Ductape({
workspace_id: process.env.DUCTAPE_WORKSPACE_ID!,
user_id: process.env.DUCTAPE_USER_ID!,
public_key: process.env.DUCTAPE_PUBLIC_KEY!,
});

async function run() {
const payload = { /* generated template */ };
const args = { /* flattened invocation args */ };
const result = await ductape.actions.run(args);
return { payload, result };
}

run().catch(console.error);

Python​

from ductape import Ductape
import os
import json

ductape = Ductape(
workspace_id=os.environ.get("DUCTAPE_WORKSPACE_ID"),
user_id=os.environ.get("DUCTAPE_USER_ID"),
public_key=os.environ.get("DUCTAPE_PUBLIC_KEY"),
)

def run():
payload = { ... }
args = { ... }
result = ductape.actions.run(args)
return {"payload": payload, "result": result}

The SDK call path is resolved automatically (e.g. actions.run, databases.query, notifications.email.send).


CLI parity​

The Ductape CLI provides equivalent commands:

ductape generate payload --help
ductape generate snippet --help

See CLI generate. The MCP tools expose the same backend API for agent-driven features.


When to use which tool​

ScenarioTool
Agent needs payload shape onlyductape_generate_payload
Agent hands code to a developerductape_generate_snippet
Agent will execute immediatelyductape_execute (skip generation)
Exploring unknown component schemaductape_generate_payload with schema_mode: best_effort
Production code scaffoldductape_generate_snippet with schema_mode: strict