Skip to main content
Glama
shreenithi23

MCP Server Practice

by shreenithi23
README.md
# MCP Server Practice

A simple practice project demonstrating how to build and use **Model Context Protocol (MCP)** servers with Python, LangGraph, and Groq.

## Overview

This project contains:

- A **Math MCP Server** using the `stdio` transport.
- A **Weather MCP Server** using the `streamable-http` transport.
- A LangGraph ReAct agent that connects to multiple MCP servers using `MultiServerMCPClient`.

## Project Structure

```text
.
├── client.py
├── mathserver.py
├── weatherserver.py
├── .env
├── requirements.txt
└── README.md
```

## Features

### Math Server (`stdio`)

Provides the following tools:

- `add(a, b)`
- `multiply(a, b)`

### Weather Server (`streamable-http`)

Provides the following tool:

- `get_weather(location)`

> Currently returns a mock weather response.

### Client

The client:

- Connects to multiple MCP servers.
- Automatically discovers available tools.
- Uses a Groq LLM with LangGraph's ReAct agent.
- Selects and invokes the appropriate tool based on the user's query.

## Tech Stack

- Python
- MCP (Model Context Protocol)
- LangGraph
- LangChain MCP Adapters
- Groq
- python-dotenv

## Installation

Clone the repository:

```bash
git clone https://github.com/shreenithi23/mcp-server-practice.git
cd mcp-server-practice
```

Create a virtual environment:

```bash
python -m venv .venv
```

Activate it:

### macOS/Linux

```bash
source .venv/bin/activate
```

### Windows

```powershell
.venv\Scripts\activate
```

Install the required packages:

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

## Environment Variables

Create a `.env` file:

```env
GROQ_API_KEY=your_groq_api_key
```

## Running the Project

### 1. Start the Weather Server

```bash
python weatherserver.py
```

The Math server is automatically launched by the client using the `stdio` transport.

### 2. Run the Client

```bash
python client.py
```

## Example Queries

```text
What's (3 + 5) x 12?
```

```text
What's the weather in California?
```

## Learning Objectives

This project demonstrates:

- Building MCP servers using `FastMCP`
- Exposing Python functions as MCP tools
- Using different MCP transports (`stdio` and `streamable-http`)
- Connecting multiple MCP servers with `MultiServerMCPClient`
- Creating an AI agent with LangGraph's ReAct agent
- Integrating Groq LLMs with MCP

## Notes

- The Weather server currently returns mock weather data.
- The Math server is started automatically by the client.
- Store API keys in a `.env` file.
- Do **not** commit `.env` to GitHub.

## License

This project is intended for learning and experimentation with the Model Context Protocol (MCP).