Skip to main content
Glama
refgrow
by refgrow

create_affiliate

Add new affiliates to your referral program by providing their email address. Each affiliate receives a unique referral code to start tracking customer referrals.

Instructions

Create a new affiliate in your Refgrow project. An affiliate receives a unique referral code and can start referring customers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailYesEmail address for the new affiliate
referral_codeNoCustom referral code (auto-generated if not provided)
partner_slugNoPartner slug for URL tracking

Implementation Reference

  • The async handler function for create_affiliate tool that builds the request body and makes a POST API call to /affiliates endpoint
    async ({ email, referral_code, partner_slug }) => {
      try {
        const body: Record<string, unknown> = { email };
        if (referral_code) body.referral_code = referral_code;
        if (partner_slug) body.partner_slug = partner_slug;
    
        const data = await apiRequest(config, "POST", "/affiliates", body);
        return textResult(data);
      } catch (err) {
        return errorResult(err);
      }
    }
  • Zod schema defining input validation for create_affiliate: email (required, email format), referral_code (optional), and partner_slug (optional)
    {
      email: z.string().email().describe("Email address for the new affiliate"),
      referral_code: z
        .string()
        .optional()
        .describe(
          "Custom referral code (auto-generated if not provided)"
        ),
      partner_slug: z
        .string()
        .optional()
        .describe("Partner slug for URL tracking"),
    },
  • src/tools.ts:154-182 (registration)
    Complete tool registration with server.tool() including name 'create_affiliate', description, schema, and handler function
    server.tool(
      "create_affiliate",
      "Create a new affiliate in your Refgrow project. An affiliate receives a unique referral code and can start referring customers.",
      {
        email: z.string().email().describe("Email address for the new affiliate"),
        referral_code: z
          .string()
          .optional()
          .describe(
            "Custom referral code (auto-generated if not provided)"
          ),
        partner_slug: z
          .string()
          .optional()
          .describe("Partner slug for URL tracking"),
      },
      async ({ email, referral_code, partner_slug }) => {
        try {
          const body: Record<string, unknown> = { email };
          if (referral_code) body.referral_code = referral_code;
          if (partner_slug) body.partner_slug = partner_slug;
    
          const data = await apiRequest(config, "POST", "/affiliates", body);
          return textResult(data);
        } catch (err) {
          return errorResult(err);
        }
      }
    );
  • TypeScript interface CreateAffiliateInput defining the type structure for create_affiliate input parameters
    export interface CreateAffiliateInput {
      email: string;
      referral_code?: string;
      partner_slug?: string;
    }
  • apiRequest helper function that handles HTTP requests to the Refgrow API, including authentication and error handling
    async function apiRequest<T = unknown>(
      config: RefgrowConfig,
      method: string,
      path: string,
      body?: Record<string, unknown>,
      query?: Record<string, string | number | boolean | undefined>
    ): Promise<ApiResponse<T>> {
      const url = new URL(`/api/v1${path}`, config.baseUrl);
    
      if (query) {
        for (const [key, val] of Object.entries(query)) {
          if (val !== undefined && val !== null) {
            url.searchParams.set(key, String(val));
          }
        }
      }
    
      const headers: Record<string, string> = {
        Authorization: `Bearer ${config.apiKey}`,
        "Content-Type": "application/json",
        Accept: "application/json",
      };
    
      const fetchOptions: RequestInit = { method, headers };
      if (body && (method === "POST" || method === "PUT" || method === "PATCH")) {
        fetchOptions.body = JSON.stringify(body);
      }
    
      const response = await fetch(url.toString(), fetchOptions);
    
      // Handle 204 No Content (e.g. DELETE)
      if (response.status === 204) {
        return { success: true } as ApiResponse<T>;
      }
    
      const data = (await response.json()) as ApiResponse<T>;
    
      if (!response.ok) {
        throw new Error(
          data.error || `API request failed with status ${response.status}`
        );
      }
    
      return data;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that an affiliate 'receives a unique referral code' and 'can start referring customers', which adds some context about outcomes, but fails to address critical aspects like required permissions, error conditions, or what the response contains (e.g., success confirmation, affiliate ID).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, consisting of two clear sentences that directly state the tool's purpose and key outcomes. There is no wasted language, and every sentence contributes essential information efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a creation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., idempotency, error handling), return values, and usage context, which are crucial for an agent to invoke the tool correctly in a real-world scenario.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters. The description does not add any semantic details beyond the schema, such as explaining the significance of 'partner_slug' or constraints on 'referral_code'. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'create' and resource 'affiliate' with the context 'in your Refgrow project', making the purpose evident. It distinguishes from siblings like 'update_affiliate' or 'delete_affiliate' by specifying creation, but does not explicitly differentiate from other creation tools (e.g., 'create_conversion').

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, conditions for use, or comparisons with sibling tools like 'create_conversion' or 'create_coupon', leaving the agent without context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/refgrow/refgrow-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server