Skip to main content
Glama
benswel

QR for Agent

get_conversions

Retrieve conversion statistics for a QR code, including total conversions, total value, event breakdowns, daily trends, and recent events, to measure ROI and identify which codes drive the most value.

Instructions

Get conversion statistics for a QR code. Returns total conversions, total value, breakdowns by event name, daily trends, and recent events. Use this to measure QR code ROI and understand which codes drive the most value.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
short_idYesThe short_id of the QR code to get conversion stats for.
periodNoTime period for aggregations. Default: 30d.30d
eventNoFilter by event name (e.g., 'purchase').

Implementation Reference

  • MCP handler for get_conversions tool - calls the HTTP API endpoint /api/conversions/:short_id with query params.
      handler: async (input: { short_id: string; period: string; event?: string }) => {
        const query: Record<string, string> = { period: input.period };
        if (input.event) query.event = input.event;
        return apiRequest(`/api/conversions/${input.short_id}`, { query });
      },
    },
  • Zod input schema for get_conversions tool: requires short_id, optional period (7d/30d/90d/all, default 30d), optional event filter.
    inputSchema: z.object({
      short_id: z.string().describe("The short_id of the QR code to get conversion stats for."),
      period: z
        .enum(["7d", "30d", "90d", "all"])
        .default("30d")
        .describe("Time period for aggregations. Default: 30d."),
      event: z
        .string()
        .optional()
        .describe("Filter by event name (e.g., 'purchase')."),
    }),
  • Registration loop that iterates over all tools (including get_conversions) and registers them with the McpServer via server.tool().
    for (const [name, tool] of Object.entries(tools)) {
      server.tool(
        name,
        tool.description,
        tool.inputSchema.shape,
        async (input: Record<string, unknown>) => {
          try {
            const result = await tool.handler(input as any);
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(result, null, 2),
                },
              ],
            };
          } catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    error: message,
                    hint: "Check the input parameters and try again. Use list_qr_codes to verify available QR codes.",
                  }),
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • Backend service function getConversions() that queries the database for conversion stats: total count, total value, breakdown by event, daily trends, and recent events.
    export function getConversions(
      qrCodeId: number,
      shortId: string,
      period: string = "30d",
      eventFilter?: string
    ) {
      const periodStart = getPeriodStart(period);
    
      // Build conditions
      const conditions = [eq(conversionEvents.qrCodeId, qrCodeId)];
      if (periodStart) conditions.push(gt(conversionEvents.createdAt, periodStart));
      if (eventFilter) conditions.push(eq(conversionEvents.eventName, eventFilter));
    
      const whereClause = conditions.length === 1 ? conditions[0] : and(...conditions);
    
      // Total conversions
      const [{ total }] = db
        .select({ total: count() })
        .from(conversionEvents)
        .where(whereClause)
        .all();
    
      // Total value
      const [{ totalValue }] = db
        .select({ totalValue: sql<string | null>`SUM(CAST(${conversionEvents.value} AS REAL))` })
        .from(conversionEvents)
        .where(whereClause)
        .all();
    
      // By event
      const byEvent = db.all<{ event_name: string; count: number; total_value: string | null }>(
        sql`SELECT ${conversionEvents.eventName} as event_name, COUNT(*) as count,
            SUM(CAST(${conversionEvents.value} AS REAL)) as total_value
            FROM conversion_events
            WHERE ${whereClause}
            GROUP BY ${conversionEvents.eventName}
            ORDER BY count DESC`
      );
    
      // By day
      const byDay = db.all<{ date: string; count: number; total_value: string | null }>(
        sql`SELECT date(${conversionEvents.createdAt}) as date, COUNT(*) as count,
            SUM(CAST(${conversionEvents.value} AS REAL)) as total_value
            FROM conversion_events
            WHERE ${whereClause}
            GROUP BY date(${conversionEvents.createdAt})
            ORDER BY date ASC`
      );
    
      // Recent events (last 20)
      const recent = db
        .select()
        .from(conversionEvents)
        .where(whereClause)
        .orderBy(sql`${conversionEvents.createdAt} DESC`)
        .limit(20)
        .all();
    
      return {
        short_id: shortId,
        total_conversions: total,
        total_value: totalValue ? parseFloat(totalValue) : 0,
        period,
        by_event: byEvent.map((e) => ({
          event_name: e.event_name,
          count: e.count,
          total_value: e.total_value ? parseFloat(e.total_value) : 0,
        })),
        by_day: byDay.map((d) => ({
          date: d.date,
          count: d.count,
          total_value: d.total_value ? parseFloat(d.total_value) : 0,
        })),
        recent_events: recent.map((r) => ({
          event_name: r.eventName,
          value: r.value ? parseFloat(r.value) : null,
          metadata: r.metadata ? JSON.parse(r.metadata) : null,
          created_at: r.createdAt,
        })),
      };
    }
  • Fastify JSON schema for the conversion stats API endpoint (GET /:shortId) with shortId param, period enum, and optional event filter.
    export const conversionStatsSchema = {
      params: {
        type: "object" as const,
        required: ["shortId"],
        properties: {
          shortId: {
            type: "string",
            description: "The short_id of the QR code to get conversion stats for.",
          },
        },
      },
      querystring: {
        type: "object" as const,
        properties: {
          period: {
            type: "string",
            enum: ["7d", "30d", "90d", "all"],
            default: "30d",
            description: "Time period for aggregations. Default: 30d.",
          },
          event: {
            type: "string",
            description: "Filter by event name (e.g., 'purchase').",
          },
        },
      },
    };
Behavior3/5

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

No annotations exist, so description must disclose behavioral traits. It does not explicitly state read-only nature, rate limits, or data freshness. It implies a read operation but could be more transparent.

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?

Two sentences: first defines function and outputs, second gives use case. No redundant words. Highly concise and front-loaded.

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

Completeness4/5

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

Given 3 parameters, no output schema, no annotations, description covers purpose and return value adequately. Missing only explicit read-only flag, but otherwise complete.

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% with descriptions. Description adds context about returns but does not add much parameter-specific meaning beyond schema. Baseline 3 applies.

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?

Description clearly states the verb 'Get conversion statistics' and the resource 'QR code'. It lists specific return types (total conversions, total value, breakdowns by event name, daily trends, recent events), distinguishing it from siblings like record_conversion or get_qr_analytics.

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?

Explicitly tells when to use: 'to measure QR code ROI and understand which codes drive the most value'. Does not mention alternatives or when not to use, but purpose is clear enough 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/benswel/qr-agent-core'

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