get_latest_audio
Retrieve the most recent audio file from the audio directory to access the newest recording without manual searching.
Instructions
Get the most recent audio file from the audio path. ONLY USE THIS IF THE USER ASKS FOR THE LATEST FILE.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_name | Yes | Name of the audio file | |
| transcription_support | No | List of transcription models that support this file format | |
| chat_support | No | List of audio LLM models that support this file format | |
| modified_time | Yes | Last modified timestamp of the file (Unix time) | |
| size_bytes | Yes | Size of the file in bytes | |
| format | Yes | Audio format of the file (e.g., 'mp3', 'wav') | |
| duration_seconds | No | Duration of the audio file in seconds, if available |
Implementation Reference
- The MCP tool handler for 'get_latest_audio' — decorated with @mcp.tool inside create_file_tools(), calls file_service.get_latest_audio_file().
@mcp.tool( description="Get the most recent audio file from the audio path. " "ONLY USE THIS IF THE USER ASKS FOR THE LATEST FILE." ) async def get_latest_audio() -> FilePathSupportParams: """Get the most recently modified audio file and returns its path with model support info. Supported formats: - Whisper: mp3, mp4, mpeg, mpga, m4a, wav, webm - GPT-4o: mp3, wav Returns detailed file information including size, format, and duration. """ return await file_service.get_latest_audio_file() - src/mcp_server_whisper/tools/file_tools.py:12-38 (registration)Registration of the get_latest_audio tool via create_file_tools() which is called by register_all_tools() in tools/__init__.py.
def create_file_tools(mcp: MCPServer) -> None: """Register file management tools with the MCP server. Args: ---- mcp: FastMCP server instance. """ # Initialize services audio_path = check_and_get_audio_path() file_repo = FileSystemRepository(audio_path) file_service = FileService(file_repo) @mcp.tool( description="Get the most recent audio file from the audio path. " "ONLY USE THIS IF THE USER ASKS FOR THE LATEST FILE." ) async def get_latest_audio() -> FilePathSupportParams: """Get the most recently modified audio file and returns its path with model support info. Supported formats: - Whisper: mp3, mp4, mpeg, mpga, m4a, wav, webm - GPT-4o: mp3, wav Returns detailed file information including size, format, and duration. """ return await file_service.get_latest_audio_file() - FileService.get_latest_audio_file() — service layer that delegates to the repository's get_latest_audio_file().
async def get_latest_audio_file(self) -> FilePathSupportParams: """Get the most recently modified audio file with model support info. Returns ------- FilePathSupportParams: File metadata and model support information. """ return await self.file_repo.get_latest_audio_file() - FileSystemRepository.get_latest_audio_file() — the actual implementation that iterates files, filters by supported formats, finds the most recently modified one, and returns metadata via get_audio_file_support().
async def get_latest_audio_file(self) -> FilePathSupportParams: """Get the most recently modified audio file with model support info. Supported formats: - Whisper: mp3, mp4, mpeg, mpga, m4a, wav, webm - GPT-4o: mp3, wav Returns ------- FilePathSupportParams: File metadata and model support information. Raises ------ AudioFileNotFoundError: If no supported audio files are found. AudioFileError: If there's an error accessing audio files. """ try: files = [] for file_path in self.audio_files_path.iterdir(): if not file_path.is_file(): continue file_ext = file_path.suffix.lower() if file_ext in TRANSCRIBE_AUDIO_FORMATS or file_ext in CHAT_WITH_AUDIO_FORMATS: files.append((file_path, file_path.stat().st_mtime)) if not files: raise AudioFileNotFoundError("No supported audio files found") latest_file = max(files, key=lambda x: x[1])[0] return await self.get_audio_file_support(latest_file) except AudioFileNotFoundError: raise except Exception as e: raise AudioFileError(f"Failed to get latest audio file: {e}") from e