Skip to main content
Glama
benswel

QR for Agent

create_webhook

Register a webhook to receive real-time notifications when QR codes are scanned. Returns a one-time HMAC-SHA256 secret for secure verification of webhook signatures.

Instructions

Register a webhook endpoint to receive real-time notifications when QR codes are scanned. Returns an HMAC-SHA256 secret for verifying webhook signatures — store it securely, it is only shown once.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe endpoint URL that will receive POST requests with scan event data.
eventsNoEvents to subscribe to. Currently supported: "qr.scanned".

Implementation Reference

  • MCP tool handler for 'create_webhook' - calls the HTTP API's POST /api/webhooks endpoint with url and events parameters.
    create_webhook: {
      description:
        "Register a webhook endpoint to receive real-time notifications when QR codes are scanned. Returns an HMAC-SHA256 secret for verifying webhook signatures — store it securely, it is only shown once.",
      inputSchema: z.object({
        url: z
          .string()
          .url()
          .describe("The endpoint URL that will receive POST requests with scan event data."),
        events: z
          .array(z.enum(["qr.scanned"]))
          .default(["qr.scanned"])
          .describe('Events to subscribe to. Currently supported: "qr.scanned".'),
      }),
      handler: async (input: { url: string; events?: string[] }) => {
        return apiRequest("/api/webhooks", { method: "POST", body: input });
      },
    },
  • Zod input schema for the 'create_webhook' MCP tool - accepts a url (string, url format) and optional events array (defaulting to ['qr.scanned']).
    inputSchema: z.object({
      url: z
        .string()
        .url()
        .describe("The endpoint URL that will receive POST requests with scan event data."),
      events: z
        .array(z.enum(["qr.scanned"]))
        .default(["qr.scanned"])
        .describe('Events to subscribe to. Currently supported: "qr.scanned".'),
    }),
  • Generic tool registration loop that registers all tools (including create_webhook) in the MCP server using the McpServer SDK.
    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,
            };
          }
        }
      );
    }
  • Helper function apiRequest used by the handler to make HTTP POST requests to the webhook API endpoint.
    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();
    }
  • Actual service-level implementation that creates a webhook - checks plan quota, generates a secret via nanoid, inserts into the database, and returns the created webhook.
    export function createWebhook(
      url: string,
      events: string[],
      apiKeyId: number,
      plan: Plan = "free"
    ) {
      // Check plan quota
      const limits = PLAN_LIMITS[plan];
      if (limits.maxWebhooks !== Infinity) {
        const [{ total }] = db
          .select({ total: count() })
          .from(webhooks)
          .where(eq(webhooks.apiKeyId, apiKeyId))
          .all();
    
        if (total >= limits.maxWebhooks) {
          return { error: "WEBHOOK_LIMIT_REACHED" as const, limit: limits.maxWebhooks };
        }
      }
    
      const secret = nanoid(32);
    
      const inserted = db
        .insert(webhooks)
        .values({
          apiKeyId,
          url,
          secret,
          events: JSON.stringify(events),
          isActive: true,
        })
        .returning()
        .get();
    
      return {
        id: inserted.id,
        url: inserted.url,
        secret: inserted.secret,
        events: JSON.parse(inserted.events) as string[],
        is_active: inserted.isActive,
        created_at: inserted.createdAt,
      };
    }
Behavior4/5

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

With no annotations, the description carries the full burden. It discloses that the tool returns an HMAC-SHA256 secret shown only once, which is critical. Does not cover limits or error cases, but provides essential behavioral context.

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 states purpose, second explains return value and security warning. No unnecessary words, 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?

For a simple tool with two parameters and no output schema, the description covers purpose, return, and security. Lacks error handling details but is mostly 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 for both parameters (url and events). The main description does not add extra information about parameters, 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 registers a webhook endpoint to receive real-time notifications on QR code scans, with a specific verb ('register') and resource, distinguishing it from sibling tools like delete_webhook and list_webhooks.

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 implies usage for receiving webhook notifications but does not explicitly mention when not to use or compare with alternatives. However, sibling names are distinct, so context is clear enough.

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