Railway MCP Server

Railway MCP Server

MCP server with Streamable HTTP transport, deployed on Railway, offering tools like weather, BMI calculator, greetings, and question generation.

Category
访问服务器

README

MCP Server with HTTP Streaming - Railway Deployment

This project demonstrates deploying a Model Context Protocol (MCP) server with HTTP streaming support to Railway. The server uses the modern Streamable HTTP transport which provides efficient bidirectional communication over a single HTTP endpoint.

Features

  • Streamable HTTP Transport: Modern MCP transport with full bidirectional streaming
  • HTTP Streaming: Supports real-time communication and server-sent events
  • Multiple Tools: Weather API, BMI calculator, and more
  • Resources & Prompts: Dynamic greetings and question generation
  • Railway Optimized: Configured for seamless Railway deployment

Tools Available

  1. get_weather(city) - Get simulated weather data for any city
  2. calculate_bmi(weight_kg, height_m) - Calculate BMI with category classification
  3. greeting://{{name}} - Personalized greeting resource
  4. ask_question(topic, style) - Generate styled questions about topics

Local Development

Prerequisites

  • Python 3.8+
  • pip or uv package manager

Setup

# Clone this repository
git clone <your-repo-url>
cd mcp-railway-server

# Install dependencies
pip install -r requirements.txt
# OR with uv
uv pip install -r requirements.txt

# Run locally
python main.py

The server will start on http://localhost:8000/mcp with Streamable HTTP transport.

Testing the Server

You can test the server using the MCP Inspector or any MCP client that supports Streamable HTTP:

# Install MCP CLI tools (if available)
uv tool install mcp

# Test with MCP Inspector
mcp inspect http://localhost:8000/mcp

Railway Deployment

Method 1: Deploy from GitHub (Recommended)

  1. Fork this repository to your GitHub account

  2. Create a new Railway project:

    • Go to Railway
    • Click "New Project"
    • Select "Deploy from GitHub repo"
    • Choose your forked repository
  3. Configure deployment:

    • Railway will automatically detect the railway.json configuration
    • The app will build using Nixpacks
    • No additional environment variables needed
  4. Generate domain:

    • Go to your service settings
    • Navigate to "Networking" tab
    • Click "Generate Domain"
    • Your MCP server will be available at: https://your-app-name.railway.app/mcp

Method 2: Deploy with Railway CLI

# Install Railway CLI
npm install -g @railway/cli

# Login to Railway
railway login

# Initialize project
railway init

# Deploy
railway up

Method 3: Deploy with Docker

If you prefer using Docker:

# Build Docker image
docker build -t mcp-server .

# Run locally (test)
docker run -p 8000:8000 -e PORT=8000 mcp-server

# Deploy to Railway (Railway will handle this automatically if Dockerfile is present)

Configuration

Environment Variables

Railway automatically sets the PORT environment variable. No additional configuration is required for basic deployment.

Optional environment variables you can add:

  • MCP_SERVER_NAME: Custom server name (default: "Railway MCP Server")
  • DEBUG: Set to "true" for debug logging

MCP Client Configuration

To connect an MCP client to your deployed server, use this configuration:

{
  "mcpServers": {
    "railway-mcp": {
      "type": "streamable-http",
      "url": "https://your-app-name.railway.app/mcp"
    }
  }
}

Architecture

This server uses:

  • FastMCP: High-level MCP server framework
  • Streamable HTTP Transport: Modern bidirectional communication protocol
  • Railway Platform: Serverless deployment with automatic scaling

Key Benefits of Streamable HTTP:

  • Single endpoint for all communication (/mcp)
  • Automatic connection upgrades to SSE when needed
  • Better performance than traditional HTTP+SSE approach
  • Full bidirectional communication support

Troubleshooting

Common Issues

  1. Port binding error locally:

    # Make sure port 8000 is available
    lsof -i :8000
    
  2. Railway deployment fails:

    • Check that requirements.txt includes mcp>=1.8.0
    • Ensure railway.json has correct start command
    • Verify Railway has access to your GitHub repository
  3. MCP client connection issues:

    • Ensure client supports Streamable HTTP transport
    • Use correct URL format: https://your-app.railway.app/mcp
    • Check that Railway domain is generated and accessible

Logs and Debugging

View Railway logs:

railway logs

Enable debug mode by setting environment variable:

railway variables set DEBUG=true

Next Steps

  1. Add Authentication: Implement OAuth 2.1 for secured endpoints
  2. Add Real APIs: Replace simulated data with real weather/data APIs
  3. Database Integration: Add persistent storage with Railway PostgreSQL
  4. Monitoring: Set up logging and monitoring for production use

Resources

License

MIT License - see LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

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

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

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

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

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

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

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

官方
精选
本地
TypeScript
VeyraX

VeyraX

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

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

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

官方
精选
Exa MCP Server

Exa MCP Server

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

官方
精选