You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ENH]: Add save_model MCP tool for persisting estimators via sktime MLflow (#48)
#### Reference Issues/PRs
Fixes#31
#### What does this implement/fix? Explain your changes.
Implements the requested `save_model` MCP tool for `sktime-mcp`.
This PR adds a new MCP tool, `save_model`, to allow persistent storage
of instantiated estimators and pipelines via
`sktime.utils.mlflow_sktime.save_model`.
For `docs`:
updated user-facing docs and examples to document the new tool, clarify
the current local filesystem path behavior of sktime's save_model API,
and mention the MLflow runtime requirement
Changes included:
- added `src/sktime_mcp/tools/save_model.py` with `save_model_tool` .
- resolved estimator handles to the underlying estimator instance
through the handle manager
- registered the tool in `src/sktime_mcp/server.py` with schema and
dispatch wiring
- added unit coverage in `tests/test_core.py`
checked if run locally or not with this command `python -m pytest
tests/test_core.py::TestTools::test_save_model_tool -q`
<img width="1856" height="135" alt="image"
src="https://github.com/user-attachments/assets/fbaf5475-8610-4be6-a09f-43fd7e0297da"
/>
- updated user-facing docs and examples to document the new too
#### Does your contribution introduce a new dependency? If yes, which
one?
No but ,the tool relies on `sktime`'s MLflow integration
(`sktime.utils.mlflow_sktime.save_model`), so MLflow must be available
in the runtime environment for the tool to work.
I documented this behavior, but did not add `mlflow` to project
dependencies .
#### What should reviewers focus on?
I’d really appreciate feedback on a few specific areas:
1. Does `save_model` feel like the right MCP interface for handling
persistence in this project?
2. Should we be more explicit in the contract and say “local filesystem
path” instead of the broader “path or URI”?
3. Does it make sense to keep MLflow as a documented/runtime
requirement, or should it be added as an explicit dependency
#### Any other comments?
The implementation follows the documented
`sktime.utils.mlflow_sktime.save_model` API, which describes saving to a
local path on the filesystem. I aligned the documentation with that
behavior to avoid overstating URI support.
#### PR checklist
##### For all contributions
- [ ] I've added myself to the
`https://github.com/alan-turing-institute/sktime/blob/main/.all-contributorsrc`
.
- [ ] Optionally, I've updated sktime's
`https://github.com/alan-turing-institute/sktime/blob/main/CODEOWNERS`
to receive notifications about future changes to these files.
- [x] I've added unit tests and made sure they pass locally.
##### For new estimators
- [ ] Not applicable, this PR does not add a new estimator.
- [ ] Not applicable, this PR does not add or modify estimator example
notebooks.
ran the test locally they are pssing
<img width="1840" height="176" alt="image"
src="https://github.com/user-attachments/assets/2013fff5-4792-48e3-9ec4-9958aa16ed81"
/>
Copy file name to clipboardExpand all lines: docs/usage-examples.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,3 +159,23 @@ When you are done with an estimator, it's good practice to release it to free up
159
159
}
160
160
}
161
161
```
162
+
163
+
### Model Persistence
164
+
165
+
**Save a Fitted Estimator**
166
+
Use `save_model` after fitting an estimator or pipeline handle. The underlying `sktime.utils.mlflow_sktime.save_model` API saves to a local filesystem path.
167
+
168
+
```json
169
+
{
170
+
"name": "save_model",
171
+
"arguments": {
172
+
"estimator_handle": "est_abc123",
173
+
"path": "/absolute/path/to/model_dir",
174
+
"mlflow_params": {
175
+
"serialization_format": "pickle"
176
+
}
177
+
}
178
+
}
179
+
```
180
+
181
+
*Returns:*`{"success": true, "saved_path": "/absolute/path/to/model_dir", "message": "Model saved successfully to '/absolute/path/to/model_dir'"}`
The server stores active handles in standard Python dictionaries.
204
+
> **Impact**: If the server restarts or connection drops, in-memory handles are lost. Use `save_model` to persist fitted estimators to a local filesystem path when needed.
164
205
165
206
#### 2. Synchronous Execution (GIL Blocking)
166
207
Heavy operations (like `AutoARIMA` fitting) run on the main thread.
@@ -197,5 +238,6 @@ Complex sktime types (Periods, Intervals) are converted to strings for LLM consu
197
238
|-------|----------|
198
239
|**"Unknown estimator"**| Use `search_estimators` to find the exact case-sensitive name. |
199
240
|**"Missing dependencies"**| Run `pip install -e ".[all]"` to ensure all extras are present. |
241
+
|**`save_model` import/runtime errors**| Install MLflow in the environment used by the server. The tool relies on `sktime.utils.mlflow_sktime.save_model` and saves to a local filesystem path. |
200
242
|**Validation Failures**| Enable `auto_format_on_load` or use `format_time_series` to clean your data. |
201
243
|**Server Timeout**| Heavy models take time. Be patient or try a simpler model (e.g., `NaiveForecaster`) first. |
0 commit comments