File size: 2,720 Bytes
fc244c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# πŸ€– MCP-Agent-1.7B

> The first open-source small language model fine-tuned to natively speak the **Model Context Protocol (MCP)**.

## What Is This?

MCP-Agent-1.7B is [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) fine-tuned with LoRA to:

- πŸ”§ **Call tools** using MCP protocol (JSON-RPC format)
- πŸ”— **Plan multi-step tool chains** with DAG dependencies
- ❓ **Ask clarifying questions** when info is missing (instead of hallucinating)
- πŸ›‘οΈ **Refuse dangerous requests** (e.g., "delete all files")

## Training

| Detail | Value |
|--------|-------|
| Base model | [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) (2B params) |
| Method | LoRA SFT (rank=16, all-linear) |
| Dataset | [muhammadtlha944/mcp-agent-training-data](https://huggingface.co/datasets/muhammadtlha944/mcp-agent-training-data) (16.5K examples) |
| Epochs | 3 |
| Learning rate | 2e-4 (cosine schedule) |
| Effective batch size | 16 |
| Precision | fp16 |
| Cost | **$0** (trained on free Kaggle/Colab GPU) |

## πŸš€ Train It Yourself (FREE)

### Option 1: Kaggle (Recommended β€” 30 free GPU hrs/week)
1. Go to [kaggle.com/code](https://kaggle.com/code) β†’ **New Notebook**
2. **Settings** β†’ Accelerator β†’ **GPU T4Γ—2** β†’ Internet β†’ **ON**
3. Copy-paste the code from [`MCP_Agent_1_7B_Kaggle.ipynb`](./MCP_Agent_1_7B_Kaggle.ipynb)
4. Run all cells β†’ wait ~2 hours β†’ model auto-pushes to Hub

### Option 2: Google Colab (Backup β€” free T4)
1. Open [colab.research.google.com](https://colab.research.google.com)
2. **Runtime** β†’ Change runtime type β†’ **T4 GPU**
3. Copy-paste from [`MCP_Agent_1_7B_Training.ipynb`](./MCP_Agent_1_7B_Training.ipynb)
4. Run all cells β†’ wait ~2 hours

## Quick Start

```python
from transformers import pipeline

pipe = pipeline("text-generation", model="muhammadtlha944/MCP-Agent-1.7B")

messages = [
    {"role": "system", "content": "You are an MCP agent with tools: github_search, read_file, shell_exec."},
    {"role": "user", "content": "Find all Python files that import pandas"}
]

response = pipe(messages, max_new_tokens=512)
print(response[0]['generated_text'][-1]['content'])
```

## Research Background

This project is informed by:
- **STAR Framework** ([arxiv 2602.03022](https://arxiv.org/abs/2602.03022)) β€” proved Qwen3-1.7B beats Llama-3.1-8B at function calling
- **TinyAgent** ([arxiv 2409.00608](https://arxiv.org/abs/2409.00608)) β€” proved 1.1B models can match GPT-4 at focused tool calling
- **LoRA Without Regret** β€” all-linear LoRA matches full fine-tuning quality

## License

Apache 2.0 (same as base model)

## Author

Built by [Muhammad Talha](https://huggingface.co/muhammadtlha944) β€” learning ML by building real projects.