Skip to content

fix(mcp): add model_size parameter to voicebox.speak#895

Open
AhmedIrfan7 wants to merge 1 commit into
jamiepine:mainfrom
AhmedIrfan7:fix/mcp-speak-model-size
Open

fix(mcp): add model_size parameter to voicebox.speak#895
AhmedIrfan7 wants to merge 1 commit into
jamiepine:mainfrom
AhmedIrfan7:fix/mcp-speak-model-size

Conversation

@AhmedIrfan7

@AhmedIrfan7 AhmedIrfan7 commented Jul 14, 2026

Copy link
Copy Markdown

What & why

The MCP voicebox.speak tool built its GenerationRequest without a
model_size, so it always fell back to the schema default ("1.7B"). As
reported 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

  • Add an optional model_size parameter to voicebox.speak and thread it
    through the _speak helper into GenerationRequest, matching the REST
    /generate surface the issue references.
  • When omitted, model_size is None; generate_speech already normalizes
    None to the engine default (see routes/generations.py), so behaviour is
    unchanged for callers that don't set it — this mirrors a REST /generate
    body with no model_size.
  • The GenerationRequest schema pattern (1.7B|0.6B|1B|3B) stays the single
    source of truth for validation; engines without multiple sizes ignore it, as
    before.
  • Documented the new parameter in the tool docstring so it surfaces to MCP
    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 a
separate PR if you'd like.

Tests

Added backend/tests/test_mcp_speak.py:

  • forwards an explicit model_size into the request
  • omitted model_size stays None (regression guard for the default path)
  • invalid size raises ValidationError before any generation runs

Verified these three behaviours pass locally against the real _speak and
GenerationRequest (with generate_speech mocked, as the test does).

Changelog

Left CHANGELOG.md untouched (its header says it is auto-compiled at release).
Suggested entry:

MCP voicebox.speak now accepts model_size (qwen: 1.7B/0.6B, tada: 1B/3B).

Fixes #884

Summary by CodeRabbit

  • New Features

    • Added an optional model size setting to voice generation requests.
    • Supported engines can now select specific model variants, while other engines continue using their default size.
    • Validation feedback is provided for invalid model size values.
  • Tests

    • Added coverage for explicit, omitted, and invalid model size settings for the voice generation tool.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c42542af-0836-454d-9847-98fbc5efcf24

📥 Commits

Reviewing files that changed from the base of the PR and between 220617f and 82430cf.

📒 Files selected for processing (2)
  • backend/mcp_server/tools.py
  • backend/tests/test_mcp_speak.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/tests/test_mcp_speak.py
  • backend/mcp_server/tools.py

📝 Walkthrough

Walkthrough

The MCP voicebox.speak tool now accepts an optional model_size, forwards it through _speak, and includes it in GenerationRequest. Tests cover explicit, omitted, and invalid values.

Changes

MCP model size support

Layer / File(s) Summary
Add model size to MCP speech requests
backend/mcp_server/tools.py
The MCP tool and _speak helper accept model_size, document its engine-specific behavior, and include it in GenerationRequest.
Validate model size request handling
backend/tests/test_mcp_speak.py
Tests verify explicit forwarding, omission as None, and rejection of invalid values before generation runs.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding model_size to voicebox.speak.
Linked Issues check ✅ Passed The PR adds the requested optional model_size parameter, forwards it into GenerationRequest, and preserves omission/default behavior.
Out of Scope Changes check ✅ Passed All code and test changes directly support the model_size MCP tool enhancement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/mcp_server/tools.py (1)

46-53: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using Literal to constrain the LLM via JSON schema.

While validation correctly relies on the inner GenerationRequest pattern, typing model_size as Literal instead of str allows FastMCP to include these options as an enum in 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

📥 Commits

Reviewing files that changed from the base of the PR and between f2cf2a7 and 220617f.

📒 Files selected for processing (2)
  • backend/mcp_server/tools.py
  • backend/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
@AhmedIrfan7
AhmedIrfan7 force-pushed the fix/mcp-speak-model-size branch from 220617f to 82430cf Compare July 14, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

voicebox.speak MCP tool has no model_size parameter — always forces 1.7B, causing unnecessary model reloads

1 participant