Simple -with-Python
The Model Context Protocol (MCP) is a standardized way to supply context to large language models (LLMs). Using the MCP Python SDK, you can build servers that expose data (resources), functionality (tools), and interaction templates (prompts) to LLM applications in a secure and modular fashion. In this tutorial, we’ll build a simple MCP server in P
claude mcp add --transport stdio ruslanmv-simple-mcp-server-with-python python -m your_server_module \ --env MCP_BIND_HOST="0.0.0.0 (default) or specific host" \ --env MCP_BIND_PORT="8000 (default) or custom port" \ --env MCP_LOG_LEVEL="INFO (optional; e.g., DEBUG for verbose logs)"
How to use
This MCP server is implemented in Python using the MCP Python SDK. It exposes three MCP primitives—Prompts, Resources, and Tools—so that a large language model can interact with structured data, perform actions, and use reusable prompt templates. Prompts are interactive templates that the LLM can invoke via slash commands or UI selections. Resources provide read-only data that the client application supplies to the LLM to enrich its context. Tools are executable functions that the LLM can call to perform actions or computations, such as API requests or data updates. When the server starts, it advertises which capabilities are enabled (prompts, resources, tools) and supports runtime changes via listChanged or subscribe flags as described in the server capabilities table. You can use the MCP SDK tooling to discover available prompts, resources, and tools, then invoke them through the LLM’s context, producing dynamic and context-aware interactions.
How to install
Prerequisites:
- Python 3.7+ (preferably 3.11 or higher)
- pip
- Node.js 18.x (if you need Node tooling; not required for the Python server itself)
Option 1: Manual installation
-
Create and activate a virtual environment
- python3 -m venv .venv
- source .venv/bin/activate
-
Upgrade pip inside the virtual environment
- pip install --upgrade pip
-
Install the MCP Python SDK with CLI support
- pip install "mcp[cli]"
-
Verify installation
- python -m pip show mcp
- mcp --version
Option 2: Using the install.sh script (Ubuntu 22.04 targeted)
- Save the provided install.sh script in your project directory.
- Make the script executable:
- chmod +x install.sh
- Run the script:
- bash install.sh
This script automates:
- Installing Python 3.11+ and virtual environment setup
- Installing Node.js 18.x if needed for auxiliary tooling
- Installing the MCP Python SDK from requirements.txt (if present)
Notes:
- Always activate the virtual environment in a new terminal session: source .venv/bin/activate
- The install.sh script is designed for Ubuntu 22.04.
Additional notes
Tips and common considerations:
- Environment variables: Configure MCP_BIND_HOST and MCP_BIND_PORT to control where the server binds. Use MCP_LOG_LEVEL=DEBUG during development for verbose logging.
- If you update dependencies, re-create or refresh the virtual environment to ensure compatibility.
- The MCP Python SDK handles exposing resources, prompts, and tools; ensure your server implementation registers these primitives correctly.
- When debugging, consider enabling listChanged/subscriber options to observe runtime changes in prompts/resources/tools.
- If you plan to run in production, consider containerizing the Python server (e.g., with Docker) and implementing proper process management (systemd, PM2, etc.).
Related MCP Servers
shellfirm
Terminal guardrails for humans and AI agents — intercepts dangerous commands with context-aware challenges before the damage is done.
mcp-cli
mcpc is a CLI client for MCP. It supports persistent sessions, stdio/HTTP, OAuth 2.1, JSON output for code mode, proxy for AI sandboxes, and much more.
mcp-shell
Give hands to AI. MCP server to run shell commands securely, auditably, and on demand.
hackerone-graphql
MCP server for the HackerOne GraphQL API
terminal
A minimal, zero-dependency terminal MCP (Model Context Protocol) client built for coding agents like OpenAI Codex.
opensearch
OpenSearch 3.0 with MCP Server