FastMCP Template
A FastMCP server template that provides a greet tool returning personalized greetings. It supports local, Docker, and Railway cloud deployments.
README
FastMCP Template
This is a FastMCP template project that works seamlessly in local, Docker, and cloud environments. Get started instantly by deploying to Railway with one click!
🚀 Quick Deploy to Railway (Recommended)
The fastest way to get your FastMCP server running in the cloud:
One-Click Deploy
Connect Remote Client to Railway
Once deployed, use this client to connect from anywhere:
Simple Method (Direct URL):
# my_client_remote.py
import asyncio
from fastmcp import Client
# Replace with your Railway URL
RAILWAY_URL = "https://your-railway-url.up.railway.app/mcp"
client = Client(RAILWAY_URL)
async def call_tool(name: str):
async with client:
result = await client.call_tool("greet", {"name": name})
print(result)
if __name__ == "__main__":
asyncio.run(call_tool("Ford"))
Run it:
uv run my_client_remote.py
With Environment Variable (More Flexible):
export RAILWAY_URL="https://your-railway-url.up.railway.app/mcp"
uv run my_client_remote.py
Project Structure
my_server.py- FastMCP server with agreettool (works locally, Docker, and Railway)my_client.py- Local/Docker client that connects via HTTPmy_client_remote.py- Remote client for Railway connectionsDockerfile- Container configuration for all cloud deployments
Local Development
Perfect for testing and development on your machine.
Terminal 1 - Start the server:
uv run fastmcp run my_server.py:mcp --transport http --port 8080
Terminal 2 - Run the client:
export PORT=8080
export HOST_URL="http://localhost"
uv run my_client.py
Output: Hello, Ford!
Docker Deployment
Deploy locally with Docker or on any container platform.
Build the Docker image:
docker build -t fastmcp-server .
Run the Docker container:
docker run -p 8080:8080 fastmcp-server
Connect the client:
export PORT=8080
export HOST_URL="http://localhost"
uv run my_client.py
Environment Variables
Local & Docker Deployments
HOST_URL- The server host URL (default:http://localhost)PORT- The server port (default:8080)
Examples:
# Custom port
export PORT=3000
uv run fastmcp run my_server.py:mcp --transport http --port 3000
export PORT=3000
uv run my_client.py
# Custom host
export HOST_URL="http://192.168.1.100"
export PORT=8080
uv run my_client.py
Railway Deployment
RAILWAY_URL- Full Railway endpoint URL (e.g.,https://your-url.up.railway.app/mcp)- Configure additional variables in Railway dashboard → Variables tab
Architecture
Why This Approach?
This template uses HTTP transport for consistency across all deployment scenarios:
- Consistency - Same protocol everywhere
- Simplicity - Just two files for any scenario
- Scalability - HTTP enables cloud deployment
- Flexibility - Easy to modify URLs/ports per environment
Deployment Options
┌──────────────────────────────────────────────┐
│ 🚀 RECOMMENDED: Railway Cloud │
│ • One-click deployment │
│ • Automatic HTTPS & CDN │
│ • Global access │
│ URL: https://your-url.up.railway.app/mcp │
└──────────────────────────────────────────────┘
┌──────────────────────────────────────────────┐
│ 🐳 Docker (Local or Any Cloud) │
│ • Full control │
│ • Works anywhere with Docker │
│ URL: http://localhost:8080/mcp │
└──────────────────────────────────────────────┘
┌──────────────────────────────────────────────┐
│ 🏠 Local Development │
│ • Perfect for testing │
│ • Two terminal setup │
│ URL: http://localhost:8080/mcp │
└──────────────────────────────────────────────┘
Configuration Details
Server (my_server.py)
The server uses the FastMCP framework with a simple greet tool:
@mcp.tool
def greet(name: str) -> str:
return f"Hello, {name}!"
When run locally with:
uv run fastmcp run my_server.py:mcp --transport http --port 8080
When run in Docker via Dockerfile:
CMD ["sh", "-c", "uv run fastmcp run my_server.py:mcp --transport http --host 0.0.0.0 --port $PORT"]
Client (my_client.py)
Local/Docker client connects with environment variables:
PORT = os.getenv("PORT", "8080")
HOST_URL = os.getenv("HOST_URL", "http://localhost")
client = Client(f"{HOST_URL}:{PORT}/mcp")
Remote Client (my_client_remote.py)
Railway/remote client connects with direct URL or environment variable:
RAILWAY_URL = os.getenv("RAILWAY_URL", "https://your-url.up.railway.app/mcp")
client = Client(RAILWAY_URL)
Troubleshooting
Railway Connection Issues
Server not responding:
- Check Railway deployment logs in dashboard
- Verify URL:
https://your-url.up.railway.app/mcp - Test with curl:
curl https://your-railway-url.up.railway.app/mcp
Finding your Railway URL:
- Go to Railway project dashboard
- Select the deployment
- Go to "Settings"
- Copy the domain URL
- Append
/mcpfor the endpoint
Custom Domain on Railway:
- Go to Service Settings → Custom Domain
- Add your domain (e.g.,
mcp.example.com)
Local Development Issues
Connection failed:
- Check if server is running:
ps aux | grep fastmcp - Verify port accessible:
curl http://localhost:8080/mcp - Ensure PORT and HOST_URL environment variables are set
Port already in use:
# Use different port
export PORT=3000
uv run fastmcp run my_server.py:mcp --transport http --port 3000
export PORT=3000
uv run my_client.py
Docker Issues
- Check if container is running:
docker ps - View logs:
docker logs <container-id> - Verify port mapping:
docker run -p 8080:8080 ... - Test connectivity:
curl http://localhost:8080/mcp
Summary
This FastMCP template provides multiple deployment options:
- ✅ Railway - Fastest cloud deployment (recommended)
- ✅ Docker - Full control, works anywhere
- ✅ Local - Perfect for development and testing
- ✅ Same codebase - No changes needed for different deployments
- ✅ Just change URLs - Environment variables handle all variations
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。