Guide · Open source
How to use python-sdk: build MCP servers and clients in Python
Updated · written with AI from the project's own documentation and checked against our catalogue data
The modelcontextprotocol python-sdk is the official Python implementation of the Model Context Protocol (MCP), a standard way for LLM applications to access data and functionality. It is for Python developers who want to expose their own functions to an LLM app, or connect to existing MCP servers. By the end of this guide you will know how to install it, run a small server, and call it from a client.
Quick start
- 1Check your Python version. Confirm you have Python 3.11 or newer installed, since the SDK requires it.
- 2Install the package. Run uv add "mcp[cli]" in your project, or pip install "mcp[cli]" if you use pip.
- 3Create server.py. Write type-hinted functions and decorate them with @mcp.tool() or @mcp.resource(...).
- 4Test in the Inspector. Run uv run mcp dev server.py and call your tools from the MCP Inspector.
- 5Run over HTTP. Start the server with uv run mcp run server.py --transport streamable-http.
- 6Call it from a client. Create a Client pointed at the server URL and call your tool with call_tool.
What you need before you install python-sdk
The SDK requires Python 3.11 or newer. It is a developer library, so you need to be comfortable writing and running Python code. It is not an end-user application.
- Python 3.11+
- A package manager: uv or pip
Install the mcp package with uv or pip
The package is published as mcp. Install it with the cli extra, which adds the mcp command-line tool. If you do not need the command-line tool, install plain mcp instead.
For one-off commands you can run the tool without creating a project.
uv add "mcp[cli]" # or: pip install "mcp[cli]"
uv run --with "mcp[cli]" mcp ...Write your first MCP server
Create a file called server.py. Plain type-hinted Python functions become MCP tools, so you do not write JSON Schema or protocol code. The type hints act as the schema, and the docstring describes the function.
This example defines one tool named add and one templated resource.
- @mcp.tool() exposes a function as a tool
- @mcp.resource(...) exposes a function as a resource using a URI template
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.resource("greeting://{name}")
def greeting(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"Test the server with the MCP Inspector
The mcp dev command opens the MCP Inspector so you can call your tools in a browser. Call add with a=1 and b=2 and you should get 3 back.
uv run mcp dev server.pyConnect a Python client to a server
The same package includes a client. To serve your server over HTTP, use the run command with the streamable-http transport. A URL given to Client means Streamable HTTP.
Client can also launch a local server as a stdio subprocess or use a custom transport. The official documentation covers those options.
- stdio: a local server started as a subprocess
- Streamable HTTP: the transport for deployed servers
- SSE: also supported according to the README
uv run mcp run server.py --transport streamable-http
import asyncio
from mcp import Client
async def main() -> None:
async with Client("http://localhost:8000/mcp") as client:
result = await client.call_tool("add", {"a": 1, "b": 2})
print(result.structured_content) # {'result': 3}
asyncio.run(main())Where to go next
The README points to the full documentation site, which has a Get started guide, a What's new page, an API reference, and a migration guide. Use these for anything beyond the basic server and client shown here.
- Get started guide: py.sdk.modelcontextprotocol.io/get-started/
- API reference: py.sdk.modelcontextprotocol.io/api/mcp/
- Contributing guide on GitHub for contributors
What people use it for
- Expose your own Python functions to an LLM app as MCP tools
- Build a client that connects to an existing MCP server
- Serve a resource such as a templated greeting URI to an MCP host
- Use a reference Python implementation while following the official MCP specification
Frequently asked questions
How do I install python-sdk?
Install the package named mcp with the cli extra. Run uv add "mcp[cli]" with uv, or pip install "mcp[cli]" with pip. You need Python 3.11 or newer.
Is python-sdk free to use?
Yes. The project is licensed under the MIT License, as stated in its README. See the LICENSE file in the repository for the full terms.
What Python version does the MCP Python SDK need?
The README lists Python 3.11+ as the requirement. Projects that must run on older Python versions will not be able to use it as described.
Do I need to write JSON Schema to define an MCP tool?
No. The SDK turns type-hinted Python functions into MCP tools, so the type hints serve as the schema and the docstring describes the tool.
Which transports does the SDK support?
The README says it supports stdio, Streamable HTTP, and SSE. A client given a URL uses Streamable HTTP, and Client can also launch a local server as a stdio subprocess.
How does python-sdk compare with FastMCP or the TypeScript SDK?
The source lists the TypeScript SDK for MCP, FastMCP, and LangChain MCP adapters as comparable projects. This page does not compare their features or performance, so check each project's documentation for differences.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Choose python-sdk if you write Python and want an official, spec-following library to expose functions as MCP tools or to build clients. Skip it if you need a ready-made end-user app, do not write code, or must run on Python below 3.11.
Install options & downloads