SyncAI.news, a Varaisys broadcasting
Build Your First MCP Server in Python (Stateless Spec Edition)
KM

Kanwal Mehreen

· 1 min read

EngineeringKDnuggets

Build Your First MCP Server in Python (Stateless Spec Edition)

The Model Context Protocol changed in an important way this summer. With the 2026-07-28 MCP specification, the protocol core is now stateless: modern clients no longer need to establish a protocol session before making requests, and servers no longer rely on Mcp-Session-Id for ordinary requests. That makes MCP servers much easier to scale behind normal HTTP infrastructure.

At the same time, the official Python SDK has moved to v2 as its current stable line and provides a higher-level MCPServer API for defining tools, resources, and prompts with regular Python functions.

In this tutorial, we will build a small but complete MCP server in Python, run it over Streamable HTTP, inspect it locally, and connect to it with a Python MCP client. Let's get started.

What Are We Building?

We will create a small developer knowledge-base server.

It will expose three MCP primitives:

Tool:
    search_kb(query, limit)

Resource:
    kb://articles

Prompt:
    draft_support_reply(customer_message)

The server will contain no user session state. Every request will contain everything required to process it, which makes it a good example of the new stateless MCP model.

Conceptually:

LLM Host
   |
   | MCP request
   v
+-----------------------+
| Python MCP Server     |
|                       |
| search_kb()           |
| kb://articles         |
| draft_support_reply() |
+-----------------------+

Step 1: Creating the Project

The current Python SDK requires Python 3.10 or newer. The official documentation recommends installing the CLI extra because it gives us the development command and MCP Inspector workflow.

Using uv:

mkdir first-mcp-server
cd first-mcp-server

uv init
uv add "mcp[cli]"

Or with pip:

pip install "mcp[cli]"

Your project can be as small as:

first-mcp-server/
├── server.py
└── client.py

No framework boilerplate is required.

Step 2: Creating Your First MCP Server

Create server.py:

Now let's give our server some data.

So far this is just Python.

Step 3: Adding an MCP Tool

Add this to server.py:

Add:

Original source

This story was published by KDnuggets and written by Kanwal Mehreen. SyncAI.news shows a preview; the complete article is on the publisher's site.

Read the full story on kdnuggets.com

Similar News