Skip to main content
Glama
chetaniitbhilai

Keyword Search MCP Server

README.md
# āœ… MCP Server – Keyword Search Tool (Case-Insensitive)

This project is a simple **MCP (Model Context Protocol) Server** built using FastAPI.
It includes a tool that allows users to **search for a keyword inside a file** (case-insensitive).

---

## šŸ“„ Documentation

You can view the detailed documentation here:  
**[Assignment Documentation](https://docs.google.com/document/d/1prMqMwjT5Zi70FqnQzCr1r0WSaW4CHpoGg6EjazEonM/edit?usp=sharing)**

---
## šŸ“ Project Structure

```
mcp-server/
ā”œā”€ā”€ server.py
ā”œā”€ā”€ tools/
│   ā”œā”€ā”€ __init__.py
│   └── search_tool.py
ā”œā”€ā”€ requirements.txt
└── README.md
```

---

## āš™ļø 1. Setup Instructions

### āœ… Step 1: Clone or Create Project Folder

```bash
cd mcp-server
```

### āœ… Step 2: Create and Activate Virtual Environment (Optional but Recommended)

```bash
python -m venv venv
# Activate it:
# On Windows:
venv\Scripts\activate
# On Linux/Mac:
source venv/bin/activate
```

### āœ… Step 3: Install Dependencies

```bash
pip install -r requirements.txt
```

---

## šŸš€ 2. Run the MCP Server

```bash
uvicorn server:app --reload --port 8000
```

If successful, you will see:

```
Uvicorn running on http://127.0.0.1:8000
```

Visit in browser:

```
http://127.0.0.1:8000
```

Or API docs (auto-generated):

```
http://127.0.0.1:8000/docs
```

---

## šŸ” 3. Search Keyword in a File (API Usage)

### āœ… Request Format (POST `/search`)

```json
{
  "file_path": "path/to/file.txt",
  "keyword": "example"
}
```

### āœ… Example using `curl`:

```bash
curl -X POST "http://127.0.0.1:8000/search" \
-H "Content-Type: application/json" \
-d '{"file_path": "sample.txt", "keyword": "hello"}'
```

### āœ… Example Response:

```json
{
  "results": [
    "Line 2: Hello World",
    "Line 5: hElLo again"
  ]
}
```

---

## šŸ›  4. Code Summary


### `server.py`

Defines API endpoint `/search`.

---

## āœ… 5. Features

āœ” FastAPI-powered MCP server
āœ” Case-insensitive keyword search
āœ” Shows line number + text where keyword exists
āœ” Error handling for missing files

---

## šŸ“Œ 6. Future Improvements (Optional)

* šŸ”¹ Search across directories
* šŸ”¹ Regex support
* šŸ”¹ Return JSON with `{line_number, content}` format
* šŸ”¹ File type filtering (.txt, .py, .md, etc.)