Learn how to create your first MCP server from scratch with this step-by-step beginner’s guide
Welcome to your first MCP (Model Context Protocol) server! This tutorial will walk you through creating a simple “Hello World” MCP server from scratch. Don’t worry if you’ve never built an MCP server before - we’ll explain everything step by step.
By the end of this tutorial, you’ll have:
Before we start, make sure you have:
New to Node.js? Download it from nodejs.org. The installer will also include npm.
First, let’s create a new folder for our MCP server and set up the basic project structure.
This creates a package.json
file with default settings. You should see something like this in your folder now.
Now we need to install the MCP SDK (Software Development Kit) that provides all the tools we need to build our server.
The MCP SDK is the official library that handles all the complex protocol details for us, so we can focus on building our server’s functionality.
Now for the exciting part - let’s create our actual MCP server! Create a new file called server.js
in your project folder:
Make sure to save this file as server.js
in your project folder. The code might look complex, but don’t worry - we’ll break it down!
Let’s break down what each part of your server does:
This creates your MCP server with a name and tells it that it can provide “tools” to AI assistants.
The ListToolsRequestSchema
handler tells AI assistants what your server can do. Our server has one tool called say_hello
that:
The CallToolRequestSchema
handler is what actually runs when an AI assistant uses your tool. It takes the person’s name and message, then returns a friendly greeting.
We need to tell Node.js that our project uses ES modules. Open your package.json
file and add this line:
The important addition is "type": "module"
which allows us to use modern JavaScript import syntax.
Let’s make sure your server works! In your terminal, run:
You should see:
Great! Your server is running. Press Ctrl+C
to stop it for now.
If you see any errors, double-check that you’ve copied the code exactly and that your package.json
includes "type": "module"
.
Now let’s connect your server to Pylee so you can use it with AI assistants!
Start your server (if it’s not already running):
Open Pylee in your web browser and go to the Server Setup page
Configure your server:
My First Hello World Server
node
server.js
my-first-mcp-server
folderTo find your full path, run pwd
(on Mac/Linux) or cd
(on Windows) in your project folder and copy the result.
Test the connection using Pylee’s test feature
Save your configuration
Once connected, you can now use your MCP server with any AI assistant connected to Pylee! Try asking:
“Use the say_hello tool to greet John with a custom message ‘Good morning’”
The AI will use your MCP server and you should get a response like:
“Good morning, John! 👋 This is your first MCP server working perfectly!”
Congratulations! You’ve successfully created and deployed your first MCP server. Here are some ideas to expand your server:
Try adding a new tool to your server. For example, a tool that generates random jokes:
MCP servers can also provide resources - think of them as files or data that AI assistants can read.
“Module not found” errors
npm install
package.json
includes "type": "module"
“Server won’t start” errors
node --version
server.js
file“Connection failed” in Pylee
npm start
)node
and arguments is server.js
If you’re stuck, here are some resources:
You’ve just built your first MCP server! Here’s what you accomplished:
✅ Created a new MCP server from scratch
✅ Added a custom tool that AI assistants can use
✅ Connected it to Pylee
✅ Tested it with an AI assistant
Your server might be simple, but it demonstrates all the core concepts of MCP servers. Every complex MCP server starts with these same basic building blocks.
The most important thing to remember is that MCP servers are just programs that follow a specific protocol to communicate with AI assistants. Once you understand this basic pattern, you can build servers that connect to databases, APIs, file systems, or any other system you can imagine!
Ready to build something more complex? Check out our other MCP server guides to learn advanced techniques and best practices.
Learn how to create your first MCP server from scratch with this step-by-step beginner’s guide
Welcome to your first MCP (Model Context Protocol) server! This tutorial will walk you through creating a simple “Hello World” MCP server from scratch. Don’t worry if you’ve never built an MCP server before - we’ll explain everything step by step.
By the end of this tutorial, you’ll have:
Before we start, make sure you have:
New to Node.js? Download it from nodejs.org. The installer will also include npm.
First, let’s create a new folder for our MCP server and set up the basic project structure.
This creates a package.json
file with default settings. You should see something like this in your folder now.
Now we need to install the MCP SDK (Software Development Kit) that provides all the tools we need to build our server.
The MCP SDK is the official library that handles all the complex protocol details for us, so we can focus on building our server’s functionality.
Now for the exciting part - let’s create our actual MCP server! Create a new file called server.js
in your project folder:
Make sure to save this file as server.js
in your project folder. The code might look complex, but don’t worry - we’ll break it down!
Let’s break down what each part of your server does:
This creates your MCP server with a name and tells it that it can provide “tools” to AI assistants.
The ListToolsRequestSchema
handler tells AI assistants what your server can do. Our server has one tool called say_hello
that:
The CallToolRequestSchema
handler is what actually runs when an AI assistant uses your tool. It takes the person’s name and message, then returns a friendly greeting.
We need to tell Node.js that our project uses ES modules. Open your package.json
file and add this line:
The important addition is "type": "module"
which allows us to use modern JavaScript import syntax.
Let’s make sure your server works! In your terminal, run:
You should see:
Great! Your server is running. Press Ctrl+C
to stop it for now.
If you see any errors, double-check that you’ve copied the code exactly and that your package.json
includes "type": "module"
.
Now let’s connect your server to Pylee so you can use it with AI assistants!
Start your server (if it’s not already running):
Open Pylee in your web browser and go to the Server Setup page
Configure your server:
My First Hello World Server
node
server.js
my-first-mcp-server
folderTo find your full path, run pwd
(on Mac/Linux) or cd
(on Windows) in your project folder and copy the result.
Test the connection using Pylee’s test feature
Save your configuration
Once connected, you can now use your MCP server with any AI assistant connected to Pylee! Try asking:
“Use the say_hello tool to greet John with a custom message ‘Good morning’”
The AI will use your MCP server and you should get a response like:
“Good morning, John! 👋 This is your first MCP server working perfectly!”
Congratulations! You’ve successfully created and deployed your first MCP server. Here are some ideas to expand your server:
Try adding a new tool to your server. For example, a tool that generates random jokes:
MCP servers can also provide resources - think of them as files or data that AI assistants can read.
“Module not found” errors
npm install
package.json
includes "type": "module"
“Server won’t start” errors
node --version
server.js
file“Connection failed” in Pylee
npm start
)node
and arguments is server.js
If you’re stuck, here are some resources:
You’ve just built your first MCP server! Here’s what you accomplished:
✅ Created a new MCP server from scratch
✅ Added a custom tool that AI assistants can use
✅ Connected it to Pylee
✅ Tested it with an AI assistant
Your server might be simple, but it demonstrates all the core concepts of MCP servers. Every complex MCP server starts with these same basic building blocks.
The most important thing to remember is that MCP servers are just programs that follow a specific protocol to communicate with AI assistants. Once you understand this basic pattern, you can build servers that connect to databases, APIs, file systems, or any other system you can imagine!
Ready to build something more complex? Check out our other MCP server guides to learn advanced techniques and best practices.