fix(mcp): add model_size parameter to voicebox.speak#895
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe MCP ChangesMCP model size support
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/mcp_server/tools.py (1)
46-53: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
Literalto constrain the LLM via JSON schema.While validation correctly relies on the inner
GenerationRequestpattern, typingmodel_sizeasLiteralinstead ofstrallows FastMCP to include these options as anenumin the tool's JSON schema. This provides strict hints directly to the LLM, reducing the chance of hallucinated values that would otherwise be rejected.💡 Proposed refactor (assuming `typing` is imported)
async def voicebox_speak( text: str, profile: str | None = None, engine: str | None = None, personality: bool | None = None, language: str | None = None, - model_size: str | None = None, + model_size: typing.Literal["1.7B", "0.6B", "1B", "3B"] | None = None, ) -> dict[str, Any]:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/mcp_server/tools.py` around lines 46 - 53, Update the model_size parameter in voicebox_speak to use a typing.Literal containing the supported model-size values, matching the options accepted by the inner GenerationRequest validation. Preserve its optional/default behavior so FastMCP exposes the values as a JSON-schema enum without changing runtime validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/mcp_server/tools.py`:
- Around line 46-53: Update the model_size parameter in voicebox_speak to use a
typing.Literal containing the supported model-size values, matching the options
accepted by the inner GenerationRequest validation. Preserve its
optional/default behavior so FastMCP exposes the values as a JSON-schema enum
without changing runtime validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c49ddce1-23ab-4c9e-bb3e-86becc56ec5d
📒 Files selected for processing (2)
backend/mcp_server/tools.pybackend/tests/test_mcp_speak.py
The MCP voicebox.speak tool built its GenerationRequest without a
model_size, so every agent-triggered generation fell back to the schema
default ("1.7B"). There was no way to reach the 0.6B Qwen variant (or
TADA's 1B/3B) through MCP, and callers paid a model reload whenever the
requested size differed from what was already loaded.
Thread an optional model_size through voicebox.speak and the _speak
helper into GenerationRequest, mirroring the REST /generate surface.
Omitting it passes None, which generate_speech normalizes to the engine
default, so existing callers are unaffected.
Add backend/tests/test_mcp_speak.py covering the forwarded value, the
omitted-default path, and rejection of an invalid size.
Fixes jamiepine#884
220617f to
82430cf
Compare
What & why
The MCP
voicebox.speaktool built itsGenerationRequestwithout amodel_size, so it always fell back to the schema default ("1.7B"). Asreported in #884, there was no way to reach the 0.6B Qwen variant — or TADA's
1B/3B — through MCP, and repeated calls at a non-default size thrashed the
model cache by reloading on every request.
Change
model_sizeparameter tovoicebox.speakand thread itthrough the
_speakhelper intoGenerationRequest, matching the REST/generatesurface the issue references.model_sizeisNone;generate_speechalready normalizesNoneto the engine default (seeroutes/generations.py), so behaviour isunchanged for callers that don't set it — this mirrors a REST
/generatebody with no
model_size.GenerationRequestschema pattern (1.7B|0.6B|1B|3B) stays the singlesource of truth for validation; engines without multiple sizes ignore it, as
before.
clients.
Scope is intentionally limited to the MCP tool per the issue. The REST
POST /speak(SpeakRequest) mirror has the same gap — happy to follow up in aseparate PR if you'd like.
Tests
Added
backend/tests/test_mcp_speak.py:model_sizeinto the requestmodel_sizestaysNone(regression guard for the default path)ValidationErrorbefore any generation runsVerified these three behaviours pass locally against the real
_speakandGenerationRequest(withgenerate_speechmocked, as the test does).Changelog
Left
CHANGELOG.mduntouched (its header says it is auto-compiled at release).Suggested entry:
Fixes #884
Summary by CodeRabbit
New Features
Tests