MCP Hello World Server

MCP Hello World Server

A simple hello world MCP server with a greeting tool, deployable on Railway.

Category
访问服务器

README

MCP Hello World Server

A simple hello world MCP (Model Context Protocol) server built with Node.js and TypeScript. This project is configured for easy deployment on Railway.

Features

  • ✅ Simple hello world tool endpoint
  • ✅ TypeScript for type safety
  • ✅ Docker containerization
  • ✅ Railway deployment ready
  • ✅ MCP SDK integration

Prerequisites

  • Node.js 18.0.0 or higher
  • npm 9.0.0 or higher

Setup

  1. Install dependencies:

    npm install
    
  2. Build the project:

    npm run build
    

Development

Stdio Mode (Default)

Start the server in stdio mode:

npm run dev

or with the compiled build:

npm start

The server will start and listen on stdio for incoming MCP protocol messages.

HTTP Mode

Start the server in HTTP mode by setting the PORT environment variable:

PORT=8080 npm start

The server will start on the specified port and expose:

  • POST /mcp - MCP protocol endpoint
  • GET /health - Health check endpoint

Example health check:

curl http://localhost:8080/health
# Response: {"status":"ok"}

Building for Production

Build the TypeScript code:

npm run build

Run the compiled server:

npm start

Project Structure

.
├── 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

MCP Server Tools

hello

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."
    }
  ]
}

Deployment on Railway

Prerequisites

  • Railway account (sign up at https://railway.app)
  • Railway CLI installed locally (optional, but recommended)
  • GitHub repository (optional, for easier deployment)

How It Works

This MCP server can run in two modes:

  1. Stdio Mode - Default, for local development or direct integration
  2. 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 clients
  • GET /health - Health check endpoint for load balancers

Deploy Using GitHub

  1. Push your code to a GitHub repository
  2. Go to railway.app
  3. Click "Create New Project"
  4. Select "GitHub Repo"
  5. Authorize Railway and select your repository
  6. Railway will automatically detect the Node.js project and set PORT for you
  7. Click "Deploy"

Railway will automatically:

  • Set the PORT environment variable
  • Build your TypeScript code
  • Start the server in HTTP mode

Deploy Using Railway CLI

  1. Install Railway CLI: https://docs.railway.app/cli/quick-start
  2. Login to Railway:
    railway login
    
  3. Create a new project in the current directory:
    railway init
    
  4. Deploy:
    railway up
    

Using the Deployed Server

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);

Environment Variables

The server automatically detects its running environment:

  • With PORT set - Runs in HTTP mode (Railway, Render, etc.)
  • Without PORT - Runs in stdio mode (local development, Docker exec)

No additional configuration needed!

Testing

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

Local Testing with Claude Desktop

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.

Cloud Testing with Railway

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"}
    }
  }'

Troubleshooting

Port Already in Use

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"

Module Not Found Errors

Make sure all dependencies are installed:

npm install
npm run build

TypeScript Errors

Run type checking:

npm run typecheck

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选