Expose speaker playback and play_tone tool via MCP

This commit is contained in:
Adolfo Reyna
2026-06-01 13:26:05 -04:00
parent 05df3d3839
commit 8302db03db
2 changed files with 183 additions and 0 deletions
+26
View File
@@ -217,6 +217,18 @@ class MCPServer:
},
"required": ["code"]
}
},
{
"name": "play_tone",
"description": "Play a pure sine wave tone/beep on the board speaker.",
"inputSchema": {
"type": "object",
"properties": {
"frequency": {"type": "integer", "description": "Frequency of the tone in Hz (e.g. 440 for A4, default 440)", "default": 440},
"duration_ms": {"type": "integer", "description": "Duration of the tone in milliseconds (default 1000)", "default": 1000},
"volume": {"type": "integer", "description": "Volume of the tone from 0 to 100 (default 50)", "default": 50}
}
}
}
]
},
@@ -407,5 +419,19 @@ class MCPServer:
return output
return f"Execution Succeeded. Console output:\n{output}"
elif name == "play_tone":
freq = int(args.get("frequency", 440))
duration = int(args.get("duration_ms", 1000))
vol = int(args.get("volume", 50))
# Limit duration to prevent blocking the main loop for too long
duration = max(50, min(5000, duration))
freq = max(50, min(10000, freq))
vol = max(0, min(100, vol))
from audio_util import play_tone
play_tone(frequency=freq, duration_ms=duration, volume=vol)
return f"Played tone of {freq}Hz for {duration}ms at volume {vol}."
else:
raise ValueError(f"Unknown tool: {name}")