Skip to main content
Glama
benswel

QR for Agent

record_conversion

Record a post-scan conversion event (purchase, signup) to track ROI for a QR code. Include event name, optional value, and metadata.

Instructions

Record a post-scan conversion event (purchase, signup, etc.) for a QR code you own. Use this to track ROI — e.g., when a user scans a QR code and then makes a purchase, record a 'purchase' conversion with the order value. For client-side tracking without code, use the tracking pixel: .

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
short_idYesThe short_id of the QR code this conversion is for.
eventYesThe conversion event name (e.g., "purchase", "signup", "add_to_cart"). Use consistent names to aggregate stats.
valueNoOptional monetary value of the conversion (e.g., 49.99).
metadataNoOptional JSON metadata (e.g., product ID, order number).

Implementation Reference

  • MCP tool handler for 'record_conversion' — proxies the request to the POST /api/conversions API endpoint.
    handler: async (input: Record<string, unknown>) => {
      return apiRequest("/api/conversions", { method: "POST", body: input });
    },
  • Zod input schema for the 'record_conversion' tool: requires short_id and event, optional value and metadata.
    inputSchema: z.object({
      short_id: z.string().describe("The short_id of the QR code this conversion is for."),
      event: z
        .string()
        .max(100)
        .describe(
          'The conversion event name (e.g., "purchase", "signup", "add_to_cart"). Use consistent names to aggregate stats.'
        ),
      value: z
        .number()
        .optional()
        .describe("Optional monetary value of the conversion (e.g., 49.99)."),
      metadata: z
        .record(z.string(), z.unknown())
        .optional()
        .describe("Optional JSON metadata (e.g., product ID, order number)."),
    }),
  • Registration of the 'record_conversion' tool in the MCP tools dictionary, with description, inputSchema, and handler.
    record_conversion: {
      description:
        "Record a post-scan conversion event (purchase, signup, etc.) for a QR code you own. Use this to track ROI — e.g., when a user scans a QR code and then makes a purchase, record a 'purchase' conversion with the order value. For client-side tracking without code, use the tracking pixel: <img src=\"https://yourhost/t/{short_id}?event=purchase&value=49.99\">.",
      inputSchema: z.object({
        short_id: z.string().describe("The short_id of the QR code this conversion is for."),
        event: z
          .string()
          .max(100)
          .describe(
            'The conversion event name (e.g., "purchase", "signup", "add_to_cart"). Use consistent names to aggregate stats.'
          ),
        value: z
          .number()
          .optional()
          .describe("Optional monetary value of the conversion (e.g., 49.99)."),
        metadata: z
          .record(z.string(), z.unknown())
          .optional()
          .describe("Optional JSON metadata (e.g., product ID, order number)."),
      }),
      handler: async (input: Record<string, unknown>) => {
        return apiRequest("/api/conversions", { method: "POST", body: input });
      },
    },
  • Core service function that inserts a conversion event into the database and returns the created record.
    export function recordConversion(input: {
      qrCodeId: number;
      eventName: string;
      value?: number | null;
      metadata?: Record<string, unknown> | null;
      referer?: string | null;
      ip?: string | null;
    }) {
      const inserted = db
        .insert(conversionEvents)
        .values({
          qrCodeId: input.qrCodeId,
          eventName: input.eventName,
          value: input.value != null ? String(input.value) : null,
          metadata: input.metadata ? JSON.stringify(input.metadata) : null,
          referer: input.referer ?? null,
          ip: input.ip ?? null,
        })
        .returning()
        .get();
    
      return {
        id: inserted.id,
        event: inserted.eventName,
        value: inserted.value ? parseFloat(inserted.value) : null,
        metadata: inserted.metadata ? JSON.parse(inserted.metadata) : null,
        created_at: inserted.createdAt,
      };
    }
  • Fastify schema for the POST /api/conversions endpoint, defining request body and 201 response shape.
    export const conversionRecordSchema = {
      body: {
        type: "object" as const,
        required: ["short_id", "event"],
        properties: {
          short_id: {
            type: "string",
            description: "The short_id of the QR code this conversion is for.",
          },
          event: {
            type: "string",
            maxLength: 100,
            description:
              'The conversion event name (e.g., "purchase", "signup", "add_to_cart"). Use consistent names to aggregate stats.',
          },
          value: {
            type: "number",
            description: "Optional monetary value of the conversion (e.g., 49.99).",
          },
          metadata: {
            type: "object",
            additionalProperties: true,
            description:
              "Optional JSON metadata for the conversion (e.g., product ID, order number).",
          },
        },
      },
      response: {
        201: {
          type: "object",
          properties: {
            id: { type: "integer", description: "Conversion event ID." },
            short_id: { type: "string" },
            event: { type: "string" },
            value: { type: "number", nullable: true },
            metadata: { type: "object", nullable: true, additionalProperties: true },
            created_at: { type: "string" },
          },
        },
      },
    };
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool 'records' an event but fails to disclose side effects, authorization requirements, idempotency, or error handling. The implicit ownership mention is not elaborated.

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 three sentences: purpose, usage example, alternative. No redundant information, each sentence earns its place.

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?

No output schema, so description should explain return values or success/error signals. It does not. It also omits duplicate handling, rate limits, or permissions beyond implied ownership. For a mutation tool, this is insufficient.

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 coverage is 100%, so baseline is 3. The description adds context about consistent event names for aggregation and the monetary value example, but does not provide additional syntax or constraints beyond the schema.

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

Purpose5/5

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

The description clearly states the tool records a post-scan conversion event for a QR code you own, with specific examples (purchase, signup) and the purpose of tracking ROI. The verb 'record' and resource 'conversion' are specific and distinct from sibling tools like 'get_conversions'.

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

Usage Guidelines4/5

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

The description gives explicit usage context ('Use this to track ROI') and provides an alternative method (tracking pixel) for client-side tracking without code. It does not explicitly state when not to use this tool, but the alternative guidance helps differentiate use cases.

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/benswel/qr-agent-core'

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