What Is MCP and How to Run Your First MCP Server on Amazon Linux

What Is MCP and How to Run Your First MCP Server on Amazon Linux

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.

 

What Is MCP?

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.

 

Why Should You Care?

  • AI tools like ChatGPT or other assistants are powerful but can only answer based on the data they have.
  • MCP allows these AI tools to access real data from your own systems securely.
  • This makes AI responses more accurate, personalized, and useful.

 

Getting Started: What You Need

  • An Amazon Linux server (EC2 instance)
  • Basic knowledge of the command line
  • Python 3 installed
  • MySQL database installed and running

 

Step 1: Set Up Your Amazon Linux EC2 Instance

Launch an Amazon Linux 2 instance on AWS EC2.

Connect to it using SSH.

Update your system:

sudo yum update -y

 

Step 2: Install Python 3 and MySQL

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

 

Step 3: Create a Sample Database and User

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;

 

Step 4: Write Your MCP Server in Python

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()

 

Step 5: Install Required Python Package

You need the mysql-connector-python package:

pip3 install mysql-connector-python

 

Step 6: Run Your MCP Server

Run the server with:

python3 mcp_server.py

You should see:

MCP server running on port 9000...

 

Step 7: Test Your MCP Server

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.

 

Conclusion

Congratulations! You have now:

  • Learned what MCP is and why it matters
  • Set up a simple database on Amazon Linux
  • Written and run a basic MCP server in Python
  • Queried your MCP server for data

This foundation will help you build smarter AI applications that leverage your own data securely and efficiently.

 

What Next?

 

  • Secure your MCP server with authentication
  • Add HTTPS support using Nginx and Certbot
  • Expand MCP capabilities for different data sources
  • Integrate MCP with AI chatbots or developer tools

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    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.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project