MCP Python SDK

MCPGitHubLevel: IntermediateFree
Logo MCP Python SDK

MCP Python SDK

4.0/52dm rating

A fast way to write an MCP server in Python.

The official library for writing MCP servers and clients in Python.

Overview

The MCP Python SDK is the official Python library set for building both MCP servers and MCP clients. For servers, you declare tools, resources and prompts using simple decorators on Python functions with type hints; for clients, you connect to any MCP server.

The SDK requires Python 3.10 or later and supports the stdio, Streamable HTTP and SSE transports. The package with the cli extra provides the mcp command to run a server, open the MCP Inspector or install a server into an AI app.

It is a good fit for businesses that already have Python scripts, data systems or Python automation and want to expose them to AI assistants.

Highlights

01

Official, MIT license

The SDK is developed by the MCP project and licensed under MIT.

02

Decorator-based declaration

Use @mcp.tool() and @mcp.resource() on Python functions to turn them into tools and data for AI.

03

Both server and client

Build a server and also use the Client class to call tools on other servers.

04

Three transports

Supports stdio, Streamable HTTP and SSE.

05

Handy mcp command

mcp dev opens the server in the Inspector, mcp run runs the server, mcp install installs it into an app.

06

Upgrade docs available

The documentation has a section introducing v2 and a migration guide.

What it's for

Expose sales data to AI

Write a Python tool that queries the order database so an AI assistant can answer revenue questions.

Reuse existing scripts

Wrap Excel and reporting scripts as tools that employees call through AI.

Connect internal systems

Create a server that calls your company's CRM or warehouse software APIs.

Build your own agent

Use the Client part so your Python app can call tools from multiple MCP servers.

Deploy a remote server

Run the server over Streamable HTTP so many people in the company can share it.

How to use it

  1. 1

    Install the SDK with uv

    A project using uv can add the package with the CLI extra.

    $uv add "mcp[cli]"
  2. 2

    Or install with pip

    Use pip if you don't use uv; drop [cli] if you don't need the mcp command.

    $pip install "mcp[cli]"
  3. 3

    Write a minimal server

    Create server.py, initialize MCPServer and attach @mcp.tool() to a function with type hints.

  4. 4

    Try it in the Inspector

    Open the server in the MCP Inspector to test the tool before connecting it to an AI app.

    $uv run mcp dev server.py
  5. 5

    Run over HTTP

    Serve the server over Streamable HTTP; the default endpoint in the README is localhost:8000/mcp.

    $uv run mcp run server.py --transport streamable-http

Video guides

Intro to MCP Servers – Model Context Protocol with Python Course

freeCodeCamp.org

Build Anything With a CUSTOM MCP Server - Python Tutorial

Tech With Tim

Python + MCP: Building MCP servers with FastMCP

Microsoft Reactor

Real-world example

Illustrative scenario

A cosmetics store chain in Ho Chi Minh City already has a Python script that totals revenue by branch. A developer wraps that function as a tool with the MCP Python SDK, tests it in the Inspector, then runs the server over Streamable HTTP on an internal machine. A regional manager asks the AI assistant about last week's branch revenue and the AI calls the existing function instead of staff running it by hand.

Tips & notes

  • Write full type hints

    The SDK relies on function types to describe parameters to the AI.

  • Name and describe tools clearly

    A good description helps the model pick the right tool.

  • Always test with mcp dev

    Check the tool in the Inspector before handing it to users.

  • Check the v2 docs

    If you follow older guides, compare against the migration page since examples now use MCPServer.

FAQ

Which Python version is needed?

Python 3.10 or later.

Is the [cli] extra required?

No. You only need it if you want the mcp commands such as mcp dev, mcp run, mcp install.

Is the SDK free?

Yes, open source under the MIT license.

Can I build a client?

Yes, the SDK provides a Client class to connect to and call tools on HTTP or stdio servers.

Useful links

Want to apply this in your business?

2dm looks at your workflows, picks the right tools and sets them up with your team. The first call is free.

Book a call
Zalo