Skip to main content
Glama
README.md
# 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.

## 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:

```bash
git clone https://github.com/Bharath-5577/mcp-ml-agent-assignment.git
cd mcp-ml-agent-assignment
```

Install dependencies:

```bash
uv sync
```

Run the custom client:

```bash
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.

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
ResponsivenessSyncing