June 6, 2025 / Nirav Shah
If you’re new to the world of AI and data integration, you might have heard about MCP but aren’t quite sure what it is or why it matters. This blog will help you understand the basics of MCP and guide you step-by-step through running your very first MCP server on Amazon Linux.
Whether you’re a student, a beginner developer, or simply curious about AI-powered applications, this guide is for you.
MCP stands for Model Context Protocol. Think of it as a simple way for AI applications to ask for information from your databases or systems, so the AI can give smarter and more relevant answers.
For example, if you have a database of users, an AI assistant could ask MCP:
“Show me the user details,”
and MCP would fetch and return that data in a structured format.
MCP acts like a bridge between your data and AI tools.
Launch an Amazon Linux 2 instance on AWS EC2.
Connect to it using SSH.
Update your system:
sudo yum update -y
Amazon Linux 2 doesn’t come with Python 3 by default, so install it:
sudo yum install python3 -y
Install MySQL server:
sudo yum install mysql-server -y sudo systemctl start mysqld sudo systemctl enable mysqld
Secure your MySQL installation:
sudo mysql_secure_installation
Log in to MySQL as root:
mysql -u root -p
Inside MySQL, create a database and a user:
CREATE DATABASE mcp_demo; CREATE USER 'mcpuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere'; GRANT ALL PRIVILEGES ON mcp_demo.* TO 'mcpuser'@'localhost'; FLUSH PRIVILEGES;
Create a simple table:
USE mcp_demo; CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100), role VARCHAR(50) ); INSERT INTO users (name, email, role) VALUES ('Alice Johnson', 'alice@example.com', 'Admin'), ('Bob Smith', 'bob@example.com', 'User'), ('Carol Lee', 'carol@example.com', 'Editor');
Exit MySQL:
exit;
Create a file called mcp_server.py with this code:
from http.server import BaseHTTPRequestHandler, HTTPServer import json import mysql.connector class MCPHandler(BaseHTTPRequestHandler): def do_POST(self): content_length = int(self.headers.get('Content-Length', 0)) post_data = self.rfile.read(content_length) try: data = json.loads(post_data.decode('utf-8')) except json.JSONDecodeError: self.send_response(400) self.end_headers() self.wfile.write(b"Invalid JSON") return table = data.get("table", "users") try: conn = mysql.connector.connect( host="localhost", user="mcpuser", password="StrongPasswordHere", database="mcp_demo" ) cursor = conn.cursor(dictionary=True) cursor.execute(f"SELECT * FROM {table} LIMIT 100") results = cursor.fetchall() self.send_response(200) self.send_header("Content-Type", "application/json") self.end_headers() self.wfile.write(json.dumps(results).encode('utf-8')) except mysql.connector.Error as err: self.send_response(500) self.end_headers() self.wfile.write(f"MySQL error: {err}".encode('utf-8')) finally: cursor.close() conn.close() def run(): server_address = ('0.0.0.0', 9000) httpd = HTTPServer(server_address, MCPHandler) print("MCP server running on port 9000...") httpd.serve_forever() if __name__ == '__main__': run()
You need the mysql-connector-python package:
pip3 install mysql-connector-python
Run the server with:
python3 mcp_server.py
You should see:
MCP server running on port 9000...
Open a new terminal and test the server by sending a POST request:
curl -X POST http://<your-ec2-ip>:9000 \ -H "Content-Type: application/json" \ -d '{"table": "users"}'
You should get back the user data as JSON.
Congratulations! You have now:
This foundation will help you build smarter AI applications that leverage your own data securely and efficiently.
As a Director of Eternal Web Private Ltd an AWS consulting partner company, Nirav is responsible for its operations. AWS, cloud-computing and digital transformation are some of his favorite topics to talk about. His key focus is to help enterprises adopt technology, to solve their business problem with the right cloud solutions.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.