mcp-client-python

MCP.Pizza Chef: alejandro-ao

mcp-client-python is a Python-based MCP client built with FastAPI, designed to facilitate interaction between Large Language Models (LLMs) and MCP servers. It provides a step-by-step tutorial for setting up an MCP client that can call MCP tools exposed by servers, fetch results, and display them. This client supports Python 3.8+, requires basic FastAPI and REST API knowledge, and enables developers to integrate LLMs seamlessly into MCP workflows.

Use This MCP client To

Build MCP clients in Python using FastAPI framework Integrate LLM calls to MCP tools on servers Fetch and display MCP server tool results in applications Develop custom MCP client workflows with Python Learn MCP client setup through a guided tutorial

README

MCP Client in Python with FastAPI

This repository contains a complete tutorial on how to create an MCP (Modular Computational Platform) client in Python using FastAPI. The tutorial is inspired by the Claude Desktop application and demonstrates how to make an LLM (Large Language Model) call MCP tools from an MCP server and display the results.

Features

  • Build an MCP client using Python and FastAPI.
  • Integrate LLMs to interact with MCP tools.
  • Fetch and display results from an MCP server.
  • Step-by-step guidance for setting up and running the client.

Prerequisites

  • Python 3.8 or higher
  • Basic knowledge of FastAPI and REST APIs
  • An MCP server setup

Getting Started

  1. Clone the Repository:
git clone git@github.com:alejandro-ao/mcp-client-python.git
cd mcp-client-python
  1. Install Dependencies:
pip install -r requirements.txt
  1. Set Up Environment Variables: Create a .env file in the root directory and add your API keys. In this example, I added the SERPER_API_KEY because it is used in the MCP server file, which we built in the previous tutorial. And since we are running everything locally, we can set all the environment variables (for both serverand client) in the same file. In a more complex setup, you would deploy your MCP server separately and set the environment variables accordingly.
ANTHROPIC_API_KEY=
SERPER_API_KEY=
  1. Run the Application:
uvicorn main:app --reload
  1. Access the API: Open your browser and navigate to http://127.0.0.1:8000/docs to explore the API documentation.

Tutorial Overview

  1. Setting Up FastAPI: Learn how to create a FastAPI application and define endpoints.

  2. Connecting to the MCP Server: Understand how to make requests to the MCP server and handle responses.

  3. Integrating LLMs: Explore how to use an LLM to call MCP tools dynamically.

  4. Displaying Results: Implement logic to process and display results from the MCP tools.

Resources

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Special thanks to the creators of FastAPI and the Claude Desktop application for their inspiration.

mcp-client-python FAQ

How do I install the mcp-client-python dependencies?
Install dependencies using 'pip install -r requirements.txt' after cloning the repository.
What Python version is required for mcp-client-python?
Python 3.8 or higher is required to run the client.
Do I need prior knowledge to use mcp-client-python?
Basic knowledge of FastAPI and REST APIs is recommended for setup and customization.
How does mcp-client-python interact with MCP servers?
It makes LLM calls to MCP tools exposed by servers and fetches their results for display.
Can I use mcp-client-python with any MCP server?
Yes, as long as the server follows the MCP protocol, this client can interact with it.
Is there a tutorial included with mcp-client-python?
Yes, the repository includes a complete step-by-step tutorial for building and running the client.
How do I configure environment variables for mcp-client-python?
Create a .env file in the root directory and add necessary API keys and settings as instructed in the tutorial.
What LLM providers can be integrated with mcp-client-python?
It supports integration with various LLMs including OpenAI, Claude, and Gemini through MCP tools.