hello world mcp server
A demonstration server that implements the Model Context Protocol (MCP) SDK, providing tools and endpoints for server-sent events and message handling.
A demonstration server that implements the Model Context Protocol (MCP) SDK, providing tools and endpoints for server-sent events and message handling.
Welcome to the Hello World MCP Server! This project demonstrates how to set up a server using the Model Context Protocol (MCP) SDK. It includes tools, prompts, and endpoints for handling server-sent events (SSE) and messages.
This project is part of the blog post: Building a TypeScript MCP Server: A Guide for Integrating Existing Services. Visit the blog to learn more about the concepts and implementation details behind this project.
.env
files for easy configuration.Before you begin, ensure you have the following installed:
Follow these steps to set up and run the project:
If you haven't already, clone the repository to your local machine:
git clone https://github.com/your-username/hello-world-mcp-server.git
cd hello-world-mcp-server
Install the required dependencies using npm or yarn:
npm install
or
yarn install
The project uses a .env
file to configure the server's port. A sample .env.example
file is provided.
.env.example
file to .env
:cp .env.example .env
.env
file and update the PORT
variable if needed. The default is 4000
.PORT=4000
Compile the TypeScript code into JavaScript:
npm run build
This will generate the compiled files in the dist
directory.
Start the server in production mode:
npm start
Alternatively, for development mode with live reloading, use:
npm run dev
The MCP Inspector is a tool to test and inspect your MCP server. You can use it to verify that your tools and prompts are registered correctly.
Run the following command to inspect your server:
npx @modelcontextprotocol/inspector ./dist/server.js
This will open an interactive interface where you can test the tools and prompts registered in your server like below.
Here’s an overview of the project structure:
hello-world-mcp-server/
├── src/
│ ├── server.ts # Main server entry point
│ ├── modules/
│ │ ├── tools.ts # Registers MCP tools
│ │ ├── prompts.ts # Registers MCP prompts
│ │ └── transports.ts # Handles SSE and message endpoints
├── .env # Environment variables
├── .env.example # Example environment variables
├── package.json # Project metadata and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
PORT
variable in the .env
file.Use the following command to debug the server:
npm run dev
This will start the server with live reloading and detailed logs.
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.