Skip to main content
Glama

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:

  1. Accepts a patient's input features.

  2. Generates predictions using Logistic Regression and KNN.

  3. Returns both predictions.

  4. Indicates whether the models agree.

  5. 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-assignment

Install dependencies:

uv sync

Run the custom client:

uv run python my_client.py

Experiment 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 tool

  • my_client.py — Client that calls the MCP tools

  • answers.md — Written assignment responses

  • screenshots/ — Execution evidence

  • uv.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 tools
confusion_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

    A3.6/5.0

    Scored across 9 tools

    Disambiguation4/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Exposes 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.
      9
      GPL 3.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables 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.
      9
      GPL 3.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables 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.
      9
      GPL 3.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables 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.
      9
      GPL 3.0