Problem
play_audio() opens a file without a context manager, causing a file handle leak:
play(open(file_path, "rb").read())
The file descriptor is never explicitly closed.
Exact location
- File:
minimax_mcp/server.py
- Function:
play_audio(), the else branch
Impact
- File descriptor leak on every call
- On systems with low fd limits, repeated calls can exhaust file descriptors
- ResourceWarning in Python 3.12+
Proposed solution
def play_audio(input_file_path: str, is_url: bool = False) -> TextContent:
if is_url:
response = requests.get(input_file_path, timeout=30)
response.raise_for_status()
play(response.content)
else:
file_path = process_input_file(input_file_path)
with open(file_path, "rb") as f:
play(f.read())
return TextContent(type="text", text=f"Successfully played audio file: {input_file_path}")
Also adds timeout to the URL download and raise_for_status() for error handling.
Acceptance criteria
- File opened with context manager (
with statement)
- No ResourceWarning when running with
-Wd flag
- URL download has timeout and error handling
Problem
play_audio()opens a file without a context manager, causing a file handle leak:The file descriptor is never explicitly closed.
Exact location
minimax_mcp/server.pyplay_audio(), theelsebranchImpact
Proposed solution
Also adds timeout to the URL download and raise_for_status() for error handling.
Acceptance criteria
withstatement)-Wdflag