Learn how to create your first MCP server from scratch with this step-by-step beginner’s guide
package.json
file with default settings. You should see something like this in your folder now.
server.js
in your project folder:
server.js
in your project folder. The code might look complex, but don’t worry - we’ll break it down!ListToolsRequestSchema
handler tells AI assistants what your server can do. Our server has one tool called say_hello
that:
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.
/mcp
package.json
file and add this line:
"type": "module"
which allows us to use modern JavaScript import syntax.
package.json
includes "type": "module"
.My First Hello World Server
http://localhost:3000/mcp
“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! 👋 Served over Streamable HTTP.”
hello-world-dev
(for testing)hello-world-prod
(for production use)npm install
package.json
includes "type": "module"
node --version
server.js
filePORT=3000 node server.js
)http://localhost:3000/mcp