MCP cover image
See in Github
2025-03-09

Python MCP Client + Server Beispiel

1

Github Watches

2

Github Forks

12

Github Stars

MCP Client Example ☀️

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

Overview

This example shows how to:

  • Create an MCP server with custom tools
  • Connect to the server using an MCP client
  • Call tools and get responses from the server

Tutorial Video

MCP Tutorial Video

Click the image above to watch a tutorial on MCP implementation.

Project Structure

.
├── pyproject.toml
├── README.md
├── src
│   ├── client
│   │   └── mcp_client.py      # MCP client implementation
│   └── server
│       └── example_server.py  # MCP server with tools
└── uv.lock

Server Implementation

The server exposes two tools:

  1. calculate_bmi - A simple calculator that computes Body Mass Index
  2. 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

Prerequisites

  • Python 3.9+
  • uv (Python package manager)

Installation

# Install dependencies
uv install -e .

Running the Example

  1. Start the client (which will automatically start the server):
uv run src/client/mcp_client.py

Usage

The client will:

  1. Connect to the server
  2. List available tools
  3. Call the BMI calculator with sample data
  4. Call the weather tool with sample coordinates

Example Response

Available tools: meta=None nextCursor=None tools=[...]
BMI calculation result: 22.857142857142858
Weather data: {"current_weather":{"temperature":14.2,"windspeed":12.6, ...}}

Test with MCP Inspector

( run command below and then visit http://localhost:5173 )

  ❯ mcp dev src/server/example_server.py
Starting MCP inspector...
Proxy server listening on port 3000

🔍 MCP Inspector is up and running at http://localhost:5173 🚀
New SSE connection
Query parameters: {
  transportType: 'stdio',
  command: 'uv',
  args: 'run --with mcp mcp run src/server/example_server.py',

Resources

This project uses:

License

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

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • Entdecken Sie die umfassendste und aktuellste Sammlung von MCP-Servern auf dem Markt. Dieses Repository dient als zentraler Hub und bietet einen umfangreichen Katalog von Open-Source- und Proprietary MCP-Servern mit Funktionen, Dokumentationslinks und Mitwirkenden.

  • OffchainLabs
  • GO -Umsetzung des Ethereum -Beweises des Anteils

  • modelcontextprotocol
  • Modellkontext -Protokollserver

  • huahuayu
  • Ein einheitliches API-Gateway zur Integration mehrerer Ethercan-ähnlicher Blockchain-Explorer-APIs mit Modellkontextprotokoll (MCP) für AI-Assistenten.

  • Mintplex-Labs
  • Die All-in-One-Desktop & Docker-AI-Anwendung mit integriertem Lappen, AI-Agenten, No-Code-Agent Builder, MCP-Kompatibilität und vielem mehr.

    Reviews

    4 (1)
    Avatar
    user_FKaUgURn
    2025-04-15

    As a dedicated MCP application user, I highly recommend the MCP server for Azure Cosmos DB using the Go SDK created by abhirockzz. It offers seamless integration and exceptional performance. The Go SDK is efficient, making it ideal for developers seeking scalability and robust database management. More details can be found at https://mcp.so/server/mcp_cosmosdb_go/abhirockzz.