play-local-sound
Play local sound files on macOS using the afplay command to enable AI assistants to trigger audio notifications after responding.
Instructions
ローカルのサウンドファイル(sound.mp3)をafplayで再生します。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:27-45 (handler)The handler function for the 'play-local-sound' tool. It asynchronously executes the 'afplay' command on the local sound file using child_process.exec and resolves with a structured content response (success or error message).async () => { return new Promise((resolve) => { exec(`afplay "${soundFile}"`, (error) => { if (error) { resolve({ content: [ { type: "text", text: `サウンド再生に失敗しました: ${error}` }, ], }); } else { resolve({ content: [ { type: "text", text: `サウンド(${soundFileName})を再生しました。` }, ], }); } }); }); }
- src/index.ts:23-46 (registration)Registration of the 'play-local-sound' MCP tool on the McpServer instance, specifying name, Japanese description, empty input schema, and the handler function.server.tool( "play-local-sound", `ローカルのサウンドファイル(${soundFileName})をafplayで再生します。`, {}, async () => { return new Promise((resolve) => { exec(`afplay "${soundFile}"`, (error) => { if (error) { resolve({ content: [ { type: "text", text: `サウンド再生に失敗しました: ${error}` }, ], }); } else { resolve({ content: [ { type: "text", text: `サウンド(${soundFileName})を再生しました。` }, ], }); } }); }); } );
- src/index.ts:26-26 (schema)Empty input schema object for the 'play-local-sound' tool (no parameters required).{},
- src/index.ts:7-11 (helper)Helper code to determine the absolute path of the sound file to play, using __dirname, command-line argument (default 'sound.mp3'), and path.join to locate it in '../sounds/'.// サウンドファイルの絶対パスを取得 const __dirname = path.dirname(fileURLToPath(import.meta.url)); // コマンドライン引数からファイル名を取得(デフォルト: sound.mp3) const soundFileName = process.argv[2] || "sound.mp3"; const soundFile = path.join(__dirname, "..", "sounds", soundFileName);