Set Up Our MCP Project
Table of Contents
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:
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:
- Create an MCP project.
- Install the MCP SDK.
- Create an MCP server.
- Start the server successfully.
Later, we will add tools to this server.
Our project will eventually look like this:
But for this chapter, weโll start with just:
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:
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:
python --versionOn macOS or Linux:
python3 --versionYou should see something similar to:
Python 3.x.xFor example:
Python 3.12.8If Python is not installed, install it from the official Python website.
After installation, run the version command again:
python --versionor:
python3 --versionOnce 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:
mkdir calculator-mcpcd calculator-mcpWe 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 BIf 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:
python -m venv .venvOn macOS/Linux:
python3 -m venv .venvThis creates a directory called .venv.
โถ๏ธ Activate the Virtual Environment
On Windows PowerShell:
.venv\Scripts\Activate.ps1On Windows Command Prompt:
.venv\Scripts\activateOn macOS/Linux:
source .venv/bin/activateAfter 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:
pip install mcpOn some systems, you may need:
python -m pip install mcpAfter installation, the MCP SDK is available to our Python project.
We can verify the installation with:
pip show mcpYou should see information about the installed MCP package.
Our project now has:
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.pyOur project now looks like:
calculator-mcp/โโโโ .venv/โโโโ server.pyOpen 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 FastMCPFastMCP 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 ServerLater, 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:
python server.pyOn systems where Python is invoked using python3:
python3 server.pyOur 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:
python server.pyIf the command remains running without an exception, our server has started.
You should not see errors such as:
ModuleNotFoundErroror:
ImportErroror another startup exception.
If the process is still running, congratulations! ๐
We have created our first MCP server.
Our current architecture is:
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.pyAnd 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. ๐