Skip to content

Commit 40294d5

Browse files
committed
fix: additional test for audio mimetype detection
1 parent b3ee109 commit 40294d5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/server/fastmcp/test_server.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,39 @@ async def test_tool_audio_helper(self, tmp_path: Path):
324324
# Check structured content - Image return type should NOT have structured output
325325
assert result.structuredContent is None
326326

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+
327360
@pytest.mark.anyio
328361
async def test_tool_mixed_content(self):
329362
mcp = FastMCP()

0 commit comments

Comments
 (0)