Skip to main content
Glama

send_notification

Send customizable notifications on macOS devices by specifying a title, message, optional subtitle, and sound settings using the osascript command.

Instructions

Send a notification on macOS using osascript

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageYesMain message content
soundNoWhether to play the default notification sound
subtitleNoOptional subtitle
titleYesTitle of the notification

Implementation Reference

  • Main handler function for send_notification tool. Validates input parameters, constructs AppleScript for osascript to display macOS notification, executes the command, and handles errors appropriately.
    export async function sendNotification(params: NotificationParams): Promise<void> {
      try {
        validateParams(params);
        const command = buildNotificationCommand(params);
        await execAsync(command);
      } catch (error) {
        if (error instanceof NotificationError) {
          throw error;
        }
    
        // Handle different types of system errors
        const err = error as Error;
        if (err.message.includes('execution error')) {
          throw new NotificationError(
            NotificationErrorType.COMMAND_FAILED,
            'Failed to execute notification command'
          );
        } else if (err.message.includes('permission')) {
          throw new NotificationError(
            NotificationErrorType.PERMISSION_DENIED,
            'Permission denied when trying to send notification'
          );
        } else {
          throw new NotificationError(
            NotificationErrorType.UNKNOWN,
            `Unexpected error: ${err.message}`
          );
        }
      }
    }
  • TypeScript interface defining the input parameters (NotificationParams) used by the send_notification handler.
    export interface NotificationParams {
      /** Title of the notification */
      title: string;
      /** Main message content */
      message: string;
      /** Optional subtitle */
      subtitle?: string;
      /** Whether to play the default notification sound */
      sound?: boolean;
    }
  • src/index.ts:59-85 (registration)
    Tool registration in the MCP server's listTools handler, including name, description, and input schema matching NotificationParams.
      name: 'send_notification',
      description: 'Send a notification on macOS using osascript',
      inputSchema: {
        type: 'object',
        properties: {
          title: {
            type: 'string',
            description: 'Title of the notification',
          },
          message: {
            type: 'string',
            description: 'Main message content',
          },
          subtitle: {
            type: 'string',
            description: 'Optional subtitle',
          },
          sound: {
            type: 'boolean',
            description: 'Whether to play the default notification sound',
            default: true,
          },
        },
        required: ['title', 'message'],
        additionalProperties: false,
      },
    },
  • MCP CallToolRequestSchema dispatch handler for 'send_notification': parses arguments, validates basics, constructs NotificationParams, calls sendNotification, and returns success response.
    case 'send_notification': {
      const { title, message, subtitle, sound } = request.params.arguments as Record<string, unknown>;
      
      if (typeof title !== 'string' || typeof message !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'Title and message must be strings');
      }
    
      const params: NotificationParams = {
        title,
        message,
        subtitle: typeof subtitle === 'string' ? subtitle : undefined,
        sound: typeof sound === 'boolean' ? sound : undefined
      };
    
      await sendNotification(params);
      return {
        content: [
          {
            type: 'text',
            text: 'Notification sent successfully',
          },
        ],
      };
    }
  • Helper function to validate NotificationParams inputs before sending the notification.
    function validateParams(params: NotificationParams): void {
      if (!params.title || typeof params.title !== 'string') {
        throw new NotificationError(
          NotificationErrorType.INVALID_PARAMS,
          'Title is required and must be a string'
        );
      }
    
      if (!params.message || typeof params.message !== 'string') {
        throw new NotificationError(
          NotificationErrorType.INVALID_PARAMS,
          'Message is required and must be a string'
        );
      }
    
      if (params.subtitle && typeof params.subtitle !== 'string') {
        throw new NotificationError(
          NotificationErrorType.INVALID_PARAMS,
          'Subtitle must be a string'
        );
      }
    }
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/turlockmike/apple-notifier-mcp'

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