Essential cookies keep the site working and remember this choice. They are always on. Read the cookie policy for every cookie we use.

Optional cookies

Engineering9 min read

MCP for Python developers: what it is and when to use it

MCP for Python developers. How the Model Context Protocol works, how to build a server and client with the Python SDK, and when it beats plain function calling.

MCP gives large language models no new capability. Everything it does, Python developers have been doing with function calling for years. What it adds is a standard way to define tools, so one server can serve many applications instead of every developer writing their own Slack or Google Drive integration.

That is the test for whether MCP is worth it. Most tutorials show you how to plug a server into Claude Desktop. This guide is developer first. It shows how to build a server with the Python SDK, connect it to your own backend, wire it into an LLM call, and then decide whether you should have done any of that.

What MCP is and why it took off

Anthropic released the Model Context Protocol on November 25, 2024. They introduced it as a new standard for connecting AI assistants to the systems where data lives, like content repositories, business tools and development environments. When I first read the announcement, I could not tell whether it was a new model, a Claude feature, or something that would also work with OpenAI.

So I ignored it for a while. New things show up in AI every other week, and I don't want to change our project architecture every month. Then search interest exploded from the beginning of March 2025, and MCP showed up everywhere, from YouTube to X to my own Data Freelancer community.

The reason was adoption. Hundreds of companies and tools now expose their APIs through MCP servers, and OpenAI added MCP support to its Agents SDK. Latent Space wrote that MCP had won. A protocol is only as strong as the number of people using it, and the GitHub star history for MCP grew faster than any AI framework I had tracked.

MCP standardizes what function calling already does

Before MCP, connecting an LLM app to Slack meant writing your own API layer. You wrote a send_message function, then either called it from your own logic or gave the model a tool definition and let it decide through function calling. Every developer did this slightly differently.

MCP puts a protocol in the middle. It defines exactly how to specify schemas, functions, documentation and arguments, so any AI application can talk to any server through one interface. That is useful, especially at scale. But it is the same thing you could already do.

Hosts, clients and servers

Three terms carry most of the protocol:

  • Hosts are programs that want to access data through MCP. Claude Desktop, an IDE, or, more interesting for developers, your own Python application.
  • Clients live inside the host and keep a one-to-one connection with a server.
  • Servers are lightweight programs that expose capabilities through the protocol. They can reach local data sources or remote services over the internet.

A server can expose tools, resources and prompts. Tools are where I see almost all of the value. Resources let you share local files through the server, and prompts let you register reusable prompts. Both work, but today you would usually serve data through a RAG pipeline and manage prompts in a tool like Langfuse.

As a developer, think of a tool as any Python function. That could be a database query or a Slack message. Whatever logic you put on the server becomes available to every host that connects.

The transport is the real design decision

MCP supports two kinds of transport, and this is the part that made the protocol click for me.

With stdio, the server and client run on the same machine. Your client starts the server as a subprocess and talks to it directly. Almost every quickstart uses this. For our own backends, it felt cumbersome. Most of our client projects needed one to three tools, all simple Python functions you could generate in one prompt. Spinning up a server and managing a connection felt like a lot of ceremony next to importing a tools.py file.

With HTTP, the server runs somewhere else and your applications connect to it over the network. Now one server can hold all your tools, several client applications can share them, and you can run multiple servers in parallel. In my crash course this transport is server-sent events (SSE). Newer versions of the MCP spec replace SSE with Streamable HTTP, so check the current SDK docs for the transport name.

The split matters less for personal tools. If you use Claude Desktop or Cursor on your own laptop, local stdio servers work well. For your own production backends, remote transport is where MCP stops being overhead.

Build a server with the Python SDK

The official Python SDK makes a server a few lines of code. Install mcp[cli] (I use uv for this), then create a FastMCP instance and decorate your functions. My crash-course server is about 31 lines. If you have used FastAPI, the pattern will look familiar:

Python
from mcp.server.fastmcp import FastMCP
 
mcp = FastMCP("calculator")
 
 
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b
 
 
if __name__ == "__main__":
    mcp.run(transport="stdio")

The function name becomes the tool name and the docstring becomes its description. Swap the body for anything you like, such as a database lookup or a call to another API.

Before you write a client, test the server with the MCP Inspector. Run mcp dev server.py, connect, and list the tools. You can call add with two numbers and see the result without writing any client code. You will keep using it to debug the server later.

Connect your own Python app to the server

The SDK also handles the client side. Over stdio you give the client the command that starts the server, and it boots the server for you:

Python
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
 
server_params = StdioServerParameters(command="python", args=["server.py"])
 
 
async def main():
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            result = await session.call_tool("add", arguments={"a": 2, "b": 4})

Over HTTP the flow is the same, except you start the server yourself and the client connects to its host and port instead. If the server is not running, the session cannot connect.

There is no AI in this example yet. MCP here only moves tools, prompts and data between processes, in a format LLMs can use.

Stuck building prototypes?

Get our production stack

What you're missing is the architecture, evaluation, and judgment to ship a real project.

See Curriculum

Wire MCP tools into an LLM call

To use the tools with a model, your client does four things. If you know how AI agents work with plain tool calling, this flow will look familiar.

First, list the tools from the server and convert each one to the format your provider expects. For OpenAI that is a function definition:

Python
openai_tools = [
    {
        "type": "function",
        "function": {
            "name": tool.name,
            "description": tool.description,
            "parameters": tool.inputSchema,
        },
    }
    for tool in tools.tools
]

Second, send the user's question and those tools to the chat completions API with tool_choice set to auto. The model decides whether to answer directly or call a tool. Third, when the response contains a tool call, parse the name and arguments and execute it through session.call_tool. The function runs on the MCP server, not in your client. Fourth, append the assistant's tool call and the tool result to the messages, and call the model again for the final answer.

In the crash course I emulate RAG this way. The server has a get_knowledge_base tool that returns five question-and-answer pairs from a company knowledge base. Ask "what is our vacation policy?" and the model calls the tool, gets the knowledge base back through MCP, and answers from it. In a real project you would replace the body of that tool with similarity search or hybrid search over your own data.

MCP vs function calling

The same app without MCP gives the exact same result. You define the tool in the same file, pass it to the model, handle the tool call and call the model again. The only difference is where the tool lives:

Function callingMCP
Where the tool livesIn your application codeOn an MCP server, local or remote
Who can reuse itThat one applicationAny host that connects to the server
SetupA function and a tool schemaA server, a client session and a transport
Best fitA few tools in one appShared tools across apps, or existing MCP servers

So should you migrate your existing AI projects to MCP? Most likely not. If function calling works today, MCP will not change the result, and it adds complexity at the start. For new projects that rely heavily on tools, using standard servers or building your own can make sense.

Run your MCP server in Docker

In my view, remote servers are the most practical way to use MCP in real backends, because that is where reuse starts. Packaging a server is ordinary Docker work. Add a Dockerfile that installs the requirements and runs server.py, build the image with docker build, and run it with docker run on the right port. Your client connects exactly as before.

From there, put the container on a virtual machine or a managed resource on Hetzner, AWS or Azure. Clone the repository, start the container, and connect to the server by domain or IP address instead of localhost. Your tools now live in one place, and any application can reach them.

Once servers hold database connections, lifecycle management matters. The SDK lets you add a lifespan to the server so connections are opened on startup and closed cleanly on shutdown. You don't need it on day one. You will need it when teams start running several servers and clients against the same databases.

When MCP is worth it in 2026

My take today is that most AI products don't need an MCP server. MCP is a protocol. It is never the direction you take to solve a problem. You solve the problem first, and once the product works, MCP is one way to make it available in another format.

It earns its place in two situations. First, when you have an existing software product and want an agent like Claude Code or Codex to work with it directly, so users don't have to click through the UI. Second, in client work. When we automate back-office work for small businesses, the on-demand layer is often a skill plus a custom MCP server that an employee uses from ChatGPT or Codex. Out-of-the-box connectors exist, but the custom servers and the skills around them are where the value is. The client delivery process shows how those projects get scoped and shipped.

MCP fits into the backend layer of production AI systems, next to FastAPI, workers, Postgres and Docker. If you want to learn that whole stack in order, with MCP in its proper place, the GenAI Accelerator is the structured path.

FAQ

What is MCP in simple terms?

MCP, the Model Context Protocol, is an open standard from Anthropic for making tools, resources and prompts available to LLM applications. It defines how a host connects to a server and how tools are described and called. It does not add new capabilities to the model.

Is MCP better than function calling?

Not for the result. A model calling a tool through MCP gives the same output as plain function calling. MCP is better when you want to share tools across several applications or use existing MCP servers, and plain function calling is simpler for a few tools inside one app.

How do I create an MCP server in Python?

Install the official SDK with mcp[cli], create a FastMCP instance, and decorate plain Python functions with @mcp.tool(). Run it with mcp.run() and test it with mcp dev server.py, which opens the MCP Inspector.

Should I migrate my AI project to MCP?

Most likely not. If your function calling already works, MCP will not change the outcome and adds setup. Consider it for new, tool-heavy projects, or when other applications or agents need to use the same tools.

What is the difference between stdio and HTTP transport in MCP?

With stdio, the client starts the server as a local subprocess on the same machine. With HTTP, the server runs separately, often in Docker on a remote VM, and clients connect over the network. Remote transport is what lets several applications share one server.

Written by

Dave Ebbelaar

Dave Ebbelaar

Senior AI Engineer

AI engineer and founder of Datalumina. Dave helps developers build production AI systems and turn technical skills into client work.