mcp-client-x

This repository provides a client-server example using the Model Context Protocol (MCP), demonstrating how to connect large language models with tools and data. It includes implementations for BMI calculation and

13
1

MCP Client Example

This project demonstrates a client-server implementation using the Model Context Protocol (MCP), a standardized way to connect large language models with tools and data.

Overview

This example showcases the creation of an MCP server with custom tools, connecting to the server using an MCP client, and calling tools to get responses from the server.

Project Structure

The project includes a pyproject.toml file, README.md, a src directory containing the client (mcp_client.py) and server (example_server.py) implementations, and a uv.lock file.

Server Implementation

The server exposes two tools: calculate_bmi, which computes Body Mass Index, and fetch_weather, an async tool that retrieves weather data from an external API.

Client Implementation

The client connects to the server via stdio, initializes a session, and calls the server's tools.

Getting Started

To get started, you need Python 3.9+ and uv (Python package manager). Install dependencies using uv install -e .. Run the example using uv run src/client/mcp_client.py.

Usage

The client connects to the server, lists available tools, calls the BMI calculator with sample data, and calls the weather tool with sample coordinates.

Test with MCP Inspector

Run mcp dev src/server/example_server.py and visit http://localhost:5173 to test with the MCP Inspector.

Resources

This project uses the Model Context Protocol Python SDK and refers to the MCP Official Documentation.

Repository

RG
RGGH

RGGH/mcp-client-x

Created

March 8, 2025

Updated

March 28, 2025

Language

Python

Category

AI