A simple hello world MCP (Model Context Protocol) server built with Node.js and TypeScript. This project is configured for easy deployment on Railway.
- ✅ Simple hello world tool endpoint
- ✅ TypeScript for type safety
- ✅ Docker containerization
- ✅ Railway deployment ready
- ✅ MCP SDK integration
- Node.js 18.0.0 or higher
- npm 9.0.0 or higher
-
Install dependencies:
npm install
-
Build the project:
npm run build
Start the server in stdio mode:
npm run devor with the compiled build:
npm startThe server will start and listen on stdio for incoming MCP protocol messages.
Start the server in HTTP mode by setting the PORT environment variable:
PORT=8080 npm startThe server will start on the specified port and expose:
POST /mcp- MCP protocol endpointGET /health- Health check endpoint
Example health check:
curl http://localhost:8080/health
# Response: {"status":"ok"}Build the TypeScript code:
npm run buildRun the compiled server:
npm start.
├── src/
│ └── index.ts # Main server implementation
├── dist/ # Compiled JavaScript (generated)
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
├── Dockerfile # Docker configuration
├── railway.toml # Railway deployment config
└── README.md # This file
A simple tool that returns a personalized greeting.
Parameters:
name(string, optional): The name to greet. Defaults to "World"
Example:
{
"name": "hello",
"arguments": {
"name": "Alice"
}
}Response:
{
"content": [
{
"type": "text",
"text": "Hello, Alice! Welcome to the MCP server."
}
]
}- Railway account (sign up at https://railway.app)
- Railway CLI installed locally (optional, but recommended)
- GitHub repository (optional, for easier deployment)
This MCP server can run in two modes:
- Stdio Mode - Default, for local development or direct integration
- HTTP Mode - For cloud deployment (Railway, Render, etc.)
When a PORT environment variable is set, the server automatically switches to HTTP mode and exposes:
POST /mcp- MCP protocol endpoint for clientsGET /health- Health check endpoint for load balancers
- Push your code to a GitHub repository
- Go to railway.app
- Click "Create New Project"
- Select "GitHub Repo"
- Authorize Railway and select your repository
- Railway will automatically detect the Node.js project and set
PORTfor you - Click "Deploy"
Railway will automatically:
- Set the
PORTenvironment variable - Build your TypeScript code
- Start the server in HTTP mode
- Install Railway CLI: https://docs.railway.app/cli/quick-start
- Login to Railway:
railway login
- Create a new project in the current directory:
railway init
- Deploy:
railway up
Once deployed to Railway, you'll get a public URL like https://your-service.railway.app.
To use it with an MCP client:
// Example: POST request to the MCP endpoint
const response = await fetch('https://your-service.railway.app/mcp', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'my-client', version: '1.0.0' }
}
})
});
const data = await response.json();
console.log(data);The server automatically detects its running environment:
- With
PORTset - Runs in HTTP mode (Railway, Render, etc.) - Without
PORT- Runs in stdio mode (local development, Docker exec)
No additional configuration needed!
To test the MCP server, you'll need an MCP client. The server communicates via:
- Stdio - Direct pipe communication for local integration
- HTTP Streamable - HTTP endpoint for cloud deployment
Configure Claude Desktop to use the local server in stdio mode:
Create or edit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"hello-world": {
"command": "node",
"args": ["C:\\path\\to\\mcp\\dist\\index.js"]
}
}
}Then restart Claude Desktop and the hello tool will be available.
Once deployed to Railway, you can make HTTP requests to your server:
# Health check
curl https://your-service.railway.app/health
# MCP protocol request
curl -X POST https://your-service.railway.app/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "hello",
"arguments": {"name": "Alice"}
}
}'If you see an error about the port being in use, the server may still be running. Kill it with:
# On Windows
taskkill /F /IM node.exe
# On macOS/Linux
pkill -f "node"Make sure all dependencies are installed:
npm install
npm run buildRun type checking:
npm run typecheckMIT