How to Build an MCP Server (Step-by-Step)
MCP (Model Context Protocol) servers let AI models interact with external tools and data. Building your own MCP server means you can expose any API, database, or service to AI assistants. This guide covers building servers in both TypeScript and Python.
What Is an MCP Server?
An MCP server exposes three types of capabilities to AI models:
- Tools: Functions the model can call (e.g., query a database, send an email)
- Resources: Data the model can read (e.g., files, configurations)
- Prompts: Reusable templates for common tasks
The server communicates via stdio (for local use) or HTTP with SSE (for remote deployments).
Option A: TypeScript MCP Server
Install the SDK
mkdir my-mcp-server
cd my-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk zod
Build the Server
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "my-tool-server",
version: "1.0.0"
});
// Define a tool
server.tool(
"get_weather",
"Get current weather for a city",
{ city: z.string().describe("City name") },
async ({ city }) => {
const response = await fetch(
`https://api.weather.example/v1?q=${city}`
);
const data = await response.json();
return {
content: [{ type: "text", text: JSON.stringify(data) }]
};
}
);
// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);
Option B: Python MCP Server
Install the SDK
pip install mcp[cli]
Build the Server
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("my-tool-server")
@mcp.tool()
def get_weather(city: str) -> str:
"""Get current weather for a city."""
import requests
resp = requests.get(f"https://api.weather.example/v1?q={city}")
return resp.json()
@mcp.resource("config://settings")
def get_settings() -> str:
"""Return server configuration."""
return {"version": "1.0", "max_results": 10}
if __name__ == "__main__":
mcp.run()
Testing Your Server
Use the MCP Inspector to test without connecting to an AI model:
npx @modelcontextprotocol/inspector
# Or test with the Python CLI
mcp dev my_server.py
The inspector lets you list tools, call them with test inputs, and see the responses.
Publishing Your Server
For npm (TypeScript):
npm publish
For PyPI (Python):
pip install build twine
python -m build
twine upload dist/*
After publishing, submit your server to the XLUXX directory for trust scoring:
pip install xluxx
curl -X POST https://api.xluxx.net/v1/tools/submit \
-H "Content-Type: application/json" \
-d '{"name": "my-mcp-server", "repo": "https://github.com/you/my-mcp-server"}'
XLUXX will analyze your server for security, documentation quality, and maintenance patterns, then assign a trust score visible to the community.
Server Architecture Tips
- Keep tools focused — one capability per tool
- Validate all inputs with schemas (Zod for TS, type hints for Python)
- Return structured data, not raw HTML
- Handle errors gracefully with descriptive messages
- Add rate limiting for external API calls
Use XLUXX Trust Layer to find reliable MCP tools: api.xluxx.net

Leave a Reply to Best MCP Servers for Database Operations (2026 Ranked) | XLUXX Cancel reply