Repository navigation
feat(mcp): a model argument for servers that serve several models, and basal-mcp --model - #66
Conversation
…d basal-mcp --model
Reviewer's GuideThis PR adds opt-in multi-model support to MCP servers, exposing model discovery and per-request routing while maintaining backward-compatible single-model schemas and behavior. The stdio bridge gains Sequence diagram for MCP model discovery and selectionsequenceDiagram
participant Client as MCP Client
participant MCP as MCP Server
participant Models as Model Registry
participant Decision as Decision API
Client->>MCP: list_models()
MCP->>Models: models()
Models-->>MCP: loaded model ids
MCP-->>Client: models
Client->>MCP: decide(model)
MCP->>Decision: decide(body with model)
Decision-->>MCP: answer with model
MCP-->>Client: answer
Sequence diagram for basal-mcp model forwardingsequenceDiagram
participant Host as MCP Host
participant Bridge as basal-mcp
participant API as Basal HTTP API
Host->>Bridge: decide(...)
Bridge->>API: POST /v1/systemone with model
API-->>Bridge: decision response
Bridge-->>Host: MCP tool result
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/mcp_server.py" line_range="109" />
<code_context>
if lang:
body["lang"] = lang
+ if model is not None:
+ body["model"] = model
r = await ask(body)
return {"model": r.get("model"), **r["answers"]["answer"]}
</code_context>
<issue_to_address>
**Selected model is ignored**
When `http()` is given a regular `Server` instance and a `models` callable, `Server.serve` passes the request to `Server.decide`, which never reads `body["model"]`, so the MCP tool returns a decision from the server's configured model instead of the selected one.
Have the HTTP adapter route the selected model to the corresponding server, or reject model selection when the supplied server cannot route requests.
</issue_to_address>| if lang: | ||
| body["lang"] = lang | ||
| if model is not None: | ||
| body["model"] = model |
There was a problem hiding this comment.
🟡 Medium · Selected model is ignored
When http() is given a regular Server instance and a models callable, Server.serve passes the request to Server.decide, which never reads body["model"], so the MCP tool returns a decision from the server's configured model instead of the selected one.
Have the HTTP adapter route the selected model to the corresponding server, or reject model selection when the supplied server cannot route requests.
Prompt for AI agents
In `basal/mcp_server.py` at line 109:
**Selected model is ignored**
When `http()` is given a regular `Server` instance and a `models` callable, `Server.serve` passes the request to `Server.decide`, which never reads `body["model"]`, so the MCP tool returns a decision from the server's configured model instead of the selected one.
Have the HTTP adapter route the selected model to the corresponding server, or reject model selection when the supplied server cannot route requests.|
Thank you, Paweł! Planned for basal 2.5: we are merging this into the 2.5 release branch now, after our checks (full CPU suite; single-model MCP unchanged). The PR will close when 2.5 is published on main. |
… version CONTRIBUTING.md credits the 2.5 pull requests as the release notes' community line lists them (Paweł Kiszczak #52, #62, #64, #66, #68, #71, #73, #75; Marcin Brzeżański #56; Grzegorz Brzezinka #76, #78) and adds Dariusz Koryto (#53, #58, #59, #60 and #55); the README's list names him too. docs/changes/README.md and the changelog.py help use 2.5.1, the next release, as the example.
Closes #65
What
list_modelsfor MCP servers configured with a model-list callable.basal-mcp --model NAMEand forward the selected model in every request.Why
Allow MCP clients to route decisions to a chosen model on a multi-model server.
Compatibility
With
models=None, tool names, schemas, instructions and request/answer behavior remain unchanged.basal-serve --mcp oncontinues to callhttp(srv, a.host)and remains single-model. No API-key behavior is included.Tests run
uv run --no-sync pytest -q tests/test_mcp.py tests/test_server.py tests/test_http_status.py— 89 passed.uv run --no-sync pytest -q -x— 765 passed, 53 skipped, 1 warning (expected hardware skips; one existing PyTorch flex-attention warning).uvx [email protected] check --select E9,F63,F7,F82 --target-version py310 .— failed on existing, untouchedbasal/gemma4.py:471:66(F821 Undefined name kpos).Summary by Sourcery
Enable MCP clients and the
basal-mcpbridge to route decisions to a selected model on multi-model servers.New Features:
--modeloption tobasal-mcpand forward the selected model with every request.Enhancements:
Documentation:
Tests: