generate_tracked_link
Generate tracked affiliate links for any program by providing a program slug and end user ID. Records clicks and attributes signups or commissions to the specified user.
Instructions
Generate a tracked affiliate link for a program and an end user. Pass the human-readable program slug (e.g. 'webflow') -- the tool resolves the UUID automatically. The link records clicks and attributes any resulting signups or commissions back to the specified end user. Returns a short redirect URL and a tracking_code you should save -- it is needed for record_signup and record_commission.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| program_slug | Yes | Slug of the affiliate program (e.g. 'webflow', 'notion'). Use list_affiliate_programs to find available slugs. | |
| end_user_id | Yes | Your internal ID for the end user who will receive credit for this referral. Can be any stable unique string (UUID, email, username, etc.). | |
| metadata | No | Optional key-value metadata to attach to the link (e.g. { campaign: 'onboarding', source: 'chat' }). |
Implementation Reference
- src/index.js:136-168 (schema)Tool definition and inputSchema for 'generate_tracked_link'. Describes parameters program_slug, end_user_id, and optional metadata.
name: "generate_tracked_link", description: "Generate a tracked affiliate link for a program and an end user. " + "Pass the human-readable program slug (e.g. 'webflow') -- the tool resolves the UUID automatically. " + "The link records clicks and attributes any resulting signups or commissions " + "back to the specified end user. Returns a short redirect URL and a tracking_code " + "you should save -- it is needed for record_signup and record_commission.", inputSchema: { type: "object", properties: { program_slug: { type: "string", description: "Slug of the affiliate program (e.g. 'webflow', 'notion'). " + "Use list_affiliate_programs to find available slugs.", }, end_user_id: { type: "string", description: "Your internal ID for the end user who will receive credit for this referral. " + "Can be any stable unique string (UUID, email, username, etc.).", }, metadata: { type: "object", description: "Optional key-value metadata to attach to the link " + "(e.g. { campaign: 'onboarding', source: 'chat' }).", additionalProperties: { type: "string" }, }, }, required: ["program_slug", "end_user_id"], }, }, - src/index.js:336-362 (handler)Handler function handleGenerateTrackedLink that validates inputs, resolves program_slug to UUID via AgentFuse catalog API, and generates a tracked link via POST /api/links/generate.
async function handleGenerateTrackedLink(args) { if (!args.program_slug) { throw new McpError(ErrorCode.InvalidParams, "program_slug is required"); } if (!args.end_user_id) { throw new McpError(ErrorCode.InvalidParams, "end_user_id is required"); } // Step 1: resolve slug -> UUID const catalogData = await agentfuse("GET", `/api/catalog/${encodeURIComponent(args.program_slug)}`); const program_id = catalogData?.data?.id; if (!program_id) { throw new McpError( ErrorCode.InvalidParams, `Program not found for slug "${args.program_slug}". Use list_affiliate_programs to check available slugs.` ); } // Step 2: generate the tracked link const body = { program_id, end_user_id: args.end_user_id, }; if (args.metadata) body.metadata = args.metadata; return agentfuse("POST", "/api/links/generate", body); } - src/index.js:446-454 (registration)Dispatch map (HANDLERS) that registers 'generate_tracked_link' to the handleGenerateTrackedLink function.
export const HANDLERS = { list_affiliate_programs: handleListAffiliatePrograms, get_affiliate_program: handleGetAffiliateProgram, generate_tracked_link: handleGenerateTrackedLink, list_tracked_links: handleListTrackedLinks, get_stats: handleGetStats, record_signup: handleRecordSignup, record_commission: handleRecordCommission, }; - src/index.js:32-78 (helper)The agentfuse helper function used by handleGenerateTrackedLink to make REST API calls to AgentFuse.
export async function agentfuse(method, path, body = null) { const apiKey = process.env.AGENTFUSE_API_KEY || ""; const baseUrl = (process.env.AGENTFUSE_API_URL || "https://api.agentfuse.io").replace(/\/$/, ""); if (!apiKey) { throw new McpError( ErrorCode.InvalidRequest, "AGENTFUSE_API_KEY environment variable is not set. " + "Get a key at https://agentfuse.io and add it to your MCP config." ); } const url = `${baseUrl}${path}`; const headers = { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", "User-Agent": "agentfuse-mcp/1.1.2", }; const options = { method, headers }; if (body !== null) { options.body = JSON.stringify(body); } const res = await fetch(url, options); const text = await res.text(); let data; try { data = JSON.parse(text); } catch { throw new McpError( ErrorCode.InternalError, `AgentFuse API returned non-JSON response (status ${res.status}): ${text.slice(0, 200)}` ); } if (!res.ok) { const msg = data?.error || data?.message || JSON.stringify(data); throw new McpError( ErrorCode.InternalError, `AgentFuse API error ${res.status}: ${msg}` ); } return data; }