MCP Client-Server Python logo

MCP Client-Server Python

by sofianhw

This project demonstrates a simple client-server implementation using the Model Context Protocol (MCP). It allows LLMs to interact with external tools and resources in a standardized way.

View on GitHub

Last updated: N/A

What is MCP Client-Server Python?

This is a Python-based client-server example that utilizes the Model Context Protocol (MCP) to enable communication between a client and a server, allowing LLMs to interact with external tools and resources.

How to use MCP Client-Server Python?

  1. Set up environment variables (OPENAI_API_KEY, MCP_SSE_URL). 2. Start the server using uv run server.py --host 0.0.0.0 --port 8080. 3. Run the client in another terminal using uv run client.py. 4. Interact with the client by typing queries, and type quit to exit.

Key features of MCP Client-Server Python

  • MCP Server exposing tools and resources via SSE

  • MCP Client connecting to the server and listing available tools

  • OpenAI Integration for processing user queries and calling server tools

  • Simple example demonstrating basic MCP functionality

Use cases of MCP Client-Server Python

  • Demonstrating MCP usage

  • Building AI agents that can interact with external tools

  • Creating LLM-powered applications that require access to external resources

  • Experimenting with different tool integrations for LLMs

FAQ from MCP Client-Server Python

What is MCP?

MCP (Model Context Protocol) is an open protocol introduced by Anthropic to enable large language models (LLMs) to interact with external tools, APIs, and resources in a standardized, extensible way.

What are the requirements for running this project?

Python 3.12+, MCP Python SDK, OpenAI Python SDK, Uvicorn, python-dotenv, and uv.

How do I install the dependencies?

Use uv sync to install all dependencies specified in uv.lock.

How do I start the server?

Run uv run server.py --host 0.0.0.0 --port 8080.

How do I run the client?

Run uv run client.py in another terminal after starting the server.