Skip to main content
Glama
zhiyingzzhou

AI Notify MCP

by zhiyingzzhou

show_completion_notification

Display system notifications when AI finishes generating responses in MCP-compatible code editors, supporting macOS, Windows, and Linux with customizable titles, messages, and sound options.

Instructions

Show a system notification when AI completes a response

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleNoNotification titleAI Assistant
messageNoNotification message已完成回答
soundNoPlay notification sound

Implementation Reference

  • The handler function for the 'show_completion_notification' tool. It extracts title, message, and sound from arguments, formats the title with project name, sends the notification using notificationService, and returns a success message.
    case 'show_completion_notification': {
      const title = (args?.title as string) || 'AI Assistant';
      const message = (args?.message as string) || '已完成回答';
      const sound = (args?.sound as boolean) ?? true;
    
      await notificationService.notify({
        title: formatNotificationTitle(title, projectName),
        message,
        sound,
        icon: iconPath,
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `✅ 系统通知已发送: "${message}"`,
          },
        ],
      };
    }
  • Input schema for the 'show_completion_notification' tool defining properties for title, message, and sound with descriptions and defaults.
    inputSchema: {
      type: 'object',
      properties: {
        title: {
          type: 'string',
          description: 'Notification title',
          default: 'AI Assistant',
        },
        message: {
          type: 'string',
          description: 'Notification message',
          default: '已完成回答',
        },
        sound: {
          type: 'boolean',
          description: 'Play notification sound',
          default: true,
        },
      },
    },
  • src/index.ts:140-163 (registration)
    Registration of the 'show_completion_notification' tool in the listTools response, including name, description, and input schema.
    {
      name: 'show_completion_notification',
      description: 'Show a system notification when AI completes a response',
      inputSchema: {
        type: 'object',
        properties: {
          title: {
            type: 'string',
            description: 'Notification title',
            default: 'AI Assistant',
          },
          message: {
            type: 'string',
            description: 'Notification message',
            default: '已完成回答',
          },
          sound: {
            type: 'boolean',
            description: 'Play notification sound',
            default: true,
          },
        },
      },
    },
  • Helper function createNotificationService that creates a cross-platform notification service using node-notifier, handling different OS-specific options and fallbacks.
    const createNotificationService = (): NotificationService => {
      // 创建 notifier 实例
      const notifier = new NodeNotifier.NotificationCenter();
    
      return {
        notify: (options: NotificationOptions): Promise<void> => {
          return new Promise((resolve, reject) => {
            try {
              const platform = os.platform();
              const iconPath = getNotificationIcon();
    
              const finalOptions: NotificationOptions = {
                ...options,
                wait: false,
                timeout: 5,
              };
    
              // 根据平台配置声音和图标
              if (options.sound) {
                if (platform === 'darwin') {
                  finalOptions.sound = 'Ping';
                  // 在 macOS 上使用 contentImage 显示图标
                  finalOptions.contentImage = iconPath;
                } else if (platform === 'win32') {
                  finalOptions.sound = true;
                  finalOptions.icon = iconPath;
                } else if (platform === 'linux') {
                  finalOptions.urgency = 'normal';
                  finalOptions.icon = iconPath;
                }
              }
    
              // 调用通知
              notifier.notify(finalOptions, (error: Error | null) => {
                if (error) {
                  console.error('通知发送失败:', error);
                  // 尝试使用备用方案
                  try {
                    console.log(`[${options.title}] ${options.message}`);
                    resolve();
                  } catch (fallbackErr) {
                    reject(fallbackErr);
                  }
                } else {
                  resolve();
                }
              });
            } catch (err) {
              console.error('通知服务错误:', err);
              reject(err);
            }
          });
        },
      };
    };

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/zhiyingzzhou/ai-notify-mcp'

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