@@ -324,6 +324,39 @@ async def test_tool_audio_helper(self, tmp_path: Path):
324
324
# Check structured content - Image return type should NOT have structured output
325
325
assert result .structuredContent is None
326
326
327
+ @pytest .mark .anyio
328
+ async def test_tool_audio_suffix_detection (self , tmp_path : Path ):
329
+ # Test different audio file extensions
330
+ test_cases = [
331
+ ("test.wav" , "audio/wav" ),
332
+ ("test.mp3" , "audio/mpeg" ),
333
+ ("test.ogg" , "audio/ogg" ),
334
+ ("test.flac" , "audio/flac" ),
335
+ ("test.aac" , "audio/aac" ),
336
+ ("test.m4a" , "audio/mp4" ),
337
+ ("test.unknown" , "application/octet-stream" ), # Unknown extension fallback
338
+ ]
339
+
340
+ mcp = FastMCP ()
341
+ mcp .add_tool (audio_tool_fn )
342
+ async with client_session (mcp ._mcp_server ) as client :
343
+ for filename , expected_mime_type in test_cases :
344
+ # Create a test audio file with the specific extension
345
+ audio_path = tmp_path / filename
346
+ audio_path .write_bytes (b"fake audio data" )
347
+
348
+ result = await client .call_tool ("audio_tool_fn" , {"path" : str (audio_path )})
349
+ assert len (result .content ) == 1
350
+ content = result .content [0 ]
351
+ assert isinstance (content , AudioContent )
352
+ assert content .type == "audio"
353
+ assert content .mimeType == expected_mime_type , (
354
+ f"Expected { expected_mime_type } for { filename } , got { content .mimeType } "
355
+ )
356
+ # Verify base64 encoding
357
+ decoded = base64 .b64decode (content .data )
358
+ assert decoded == b"fake audio data"
359
+
327
360
@pytest .mark .anyio
328
361
async def test_tool_mixed_content (self ):
329
362
mcp = FastMCP ()
0 commit comments