How to Set Up an MCP Server (Production-Ready)
This guide shows the minimum production-ready MCP server setup: predictable endpoints, tool schema, auth, and health checks. It’s written in a DigitalOcean-style, step-by-step format.
What you’ll build
- A working MCP server endpoint
- A simple tool schema
- API key protection
- A health check endpoint
Prerequisites
- Node.js 18+ (or Python 3.10+)
- A public HTTP server
- 10 minutes
Step 1: Define your tool schema
Your MCP server must expose a tools list or tool schema so clients know what actions are available.
Example tool schema:
{
"name": "healthcheck",
"description": "Check MCP server health",
"input_schema": {
"type": "object",
"properties": {}
}
}
Step 2: Create the MCP endpoint
Expose an HTTP endpoint (recommended: POST /api/v1/mcp) that accepts JSON:
Node.js (Express example)
import express from "express";
const app = express();
app.use(express.json());
app.post("/api/v1/mcp", async (req, res) => {
const { tool, args } = req.body;
if (tool === "healthcheck") {
return res.json({ ok: true });
}
return res.status(404).json({ error: "Unknown tool" });
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`MCP server running on ${port}`));
Step 3: Add API key protection
Always gate MCP calls with an API key or bearer token:
app.post("/api/v1/mcp", (req, res, next) => {
const token = req.headers.authorization?.replace("Bearer ", "");
if (token !== process.env.MCP_API_KEY) {
return res.status(401).json({ error: "Unauthorized" });
}
next();
});
Step 4: Add a health endpoint
Health checks are required for production readiness:
app.get("/health", (req, res) => res.json({ ok: true }));
Step 5: Run locally
export MCP_API_KEY="dev-key"
npm install
npm start
Test:
curl -X POST http://localhost:3000/api/v1/mcp \
-H "Authorization: Bearer dev-key" \
-H "Content-Type: application/json" \
-d '{"tool":"healthcheck","args":{}}'
Expected:
{ "ok": true }
Step 6: Deploy (fast test path)
If you want the fastest hosted test path, deploy on Yamify and test it live:
- Deploy your repo using Deploy from GitHub
- Ensure your server listens on
PORT - Use the generated HTTPS URL to run the same curl test
Full hosted MCP guide: Host your MCP server on Yamify
Common mistakes
- Not listening on
PORT - Missing
Authorizationheader - Returning non-JSON responses
- No
/healthendpoint
Next step
Once your MCP is live, you can connect it to OpenClaw, Claude, or any MCP client.