MCP ML 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 ML Agent predict both models for this patient and tell me if they agree"
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 ML Agent — Custom Tool Assignment
Project Overview
This project demonstrates how to build and call a custom Model Context Protocol (MCP) tool using Python.
The MCP server provides machine learning tools for training, predicting, evaluating, and auditing Logistic Regression and K-Nearest Neighbors (KNN) models.
For this assignment, I implemented a custom tool called predict_both, which compares predictions from both models for the same patient.
Related MCP server: MCP Machine Learning Agent
Technologies Used
Python
Model Context Protocol (MCP)
Logistic Regression
K-Nearest Neighbors (KNN)
Scikit-learn
Parquet
uv package manager
Custom MCP Tool: predict_both
The predict_both tool:
Accepts a patient's input features.
Generates predictions using Logistic Regression and KNN.
Returns both predictions.
Indicates whether the models agree.
Records the tool execution for auditing.
How to Run
Clone the repository:
git clone https://github.com/Bharath-5577/mcp-ml-agent-assignment.git
cd mcp-ml-agent-assignmentInstall dependencies:
uv syncRun the custom client:
uv run python my_client.pyExperiment Results
The custom client evaluated 114 test patients.
Metric | Result |
Total test patients | 114 |
Model disagreements | 8 |
Logistic Regression correct on disagreements | 7 |
KNN correct on disagreements | 1 |
Better model on disagreement cases | Logistic Regression |
The disagreement patient indices were:
[3, 25, 48, 53, 76, 80, 99, 102]
These results show that Logistic Regression performed better on the eight disagreement cases. This does not necessarily establish that it performs better across every evaluation metric.
Project Files
mcp_ml_server.py— MCP server and custom toolmy_client.py— Client that calls the MCP toolsanswers.md— Written assignment responsesscreenshots/— Execution evidenceuv.lock— Dependency lockfile
Conclusion
This assignment helped me understand how to extend an existing MCP server, expose a custom tool, call it from an MCP client, compare machine learning predictions, and maintain an audit trail.
The experiment demonstrated how a custom MCP tool can simplify model comparison and make machine learning workflows easier to inspect.
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
Each tool maps to a distinct pipeline stage (training, sampling, per-model prediction, metrics, selection, explanation, export). The only mild overlap is predict_both versus the two single-model predict tools, but the descriptions make the convenience-versus-specific distinction clear.
Most names follow a verb_noun pattern (train_models, get_sample_input, predict_knn, select_best_model, export_parquet_audit). Two deviate: confusion_matrix_metrics is a bare noun phrase and shap_explain_selected is an awkward ordering, but the set remains readable and predictable.
Nine tools neatly cover one end-to-end classification workflow with no padding. Each tool earns its place: train, sample, predict, evaluate, select, explain, export.
The full lifecycle is covered: training, sample input, prediction for both models, agreement check, metrics, model selection, SHAP explanation, and audit export. Minor gaps exist (no explicit way to inspect/list saved models or retrain a single model), but agents can work around them.
Maintenance
Related MCP Connectors
Diagnoses, functioning, drugs & labs: ICD-11, ICF, LOINC, RxNorm, MeSH, ATC, CID-10. 37 tools, MIT.
Train AutoML models on CSV files and run predictions from Claude and other MCP clients.
Privacy-preserving synthetic health data generation. FHIR R4/R5 compliant.
Train, explain, optimise and deploy transparent glass-box ML models via workflow tools.
Related MCP Servers
- 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
- AlicenseAqualityBmaintenanceEnables training and comparing logistic regression and KNN models, retrieving sample patient inputs, generating predictions and confusion-matrix metrics, selecting the best model, producing SHAP explanations, and exporting Parquet audit logs through MCP tools.9GPL 3.0