Skip to main content
Glama
benswel

QR for Agent

set_utm_params

Set UTM tracking parameters on a URL QR code to attribute scans to specific marketing campaigns. Parameters like source, medium, and campaign are appended to the target URL on each scan. Use the clear option to remove all UTM parameters.

Instructions

Set UTM tracking parameters on a URL QR code. These parameters are automatically appended to the target URL on every scan redirect. Use this to track QR code scans in Google Analytics or other analytics tools. Set 'clear' to true to remove all UTM parameters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
short_idYesThe short ID of the QR code (must be type='url').
sourceNoutm_source value (e.g. 'flyer', 'email', 'poster').
mediumNoutm_medium value (e.g. 'print', 'qr', 'social').
campaignNoutm_campaign value (e.g. 'summer_2026').
termNoutm_term value (paid search keyword).
contentNoutm_content value (A/B test variant).
clearNoSet to true to remove all UTM parameters from this QR code.

Implementation Reference

  • The handler function for set_utm_params. Builds a body with utm_params (or null to clear) and PATCHes the QR code via the API.
    handler: async (input: { short_id: string; source?: string; medium?: string; campaign?: string; term?: string; content?: string; clear?: boolean }) => {
      const body: Record<string, unknown> = {};
      if (input.clear) {
        body.utm_params = null;
      } else {
        const utm: Record<string, string> = {};
        if (input.source) utm.source = input.source;
        if (input.medium) utm.medium = input.medium;
        if (input.campaign) utm.campaign = input.campaign;
        if (input.term) utm.term = input.term;
        if (input.content) utm.content = input.content;
        body.utm_params = utm;
      }
      return apiRequest(`/api/qr/${input.short_id}`, { method: "PATCH", body });
    },
  • Zod schema defining the input: short_id (required), source/medium/campaign/term/content (optional strings), clear (optional boolean).
    inputSchema: z.object({
      short_id: z.string().describe("The short ID of the QR code (must be type='url')."),
      source: z.string().optional().describe("utm_source value (e.g. 'flyer', 'email', 'poster')."),
      medium: z.string().optional().describe("utm_medium value (e.g. 'print', 'qr', 'social')."),
      campaign: z.string().optional().describe("utm_campaign value (e.g. 'summer_2026')."),
      term: z.string().optional().describe("utm_term value (paid search keyword)."),
      content: z.string().optional().describe("utm_content value (A/B test variant)."),
      clear: z.boolean().optional().describe("Set to true to remove all UTM parameters from this QR code."),
    }),
  • All tools (including set_utm_params) are registered via server.tool() in a loop over the tools object.
    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,
            };
          }
        }
      );
  • The tool definition object set_utm_params is part of the exported 'tools' object, which is imported and registered in server.ts.
    set_utm_params: {
      description:
        "Set UTM tracking parameters on a URL QR code. These parameters are automatically appended to the target URL on every scan redirect. Use this to track QR code scans in Google Analytics or other analytics tools. Set 'clear' to true to remove all UTM parameters.",
      inputSchema: z.object({
        short_id: z.string().describe("The short ID of the QR code (must be type='url')."),
        source: z.string().optional().describe("utm_source value (e.g. 'flyer', 'email', 'poster')."),
        medium: z.string().optional().describe("utm_medium value (e.g. 'print', 'qr', 'social')."),
        campaign: z.string().optional().describe("utm_campaign value (e.g. 'summer_2026')."),
        term: z.string().optional().describe("utm_term value (paid search keyword)."),
        content: z.string().optional().describe("utm_content value (A/B test variant)."),
        clear: z.boolean().optional().describe("Set to true to remove all UTM parameters from this QR code."),
      }),
      handler: async (input: { short_id: string; source?: string; medium?: string; campaign?: string; term?: string; content?: string; clear?: boolean }) => {
        const body: Record<string, unknown> = {};
        if (input.clear) {
          body.utm_params = null;
        } else {
          const utm: Record<string, string> = {};
          if (input.source) utm.source = input.source;
          if (input.medium) utm.medium = input.medium;
          if (input.campaign) utm.campaign = input.campaign;
          if (input.term) utm.term = input.term;
          if (input.content) utm.content = input.content;
          body.utm_params = utm;
        }
        return apiRequest(`/api/qr/${input.short_id}`, { method: "PATCH", body });
      },
    },
  • The apiRequest helper function used by the handler to call the backend API.
    export async function apiRequest(path: string, options: RequestOptions = {}) {
      const { method = "GET", body, query } = options;
    
      let url = `${BASE_URL}${path}`;
      if (query) {
        const params = new URLSearchParams();
        for (const [key, value] of Object.entries(query)) {
          params.set(key, String(value));
        }
        url += `?${params.toString()}`;
      }
    
      const headers: Record<string, string> = {
        "X-API-Key": API_KEY,
      };
    
      if (body) {
        headers["Content-Type"] = "application/json";
      }
    
      const res = await fetch(url, {
        method,
        headers,
        body: body ? JSON.stringify(body) : undefined,
      });
    
      return res.json();
    }
Behavior3/5

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

No annotations are provided, so the description must convey behavioral traits. It states that parameters are 'automatically appended to the target URL on every scan redirect' and that setting 'clear' to true removes all UTM parameters. However, it does not clarify whether setting a new value overwrites an existing one or if there are any side effects, leaving some ambiguity.

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

Conciseness4/5

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

The description is three sentences long, front-loaded with the main action, and uses clear language. It is concise but still covers key points. Slightly more detail on overwrite behavior could be added, but overall efficient.

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?

For a tool with 7 parameters and no output schema, the description adequately explains the core functionality: setting and clearing UTM parameters on redirect. It does not mention return values, but the schema implies success/failure (likely a confirmation). Given the tool's specificity, this is sufficient.

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?

The input schema has 100% description coverage, with each parameter clearly described (e.g., 'utm_source value (e.g. 'flyer', 'email', 'poster')'). The description adds no additional meaning beyond what the schema provides, so baseline 3 is appropriate.

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's purpose: 'Set UTM tracking parameters on a URL QR code.' It specifies the resource (URL QR code) and action (set UTM params), distinguishing it from siblings like 'update_qr_destination' which changes the target URL itself.

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 explains when to use the tool: 'to track QR code scans in Google Analytics or other analytics tools.' It does not explicitly state when not to use it or provide alternatives, but the context is sufficient for an agent to decide.

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