Skip to content

Commit 1f3279c

Browse files
author
Developer
committed
fix: handle empty text_to_audio errors consistently
1 parent f4d6a61 commit 1f3279c

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

minimax_mcp/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ def text_to_audio(
8787
format: str = DEFAULT_FORMAT,
8888
language_boost: str = DEFAULT_LANGUAGE_BOOST,
8989
):
90-
if not text:
91-
raise MinimaxRequestError("Text is required.")
92-
9390
payload = {
9491
"model": model,
9592
"text": text,
@@ -111,6 +108,9 @@ def text_to_audio(
111108
if resource_mode == RESOURCE_MODE_URL:
112109
payload["output_format"] = "url"
113110
try:
111+
if not text:
112+
raise MinimaxRequestError("Text is required.")
113+
114114
response_data = api_client.post("/v1/t2a_v2", json=payload)
115115
audio_data = response_data.get('data', {}).get('audio', '')
116116

tests/test_server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import importlib
2+
import sys
3+
4+
from mcp.types import TextContent
5+
6+
7+
def load_server(monkeypatch):
8+
monkeypatch.setenv("MINIMAX_API_KEY", "test-key")
9+
monkeypatch.setenv("MINIMAX_API_HOST", "https://api.example.com")
10+
sys.modules.pop("minimax_mcp.server", None)
11+
return importlib.import_module("minimax_mcp.server")
12+
13+
14+
def test_text_to_audio_returns_text_content_for_empty_text(monkeypatch):
15+
server = load_server(monkeypatch)
16+
17+
result = server.text_to_audio(text="")
18+
19+
assert isinstance(result, TextContent)
20+
assert result.type == "text"
21+
assert result.text == "Failed to generate audio: Text is required."

0 commit comments

Comments
 (0)