Set Up Our MCP Project

Enough theory. Let’s start building! 🚀

In the previous part, we learned what MCP is, why it is useful, and how MCP clients and servers communicate.

Now it’s time to build our first MCP server.

By the end of this chapter, we will have a running MCP server.

We won’t add any tools yet. We will connect Jan in the next chapter, and then build tools after that.

Our goal here is simple:

Create a Python project

Install MCP SDK

Create an MCP server

Run the server

Verify that it starts

Let’s get started.


🧱 3.1 What Are We Building?

Before writing any code, let’s understand what we are going to build.

We are going to create a small Python application that acts as an MCP server.

For now, the server won’t do anything useful. It won’t have a calculator, database, file reader, or any other tool.

That’s intentional.

We first want to make sure that we can:

  1. Create an MCP project.
  2. Install the MCP SDK.
  3. Create an MCP server.
  4. Start the server successfully.

Later, we will add tools to this server.

Our project will eventually look like this:

MCP Client

MCP Server

add()

subtract()

multiply()

divide()

But for this chapter, we’ll start with just:

MCP Client

MCP Server

Once this works, we can build on top of it.


🐍 3.2 Why Python?

For this tutorial, we will use Python to build our MCP server.

MCP is not tied to a particular programming language. You can build MCP servers using different languages and SDKs.

We are choosing Python because it is:

  • Easy to learn
  • Widely used in AI and automation
  • Well suited for building small services
  • Easy to set up
  • A good fit for our MCP examples

So our stack will be:

Python

MCP Python SDK

MCP Server

If you’re completely new to Python, don’t worry. You only need a basic understanding of Python to follow this tutorial.


📥 3.3 Install Python

Before creating our MCP project, we need Python installed on our machine.

We recommend using a recent supported Python 3 version for this tutorial.

You can check whether Python is already installed by opening a terminal.

On Windows:

Terminal window
python --version

On macOS or Linux:

Terminal window
python3 --version

You should see something similar to:

Python 3.x.x

For example:

Python 3.12.8

If Python is not installed, install it from the official Python website.

Download Python

After installation, run the version command again:

Terminal window
python --version

or:

Terminal window
python3 --version

Once you can see the Python version, we are ready.


📁 3.4 Create the Project

Let’s create a directory for our MCP project.

Open your terminal and run:

Terminal window
mkdir calculator-mcp
cd calculator-mcp

We now have an empty project directory:

calculator-mcp/

We will gradually add our MCP server code to this directory.

For now, keep it simple.


📦 3.5 Create a Virtual Environment

Before installing any Python packages, let’s create a virtual environment.

A virtual environment gives our project its own isolated Python environment.

Why do we need this?

Imagine you have two Python projects:

Project A
MCP SDK version A
Project B
MCP SDK version B

If both projects use the same global Python environment, their dependencies can interfere with each other.

A virtual environment avoids this problem.

Our project will have its own environment:

calculator-mcp/
├── .venv/
└── ...

⚙️ Create the virtual environment

On Windows:

Terminal window
python -m venv .venv

On macOS/Linux:

Terminal window
python3 -m venv .venv

This creates a directory called .venv.


▶️ Activate the Virtual Environment

On Windows PowerShell:

Terminal window
.venv\Scripts\Activate.ps1

On Windows Command Prompt:

Terminal window
.venv\Scripts\activate

On macOS/Linux:

Terminal window
source .venv/bin/activate

After activation, your terminal will usually show something like:

(.venv)

For example:

(.venv) C:\projects\calculator-mcp>

That tells us that our virtual environment is active.


📚 3.6 Install the MCP SDK

Now we need the Python SDK that allows us to build an MCP server.

We’ll install it using pip.

Run:

Terminal window
pip install mcp

On some systems, you may need:

Terminal window
python -m pip install mcp

After installation, the MCP SDK is available to our Python project.

We can verify the installation with:

Terminal window
pip show mcp

You should see information about the installed MCP package.

Our project now has:

Python

Virtual Environment

MCP Python SDK

We’re ready to write some code. 🚀


🖥️ 3.7 Create Our First MCP Server

Now let’s create our first MCP server.

Create a file called:

server.py

Our project now looks like:

calculator-mcp/
├── .venv/
└── server.py

Open server.py.

We’ll start with a very small MCP server.

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Calculator Server")

That’s it.

Our MCP server has been created.

Let’s understand these two lines.

📦 Import FastMCP

from mcp.server.fastmcp import FastMCP

FastMCP is provided by the MCP Python SDK.

It gives us a convenient way to create an MCP server without having to deal with all the lower-level protocol details ourselves.

🏗️ Create the server

mcp = FastMCP("Calculator Server")

Here we create an MCP server instance.

We give our server a name:

Calculator Server

Later, we’ll add calculator tools to this server.

For now, the server doesn’t have any tools.

That’s okay.

We are building it step by step.


▶️ 3.8 Run the MCP Server

Our server needs an entry point so that Python can start it.

Update server.py:

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Calculator Server")
if __name__ == "__main__":
mcp.run()

Now we have a complete minimal MCP server.

The complete file is:

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Calculator Server")
if __name__ == "__main__":
mcp.run()

Let’s run it.

From the project directory:

Terminal window
python server.py

On systems where Python is invoked using python3:

Terminal window
python3 server.py

Our server should start.

At this point, you may not see a big message saying:

MCP Server Started!

And that’s okay.

Depending on the MCP SDK version and transport being used, the terminal output may be minimal.

The important thing is that the process stays running instead of immediately exiting with an error.


✅ 3.9 Verify That the Server Starts

How do we know our server actually started?

The simplest first check is the terminal.

Run:

Terminal window
python server.py

If the command remains running without an exception, our server has started.

You should not see errors such as:

ModuleNotFoundError

or:

ImportError

or another startup exception.

If the process is still running, congratulations! 🎉

We have created our first MCP server.

Our current architecture is:

MCP Server

Calculator Server

No tools yet

There is one important thing to understand.

Starting the server is not the same as using the server.

Right now, we have only created and started the server.

We haven’t connected an MCP client yet.

We also haven’t created any tools.

That’s exactly what we want at this stage.


🧾 3.10 What We Have Built

Let’s quickly review what we accomplished.

We:

  • Installed Python
  • Created our project
  • Created a virtual environment
  • Installed the MCP Python SDK
  • Created an MCP server
  • Started the server
  • Verified that it runs

Our project is currently:

calculator-mcp/
├── .venv/
└── server.py

And our server code is:

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Calculator Server")
if __name__ == "__main__":
mcp.run()

We now have the foundation for our MCP application.

But our server is still pretty boring. 😄

It doesn’t have anything for an MCP client to actually use.

That’s about to change.

In the next chapter, we’ll set up Jan as our MCP host/client, connect it to this server, and verify that the two can communicate.

Then we’ll build our first real MCP tool:

add(10, 20)

And that’s where things start getting interesting. 🚀