Skip to main content
Glama

send_notification

Send notifications to Discord or Slack via webhooks, including messages, embeds, and attachments, with automatic service detection, retry logic, and secure input validation.

Instructions

Send a notification to Discord and/or Slack webhooks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
avatar_urlNo
embed_jsonNo
messageNo
serviceNo
ttsNo
usernameNo

Implementation Reference

  • Full implementation of the send_notification tool handler, including inline schema validation, service detection, payload construction, API calls to Discord/Slack, error handling, and result aggregation.
    server.tool(
      "send_notification",
      "Send a notification to Discord and/or Slack webhooks",
      {
        message: z.string().optional(),
        service: z.enum(["discord", "slack", "both"]).optional(),
        embed_json: z.union([z.string(), z.object({}).passthrough(), z.array(z.unknown())]).optional(),
        username: z.string().optional(),
        avatar_url: z.string().url().optional(),
        tts: z.boolean().optional(),
      },
      async (args) => {
        // Validate that either message or embed_json is provided
        if (!args.message && args.embed_json === undefined) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ 
                  error: "You must provide either message or embed_json parameter" 
                }, null, 2)
              }
            ]
          };
        }
    
        try {
          const targetServices = detectService(args.service);
          const config = getConfig();
          const results: ServiceResult[] = [];
    
          for (const service of targetServices) {
            try {
              let result;
              
              if (service === "discord") {
                const payload = buildDiscordPayload({
                  message: args.message,
                  embedJson: args.embed_json,
                  username: args.username,
                  avatarUrl: args.avatar_url,
                  tts: args.tts
                });
                result = await sendDiscord(config.discordWebhookUrl!, payload);
              } else {
                const payload = buildSlackPayload({
                  message: args.message,
                  embedJson: args.embed_json,
                  username: args.username,
                  avatarUrl: args.avatar_url
                });
                result = await sendSlack(config.slackWebhookUrl!, payload);
              }
    
              results.push({
                service,
                success: result.success,
                httpCode: result.httpCode,
                timestamp: result.timestamp
              });
            } catch (error) {
              results.push({
                service,
                success: false,
                error: error instanceof Error ? error.message : "Unknown error"
              });
            }
          }
    
          const overall = results.some(r => r.success);
          const response: SendResult = {
            success: overall,
            overall,
            results
          };
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(response, null, 2)
              }
            ]
          };
        } catch (error) {
          const errorMsg = error instanceof Error ? error.message : "Unknown error";
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ error: errorMsg }, null, 2)
              }
            ]
          };
        }
      }
    );
  • Zod input schema for the send_notification tool parameters.
    export const SendNotificationSchema = z.object({
      message: z.string().optional(),
      service: ServiceSchema.optional(),
      embed_json: z.union([z.string(), z.object({}).passthrough(), z.array(z.unknown())]).optional(),
      username: z.string().optional(),
      avatar_url: z.string().url().optional(),
      tts: z.boolean().optional(),
    });
  • Helper function to send notifications to Discord webhook with retry logic.
    export async function sendDiscord(
      webhookUrl: string, 
      payload: object, 
      maxRetries = 2
    ): Promise<HttpResult> {
      logger.debug("Sending Discord notification");
      
      const result = await postJsonWithRetries(webhookUrl, payload, "discord", maxRetries);
      
      logger.serviceResult("discord", result.success, result.httpCode);
      
      if (!result.success && result.httpCode > 0) {
        logger.apiError("discord", result.httpCode, maxRetries + 1);
      }
      
      return result;
    }
  • Helper function to send notifications to Slack webhook with retry logic.
    export async function sendSlack(
      webhookUrl: string, 
      payload: object, 
      maxRetries = 2
    ): Promise<HttpResult> {
      logger.debug("Sending Slack notification");
      
      const result = await postJsonWithRetries(webhookUrl, payload, "slack", maxRetries);
      
      logger.serviceResult("slack", result.success, result.httpCode);
      
      if (!result.success && result.httpCode > 0) {
        logger.apiError("slack", result.httpCode, maxRetries + 1);
      }
      
      return result;
    }
  • Core HTTP POST helper with retries, rate limiting handling, and error management used by both sendDiscord and sendSlack.
    async function postJsonWithRetries(
      url: string, 
      payload: object, 
      service: "discord" | "slack",
      maxRetries = 2
    ): Promise<HttpResult> {
      let attempt = 0;
      
      while (true) {
        attempt++;
        
        try {
          const response = await fetch(url, {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify(payload),
          });
    
          // Success cases
          if (response.status === 200 || response.status === 204) {
            return {
              success: true,
              httpCode: response.status,
              timestamp: new Date().toISOString(),
            };
          }
    
          // Rate limiting (429) - retry with delay
          if (response.status === 429 && attempt <= maxRetries) {
            const retryAfterHeader = response.headers.get("retry-after");
            const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : 1;
            const delayMs = retryAfter * 1000;
            
            logger.retryAttempt(service, attempt, maxRetries, delayMs);
            await sleep(delayMs);
            continue;
          }
    
          // Other error - read body safely for context
          const errorBody = await safeReadBody(response);
          
          return {
            success: false,
            httpCode: response.status,
            timestamp: new Date().toISOString(),
          };
          
        } catch (error) {
          if (attempt <= maxRetries) {
            logger.retryAttempt(service, attempt, maxRetries, 1000);
            await sleep(1000);
            continue;
          }
          
          return {
            success: false,
            httpCode: 0, // Network error
            timestamp: new Date().toISOString(),
          };
        }
      }
    }
Behavior1/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the basic action without mentioning critical traits like required webhook setup, authentication needs, rate limits, error handling, or what happens on failure. This is inadequate for a tool that likely involves external API calls and potential side effects.

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 a single, efficient sentence that directly states the tool's purpose without any fluff. It's appropriately sized and front-loaded, making it easy to grasp immediately, which is ideal for conciseness.

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

Completeness1/5

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

Given the complexity of sending notifications to external services, no annotations, no output schema, and 0% schema coverage, the description is severely incomplete. It lacks essential details like prerequisites (e.g., webhook URLs), behavioral expectations, and error handling, making it inadequate for safe and effective use by an AI agent.

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

Parameters2/5

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

With 0% schema description coverage for 6 parameters, the description adds no meaning beyond the schema. It doesn't explain what parameters like 'avatar_url', 'embed_json', or 'tts' do, how they interact, or provide examples. The description fails to compensate for the lack of schema documentation, leaving parameters largely unexplained.

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 action ('send a notification') and target destinations ('Discord and/or Slack webhooks'), which is specific and actionable. However, it doesn't distinguish this tool from its siblings (list_services, validate_webhook), which are clearly different operations, so it doesn't reach the highest score.

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, such as whether it's for urgent alerts or general messaging, or how it relates to sibling tools like validate_webhook. It mentions multiple services but doesn't clarify when to choose one over another, leaving usage context implied at best.

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

Related 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/thesammykins/notifyme_mcp'

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