October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Developer Tools

How to Run an MCP Server in Python

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run a Python MCP server, install the official MCP SDK v2 with its CLI extra, create a server file, and start it with the development command. The SDK requires Python 3.10 or newer. For local clients that launch your program, use stdio; for clients connecting to a network endpoint, use Streamable HTTP and configure its host security deliberately.

Install the official Python MCP SDK

The MCP Python SDK documentation lists v2 as its current stable release line and specifies Python 3.10+. The cli extra provides the mcp command used for development.

  1. Check your interpreter: python --version. Use Python 3.10 or later.
  2. Install the package in your project with one of these options:
    uv add "mcp[cli]"
    or
    pip install "mcp[cli]"

Use the same Python environment for installation and execution. With uv, run commands through uv run so the project environment is used. With pip, activate the virtual environment where you installed the package before running the CLI.

Create a minimal server with one tool

Save this complete example as server.py. It registers a named server and a tool called add, which accepts two integers and returns their sum.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Example Python Server")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two integers and return the result."""
    return a + b

if __name__ == "__main__":
    mcp.run()

The function’s name, parameters, type hints, and docstring give an MCP client the tool’s identity and description. Keep the example’s mcp.run() default for the usual local stdio launch; choose another transport explicitly when serving network clients. This uses the v2-style FastMCP API rather than assuming older SDK examples or imports still apply.

Run and inspect it during development

From the directory containing server.py, run:

uv run mcp dev server.py

The official quickstart uses this command to start the server file in the SDK’s development workflow, allowing you to inspect and exercise its registered tools. It is a development path, not by itself a production deployment recipe. The quickstart also documents testing through an in-process SDK client; use the SDK’s current quickstart for the version-specific client setup: Python server quickstart.

If you installed with pip rather than uv, activate the environment containing the CLI and run mcp dev server.py. If the shell cannot find mcp, verify that the CLI extra was installed in the active environment.

Rank #2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)

Choose a transport for the client you have

The SDK supports stdio, Streamable HTTP, and SSE. These are different connection models, not interchangeable launch flags: choose according to how the MCP client reaches the server.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Transport Connection model When it fits Operational consideration
stdio A local host launches the server as a subprocess and exchanges protocol messages through standard input and output. Local developer tools or other hosts configured to start a command on the same machine. Standard output is reserved for protocol traffic; send logs and diagnostics to standard error.
streamable-http A client reaches a server over HTTP. Web or remote-client integrations where the server is hosted as an ASGI application or process. Configure accepted host values for a real hostname; plan process scaling and session handling as part of deployment.
sse An additional network transport supported by the SDK. Use when the client and deployment you target require the SDK’s SSE transport. Check client compatibility and the SDK’s current transport documentation instead of assuming it behaves like stdio or Streamable HTTP.

The current MCPServer.run() API supports all three names and defaults to stdio. For a client that launches a local process, the default is generally the natural choice. For a client that connects to an HTTP endpoint, select Streamable HTTP and serve the HTTP app or run the matching transport directly.

Keep stdio protocol traffic clean

With stdio, the server reads MCP messages from stdin and writes them to stdout. Any ordinary text printed to stdout can be mistaken for a protocol message and break the connection. Avoid print() for diagnostics in this mode; configure logging to stderr instead.

Rank #3
ELECROW CrowPi Case Kit for Raspberry Pi 5, 9-Inch Display
  • Not including the Raspberry Pi 5 (8GB), the Crowpi advanced version comes with the Raspberry Pi 5
  • ELECROW Black Case for the Raspberry Pi 5, CrowPi is equipped with a 9-inch HD touchscreen along with a camera; All the regular components used in DIY electronics are packed into the CrowPi development board, such as LCD, LED matrix, buzzer, light sensor, PIR sensor, ultrasonic sensor, IR sensor, etc
  • Raspberry Pi Sensors: The Crowpi raspberry pi 5 programming kit is jam-packed with lots of buttons such as 19 different sensors in a tidy easy to use package; You don't have to wait and wire things
  • Build Quality: Solid ABS shell and well made components in one place make it strong and convenient to travel
  • Programming Lessons: This raspberry pi 5 learning kit ships with step by step instructions and provides 21 lessons to take you through identifying components reading code and running it in the terminal
import logging
import sys

logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logging.info("Server starting")

Tool results should be returned through the SDK’s tool mechanism, not emitted as ad hoc terminal output. This distinction matters even when the server appears to run normally in a terminal: the MCP host communicates through those same streams.

Run the server over Streamable HTTP

Use the SDK ASGI app

For integration with a web application, the SDK’s mcp.streamable_http_app() returns a Starlette ASGI app and includes the /mcp route. An ASGI host such as Uvicorn can serve it. A basic local host can be assembled as follows, assuming the server object from the earlier example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import uvicorn

if __name__ == "__main__":
    app = mcp.streamable_http_app()
    uvicorn.run(app, host="127.0.0.1", port=8000)

Install Uvicorn in the same environment if it is not already present. Start the file with that environment’s Python, then the MCP endpoint is http://127.0.0.1:8000/mcp. This binds to the local machine for development; it does not make the server publicly reachable.

Rank #4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
  • Fully assembled for plug-and-play operation
  • Includes Raspberry Pi 5 with 8GB RAM
  • 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
  • M.2 HAT+
  • CanaKit Turbine Black Case for the Pi 5

Do not expose localhost defaults unchanged

The ASGI helper is localhost-oriented and enables DNS-rebinding protections. A real hostname must be explicitly included in the transport security settings’ accepted host values. Configure that allowlist to match the hostname through which clients actually reach the service, and retain the protections rather than treating them as optional cosmetics. The exact configuration interface can change with SDK releases, so use the version-matched deployment guide: MCP remote server deployment guide.

Do not assume that changing Uvicorn’s bind address is sufficient. Binding controls where the process listens; accepted-host security controls which host headers the MCP transport will accept. For a public deployment, account separately for TLS termination, authentication and authorization, firewall or proxy configuration, and the identity of permitted clients. The SDK’s transport helper does not by itself establish those application-specific policies.

Plan scaling and session behavior

The SDK deployment guide notes that mcp.run("streamable-http") starts one Uvicorn process. Production worker counts, process supervision, and multi-worker behavior depend on the ASGI/process architecture and session handling. Before adding workers or replicas, confirm that sessions and any in-memory state are handled correctly across processes; a successful single-process local run does not prove that a multi-worker topology will behave correctly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build beyond the first tool

Once the client can discover and invoke add, extend the server in small steps:

  • Give each tool a narrow, descriptive name and a docstring that tells a model or user what it does.
  • Use accurate parameter types and validate values that need constraints beyond their Python type.
  • Return useful errors for invalid inputs without exposing secrets or internal implementation details.
  • Keep side effects explicit. A tool that writes files, sends messages, or changes remote data should have an understandable scope and appropriate access controls.
  • Choose stdio or HTTP based on the client’s actual connection model before designing deployment around it.

These are application-design practices rather than transport guarantees. The SDK makes tools available through MCP; it does not decide which users should be authorized to invoke a sensitive operation.

Troubleshoot common startup and connection problems

Symptom Likely cause What to check
mcp: command not found The CLI extra is missing, or the command is being run outside the environment where it was installed. Install mcp[cli] and activate that environment, or use uv run mcp dev server.py from the project.
Import or syntax errors during startup The interpreter may be too old, the wrong environment may be active, or code may follow a different SDK API version. Check python --version, verify the installed package environment, and follow the v2 documentation rather than copying an older example.
The local host cannot connect in stdio mode The host may be launching a different executable or working directory, or the server may emit non-protocol text to stdout. Check the host’s configured command and file path, then move diagnostic prints and logging to stderr.
The HTTP route returns a host-related rejection The hostname is not included in the transport’s accepted-host settings. Configure the host allowlist for the actual hostname and review the deployment guide’s DNS-rebinding security guidance.
A remote client cannot reach a locally working endpoint The process may be bound only to loopback, or a proxy, firewall, TLS, or routing layer may not forward the endpoint. Check the bind address and network path separately from host allowlisting; expose the service only behind the access controls your deployment requires.
Behavior changes after adding workers Sessions or in-memory server state may not be shared across worker processes. Review the ASGI deployment architecture and session strategy before scaling the process count.

Or skip the browser setup

If the MCP tool you need is a clean website screenshot, ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-request screenshot API returns an image or PDF. For a direct API call, install Python’s requests package and run this complete example; replace the URL with the page you need and set your API key.

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

See the ScreenshotNeo API documentation for request options and response details. It accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, or any MCP client. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Does mcp.run() use stdio by default?

Yes. The current Python SDK API defaults to stdio; select another supported transport when your client requires it.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99
Bestseller No. 4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
Fully assembled for plug-and-play operation; Includes Raspberry Pi 5 with 8GB RAM; 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
$339.97

What URL does the SDK’s Streamable HTTP app expose?

The ASGI helper includes the /mcp route.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.