The Model Context Protocol (MCP) is an open standard for connecting AI assistants to external data and tools. With it, a language model can read from your database, act inside an internal system or search documents, without a custom integration for every AI app. An MCP server exposes these tools in a standard format, and MCP-capable clients connect to it.
stdio or HTTP: where the server runs
MCP servers mainly use two transports. With stdio, the client launches the server as a process on the user's machine and they talk over standard input and output, which suits personal use. With Streamable HTTP, the server runs permanently on its own machine and clients connect over the network. If a whole team or several AI apps need the tool, choose HTTP, and that is where a server, a domain and SSL come in.
Example: a stock checker for an electronics store
Imagine sales staff at an electronics store in Tashkent asking an AI assistant, "Is this laptop in stock and how much is it?". The MCP server exposes one tool that takes a product SKU and reads stock and price from MySQL. The model decides when to call it based on its description. Such a server needs very few resources, so a small VPS or an existing server is plenty.
Preparing the environment and writing the server
The FastMCP class in the official Python SDK makes this simple. Create a folder and a virtual environment and install the packages.
sudo apt install python3-venv
sudo mkdir -p /opt/dokon-mcp && cd /opt/dokon-mcp
python3 -m venv venv
./venv/bin/pip install "mcp[cli]" pymysql
Create server.py. The function docstring becomes the tool description the model reads, so keep it clear. Parameter types matter too, because the SDK builds an argument schema from them.
from mcp.server.fastmcp import FastMCP
import os, pymysql
mcp = FastMCP("dokon", host="127.0.0.1", port=8000)
def db():
return pymysql.connect(host="localhost", user="mcp_reader",
password=os.environ["DB_PASS"], database="dokon")
@mcp.tool()
def mahsulot_qoldigi(sku: str) -> str:
"""Mahsulotning ombordagi qoldig'i va narxini qaytaradi."""
with db() as conn, conn.cursor() as cur:
cur.execute("SELECT nomi, qoldiq, narx FROM mahsulotlar WHERE sku=%s", (sku,))
row = cur.fetchone()
if not row:
return "Bunday mahsulot topilmadi"
return f"{row[0]}: {row[1]} dona, narxi {row[2]} so'm"
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Create a database user that can only read the needed table, so no request from the model can change data.
CREATE USER 'mcp_reader'@'localhost' IDENTIFIED BY 'UZUN_PAROL';
GRANT SELECT ON dokon.mahsulotlar TO 'mcp_reader'@'localhost';
Put the password in /opt/dokon-mcp/.env as DB_PASS=... and make the file readable only by the service user.
Keeping it running with systemd
Create a system user with sudo useradd -r -s /usr/sbin/nologin mcp, save the unit below as /etc/systemd/system/dokon-mcp.service and enable it with sudo systemctl enable --now dokon-mcp.
[Unit]
Description=Dokon MCP server
After=network.target mysql.service
[Service]
User=mcp
WorkingDirectory=/opt/dokon-mcp
EnvironmentFile=/opt/dokon-mcp/.env
ExecStart=/opt/dokon-mcp/venv/bin/python server.py
Restart=always
[Install]
WantedBy=multi-user.target
Nginx, SSL and token protection
FastMCP listens on a local address and Nginx exposes it. First create an A record for mcp.example.uz pointing to the VPS, for example in the sayt.uz cabinet, and get a certificate with Certbot. MCP tools reach internal data, so never leave the endpoint open. The simplest protection is a Bearer token check in Nginx; for larger projects look at the OAuth-based authorization described in the MCP specification.
location /mcp {
if ($http_authorization != "Bearer UZUN_MAXFIY_TOKEN") {
return 401;
}
proxy_pass http://127.0.0.1:8000/mcp;
proxy_http_version 1.1;
proxy_buffering off;
proxy_read_timeout 300s;
}
Buffering is off because responses may arrive as an SSE stream. The Host header is deliberately not overridden: newer SDK versions may validate the host name of requests to a local server, so if you see such an error, check the allowed hosts setting in the SDK docs.
Testing and connecting a client
Send an initialize request, the first step of the MCP protocol; a correct reply returns the server name and capabilities.
curl -X POST https://mcp.example.uz/mcp \
-H "Authorization: Bearer UZUN_MAXFIY_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
For a visual check, run the official MCP Inspector with npx @modelcontextprotocol/inspector and enter the server URL and token. Then add the URL to any AI client that supports remote MCP servers, and follow the logs with journalctl -u dokon-mcp -f to see which tools are called and what errors appear.