mcp_server_client_tutorial_using_python
MCP server from mkcod/mcp_server_client_tutorial_using_python
claude mcp add --transport stdio mkcod-mcp_server_client_tutorial_using_python python -m server_project_name.server
How to use
This MCP server tutorial demonstrates building a Python-based MCP server and a client with a graphical user interface. The server is designed to expose tools that clients can call over the MCP protocol; the included example shows an add tool that sums two numbers. To use it, first start the server module as described in the installation steps, then connect a client to the running server. The client can query the server for available tools and invoke them by passing the required arguments. The provided client code hints at a UI workflow where users can select tools, enter inputs, and view results, with a Tkinter-based UI option included for convenience. The overall flow is: launch server -> client discovers tools -> client calls a tool -> server returns the result, enabling seamless interaction between LLMs and tool providers.
How to install
Prerequisites:
- Python 3.8+ installed on Windows or macOS/Linux
- Basic familiarity with Python and asynchronous programming
- Optional: uv (Python tool) for scaffolding projects
Installation steps:
- Install uv if you plan to scaffold the project:
pip install uv
- Create the MCP server project using uv (as described in the guide):
cd "your_desired_directory"
uvx create-mcp-server
- Navigate into the generated server project directory and set up the environment:
cd server-project-name
uv sync --dev --all-extras
- Prepare and run your server:
python -m server_project_name.server
- Optional: Set up a client project (with uv) and install required packages for MCP client usage:
uv init mcp-client
cd mcp-client
uv venv
# Activate the virtual environment (example for Unix-like systems)
# On Windows:
# .venv\Scripts\activate
source .venv/bin/activate
uv add mcp anthropic python-dotenv
- If you plan to use the provided UI-based client, ensure Tkinter support is available (e.g., install GUI packages as needed).
Additional notes
Tips and notes:
- The example server exposes an add tool; you can extend it by implementing more tools in server.py as shown in the guide.
- The server defaults to localhost:8000 unless configured otherwise.
- When connecting with a client, ensure the correct Python module path is used (server_project_name.server in this guide).
- If using the UI, you can wire up the Tkinter interface to call the server's tools and display results in the GUI.
- Environment variables can be used to pass API keys or configuration to the server or client if needed; add them under the env field in mcp_config or through your OS environment.
- If you encounter permission or path issues, verify that your virtual environment is active and that the server module path matches your project structure.