mcpField
M
MCP Client-Server Python Example

MCP Client-Server Python Example

Local
github.com/sofianhwDeveloper Tools0Updated 77w ago

About MCP Client-Server Python Example

MCP Client-Server Python Example is a Python demonstration of an MCP server and client, for developers exploring the protocol. The client uses OpenAI chat completions to handle queries and call server tools.

Key features

  1. 01SSE server with tools and resources
  2. 02Client connects and lists tools
  3. 03OpenAI chat-completions integration

Use cases

  1. 01Explore a basic MCP client-server setup
  2. 02Try tool calls from an interactive chat

MCP support

The example includes an MCP server that exposes tools and resources over SSE, plus a client that connects, lists tools, and invokes them through an OpenAI-powered chat loop.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

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

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/sse
    
  2. Start the Server

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

    The server exposes tools and resources via SSE at /sse.

  3. Run the Client

    In another terminal:

    uv run client.py
    

    The 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.

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.