MCP Machine Learning Agent
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Machine Learning Agent train both models, compare their metrics, and select the best one for malignant recall"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Machine Learning Agent
This project demonstrates how to deploy Machine Learning models as real MCP (Model Context Protocol) tools. You will train Logistic Regression and KNN models, evaluate them, select the best model, generate SHAP explanations, and log results to Parquet — all exposed through an MCP server.
This project accompanies the MCP and Agent Skills module.
What This Project Includes
The MCP server exposes the following tools:
Tool | What it does |
| Train Logistic Regression and KNN and export them to joblib |
| Return a real test-set patient as a ready-to-use prediction input |
| Predict malignant or benign with the Logistic Regression model |
| Predict malignant or benign with the KNN model |
| Confusion matrix, accuracy, precision and recall for both models |
| Select the best model using a rule |
| Global and local SHAP explanations for the selected model |
| Export a copy of the Parquet audit log |
Every tool call is logged to Parquet.
About the labels
The data is scikit-learn's Wisconsin breast cancer dataset (569 patients, 30 numeric features).
0= malignant1= benign
Missing a cancer is the costly mistake, so malignant is the positive class: precision and recall are reported for malignant, and the default selection rule picks the model with the highest malignant recall. Confusion matrices are ordered [malignant, benign], with rows = actual and columns = predicted.
Artifacts generated:
artifacts/*.joblib(trained models)artifacts/*.json(feature schema, training settings, selection, SHAP)data_parquet/*.parquet(audit log)
The evaluation, selection and SHAP tools reuse the saved models when they were trained with the same settings, so every tool describes the exact models the predict tools use. If you pass different settings (for example knn_neighbors), the models are retrained and re-saved.
Requirements
You must install:
Python 3.10 or newer
uv package manager
VSCode (recommended)
Setup Instructions
Related MCP server: MCP Machine Learning Agent
Step 1 — Clone the repository
In VSCode:
File → Open Folder → select the project folder
OR from terminal:
git clone <repository_url>
cd mcp_ml_agentStep 2 — Open terminal in the project folder
In VSCode:
Right-click on:
pyproject.tomlSelect:
Open in Integrated TerminalConfirm you are in the correct folder:
Windows:
dir pyproject.tomlMac/Linux:
ls pyproject.tomlStep 3 — Install dependencies
In terminal, run:
If (base) or any conda environment is showing in your command line path:
conda deactivateuv syncThis will:
Create
.venvInstall all dependencies
Prepare MCP environment
This may take a few minutes the first time.
Running the MCP Server
Start the MCP server:
uv run python mcp_ml_server.pyIf successful, the server will start and wait for MCP tool requests.
No additional output is expected — this is normal.
Running the Client Demo (Optional)
To test the tools automatically:
uv run python mcp_client_demo.pyThis will:
Train models
Run predictions on sample patients with both models
Show a prediction from an edited input, and the error returned for an invalid one
Evaluate models
Select best model
Generate SHAP explanations
Export Parquet audit log
Making Predictions
Both predict tools take an input_data object containing all 30 features, keyed by their exact names, as numbers. A missing, misspelled or non-numeric feature returns an error that lists the expected names.
Train the models first (train_models), then use either approach below.
Option 1 — Let the server give you a valid input
Call get_sample_input with a test-set row number:
{"index": 0}It returns the patient's true diagnosis and an input_data dictionary you can pass straight to a predict tool:
{
"status": "success",
"index": 0,
"true_label": 0,
"true_class": "malignant",
"input_data": {"mean radius": 19.55, "mean texture": 28.77, "...": "..."}
}Option 2 — Use the example file
examples/prediction_examples.json contains two complete patients (one malignant, one benign). Copy one input_data block, change any values you like, and call a predict tool:
{
"input_data": {
"mean radius": 19.55,
"mean texture": 28.77,
"mean perimeter": 133.6,
"...": "all 30 features"
},
"request_id": "my-first-prediction"
}The response
{
"status": "success",
"tool": "predict_logistic_regression",
"model_used": "logistic_regression",
"result": {
"prediction": 0,
"predicted_class": "malignant",
"confidence": 0.99999,
"probabilities": {"malignant": 0.99999, "benign": 0.00001}
}
}Predictions from Python
import json
import ml_pipeline as ml
ml.train_and_export_all()
example = json.load(open("examples/prediction_examples.json"))["examples"][0]
model = ml.load_model("logistic_regression")
print(ml.predict_with_model(model, example["input_data"]))Asking an AI agent
When the server is connected to an MCP host (such as Claude Desktop or VS Code), you can ask in plain language, for example:
Train the models, get test patient 2, and predict it with both models. Do they agree with the true diagnosis?
Generated Files
After running tools, you will see:
artifacts/
logistic_regression.joblib
knn.joblib
feature_names.json
training_config.json
selection.json
shap_*.json
data_parquet/
tool_audit.parquet
audit_export.parquet (or the filename you choose)You can open Parquet files in Python:
import pandas as pd
df = pd.read_parquet("data_parquet/tool_audit.parquet")
print(df)Running Jupyter Notebook (Optional)
If using the notebook version:
uv run jupyter notebookOpen the notebook and run the cell.
Important: Do NOT manually activate .venv
Do NOT run:
.venv\Scripts\activateAlways use:
uv run python filename.pyuv automatically uses the correct environment.
Project Structure
mcp_ml_agent/
- pyproject.toml
- uv.lock
- mcp_ml_server.py MCP server: exposes the tools
- mcp_client_demo.py scripted client that calls every tool
- ml_pipeline.py training, evaluation, selection, SHAP, prediction
- parquet_store.py Parquet audit log
- examples/
- prediction_examples.json
artifacts/ (created when you run the tools)
data_parquet/ (created when you run the tools)The server works with both version 1.x and 2.x of the MCP Python SDK.
Available Tools
9 toolsconfusion_matrix_metricsA
Compute the confusion matrix plus accuracy/precision/recall for both models on the test set. Precision and recall are for the malignant class. Confusion matrix order is [malignant, benign]; rows = actual, columns = predicted.
Inputs: test_size, request_id, random_state, knn_neighbors. Returns: result
export_parquet_auditB
Export a copy of the Parquet audit log for submission.
Inputs: filename, request_id. Returns: result
get_sample_inputA
Return one test-set patient as a ready-to-use input_data dictionary for
the predict tools, along with that patient's true diagnosis.
Inputs: index, test_size, request_id, random_state. Returns: result
predict_bothA
Predict with BOTH models in one call and report whether they agree.
Inputs: input_data (required), request_id. Returns: result
predict_knnA
Predict malignant (0) or benign (1) using the saved KNN model.
Inputs: input_data (required), request_id. Returns: result
predict_logistic_regressionB
Predict malignant (0) or benign (1) using the saved Logistic Regression model.
Inputs: input_data (required), request_id. Returns: result
select_best_modelB
Select the best model using a rule (default: recall, then precision, then accuracy).
Inputs: rule, test_size, request_id, random_state, +1 more. Returns: result
shap_explain_selectedB
Run SHAP for the selected model: global top features plus a local explanation for one test row. Positive SHAP values push toward malignant.
Inputs: top_k, test_size, request_id, local_index, +3 more. Returns: result
train_modelsB
Train Logistic Regression and KNN on the breast cancer dataset and export joblib artifacts.
Inputs: test_size, request_id, random_state, knn_neighbors. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
The tools map cleanly to distinct ML workflow stages: training, prediction, evaluation, model selection, explanation, sample input, and audit export. The three prediction tools are clearly differentiated by model choice or predicting both, so an agent can select among them without ambiguity.
All names use snake_case, but the naming conventions are mixed: predict_* and select/train/get/export verb phrases coexist with noun-style metrics and domain-prefixed shap_explain_selected. The names remain readable, but they do not follow one predictable verb_noun pattern.
Nine tools is well-scoped for an end-to-end ML agent covering training, prediction, evaluation, selection, explanation, sampling, and audit export. Each tool has a clear role without excessive granularity.
The tool set covers the full visible lifecycle: train models, retrieve sample input, predict with either or both models, compute evaluation metrics, select a best model, explain the selected model, and export an audit artifact. No obvious operational gaps remain for the stated breast-cancer ML workflow.
Maintenance
Related MCP Connectors
Train AutoML models on CSV files and run predictions from Claude and other MCP clients.
Train, explain, optimise and deploy transparent glass-box ML models via workflow tools.
List datasets, schemas, run APL queries, and use prompts for exploration, anomalies, and monitoring.
Independent statistical feature evaluation for machine learning and forecasting. ML Referee tests up to 1,000 candidate features in one run against a declared baseline, helping researchers and AI agents decide which inputs to pursue, which bounded feature repairs merit further testing, and where more evidence is needed—without a separate ablation run for every feature. Use the MCP tools to discover input schemas, check access and credits, preflight a dataset, obtain a quote, submit an authorized evaluation, and retrieve structured results and reports. Results are scoped to the submitted evidence and evaluation design; they do not guarantee future model performance. Invite-only beta with manual approval. Public tool discovery requires no authentication; account and evaluation tools require OAuth through approved client connections and available evaluation credits. Connect directly to https://api.mlreferee.com/mcp. Website: https://mlreferee.com Request beta access: https://mlreferee.com/beta Agent setup and documentation: https://mlreferee.com/agents
Related MCP Servers
- AlicenseAqualityBmaintenanceEnables training and evaluating Logistic Regression and KNN models on breast cancer data, making predictions, selecting the best model, generating SHAP explanations, and exporting Parquet audit logs through MCP tools.9GPL 3.0
- AlicenseAqualityBmaintenanceExposes MCP tools that train, evaluate, compare and explain Logistic Regression and KNN models on the Wisconsin breast cancer dataset, then serve malignant/benign predictions with SHAP explanations and a Parquet audit log of every call. It also provides ready-to-use sample patient inputs and model-selection tooling so agents can run a full ML workflow through natural language.9GPL 3.0
- AlicenseAqualityBmaintenanceEnables training and comparing Logistic Regression and KNN models, retrieving sample patient inputs, predicting malignant or benign cases, evaluating metrics, selecting the best model, generating SHAP explanations, and exporting a Parquet audit log through MCP tools.9GPL 3.0
- AlicenseAqualityBmaintenanceEnables users to train and compare Logistic Regression and KNN models on the Wisconsin breast cancer dataset, run predictions on patient feature inputs, compute confusion-matrix metrics and select the best model by malignant recall, generate global and local SHAP explanations, and export Parquet audit logs of every tool call. Also provides sample test-set inputs so agents can invoke prediction tools with valid 30-feature payloads.9GPL 3.0