play_notification
Trigger a notification sound to signal task completion, optionally displaying a message. Integrates with the Notifications MCP Server for AI agents to communicate status updates effectively.
Instructions
Play a notification sound to indicate task completion
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | No | Optional message to display with notification |
Implementation Reference
- src/index.ts:97-130 (handler)Handler for the play_notification tool. Checks the tool name, determines the sound file, executes platform-specific play command, and returns success or error message.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== "play_notification") { throw new Error("Unknown tool"); } try { // Get the sound file to play (potentially random) const SOUND_FILE_TO_PLAY = getSoundFile(); // Play sound using platform-specific command const command = process.platform === 'win32' ? `start "" "${SOUND_FILE_TO_PLAY}"` : `afplay "${SOUND_FILE_TO_PLAY}"`; await execAsync(command); return { content: [{ type: "text", text: request.params.arguments?.message ? `Notification played: ${request.params.arguments.message}` : "Notification played successfully" }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to play notification: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/index.ts:73-91 (registration)Registers the play_notification tool via ListToolsRequestHandler, providing name, description, and input schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "play_notification", description: "Play a notification sound to indicate task completion", inputSchema: { type: "object", properties: { message: { type: "string", description: "Optional message to display with notification" } } } } ] }; });
- src/index.ts:79-88 (schema)Input schema for play_notification tool: optional string message.inputSchema: { type: "object", properties: { message: { type: "string", description: "Optional message to display with notification" } } } }
- src/index.ts:41-52 (helper)Helper function to determine the sound file path based on environment variables, random selection, or default.function getSoundFile(): string { if (USER_CONFIGURED_SOUND_PATH) { return USER_CONFIGURED_SOUND_PATH; } if (DEFAULT_SOUND_NAME === 'random') { return path.join(__dirname, '..', getRandomSound()); } const DEFAULT_SOUND_FILE = SOUND_FILES[DEFAULT_SOUND_NAME as keyof typeof SOUND_FILES] || SOUND_FILES.gentle; return path.join(__dirname, '..', DEFAULT_SOUND_FILE); }
- src/index.ts:21-27 (helper)Constant mapping sound names to file paths used by the notification tool.const SOUND_FILES = { cosmic: 'sounds/cosmic_chime.mp3', fairy: 'sounds/fairy_chime.mp3', gentle: 'sounds/gentle_chime.mp3', pleasant: 'sounds/pleasant_chime.mp3', retro: 'sounds/retro_chime.mp3' };