mcp-client-server-python
Basic implementation mcp client server
Documentation
MCP Client-Server Python Example
This project demonstrates a simple client-server MCP.
What is MCP (Model Context Protocol)?
> MCP 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.
> It facilitates secure, multi-channel communication between AI models and external systems, supporting advanced agentic workflows and tool use.
>
> ๐ Anthropic's announcement
> ๐ MCP documentation
Features
- MCP Server: Exposes tools (e.g., addition) and resources (e.g., greetings) via SSE.
- MCP Client: Connects to the server, lists available tools, and interacts using OpenAI's chat completions.
- OpenAI Integration: Uses OpenAI's GPT models to process user queries and call server tools as needed.
Requirements
- Python 3.12+
- MCP Python SDK
- OpenAI Python SDK
- Uvicorn (for running the server)
- python-dotenv (for loading environment variables)
- uv (fast Python package installer and resolver)
Project Structure
.
โโโ client.py # MCP client implementation
โโโ server.py # MCP server implementation
โโโ pyproject.toml # Project metadata and dependencies
โโโ .env # Environment variables (not committed)
โโโ README.md # This file**Install dependencies with uv:**
uv sync*(This will install all dependencies as specified in `uv.lock`.)*
Setup
1. Environment Variables
Create a `.env` file in the project directory:
OPENAI_API_KEY=your-openai-api-key
MCP_SSE_URL=http://localhost:8080/sse2. Start the Server
uv run server.py --host 0.0.0.0 --port 8080The server exposes tools and resources via SSE at `/sse`.
3. Run the Client
In another terminal:
uv run client.pyThe client will connect to the server, list available tools, and start an interactive chat loop.
Usage
- Type your queries in the client prompt.
- The client will use OpenAI to process your query and call server tools if needed.
- Type `quit` to exit the client.
Frequently asked questions
What is mcp-client-server-python?
mcp-client-server-python is Basic implementation mcp client server
How do I install mcp-client-server-python?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is mcp-client-server-python open source?
Yes โ it is hosted on GitHub at https://github.com/sofianhw/mcp-client-server-python.
Related MCP tools
AWS MCP Servers โ helping you get the most out of AWS, wherever you use MCP. Python-based implementation. Trusted by 6900+ developers.
A simple, secure MCP-to-OpenAPI proxy server Python-based implementation. Trusted by 3500+ developers. Trusted by 3500+ developers.
MCP server that interacts with Obsidian via the Obsidian rest API community plugin Python-based implementation. Trusted by 2300+ developers.
Default Configuration: MCP CLI defaults to using Ollama with the gpt-oss reasoning model for local, privacy-focused operation without requiring API keys.
Official MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
MCP server for long term agent memory with Mem0. Also useful as a template to get you started building your own MCP server with Python!
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP