playCompletionSound
Plays a sound to provide audio feedback when Cursor AI completes code generation, enhancing interactivity during coding.
Instructions
Plays a completion sound when called
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:30-55 (handler)The core handler logic for the playCompletionSound tool. Plays the completion.mp3 sound file asynchronously using the play-sound library, with error handling and MCP response formatting.async () => { try { // Play custom sound using a Promise to handle the callback properly await new Promise<void>((resolve, reject) => { audioPlayer.play(COMPLETION_SOUND, (err: Error | null) => { if (err) { log(`Error playing sound: ${err.message}`); reject(err); } else { log('Played completion sound successfully'); resolve(); } }); }); // Return proper JSON response return { content: [{ type: 'text', text: 'Played completion sound' }] }; } catch (error) { log(`Failed to play sound: ${error}`); return { content: [{ type: 'text', text: 'Failed to play sound' }] }; } }
- src/index.ts:27-56 (registration)Registers the playCompletionSound tool with the MCP server, providing the tool name, description, and inline handler function.server.tool( 'playCompletionSound', 'Plays a completion sound when called', async () => { try { // Play custom sound using a Promise to handle the callback properly await new Promise<void>((resolve, reject) => { audioPlayer.play(COMPLETION_SOUND, (err: Error | null) => { if (err) { log(`Error playing sound: ${err.message}`); reject(err); } else { log('Played completion sound successfully'); resolve(); } }); }); // Return proper JSON response return { content: [{ type: 'text', text: 'Played completion sound' }] }; } catch (error) { log(`Failed to play sound: ${error}`); return { content: [{ type: 'text', text: 'Failed to play sound' }] }; } } );
- src/index.ts:11-13 (helper)Initializes the audio player instance and defines the path to the completion sound file used by the handler.const audioPlayer = player(); // Use the custom sound file from the sounds directory const COMPLETION_SOUND = path.join(__dirname, '..', 'sounds', 'completion.mp3');