This project is a secure local MCP server built with Node.js and Express. It features HTTPS encryption using self-signed certificates, GitHub OAuth authentication, and additional security measures like rate limiting and HTTP header protection.
- HTTPS Encryption: Ensures secure communication between clients and the server.
- GitHub OAuth Authentication: Allows users to log in using their GitHub accounts.
- Rate Limiting: Protects against abuse and denial-of-service (DoS) attacks.
- Secure Session Management: Uses
express-sessionwith secure cookies. - HTTP Header Security: Implements
helmetto protect against common vulnerabilities.
Before you begin, ensure you have the following installed on your system:
Clone this repository to your local machine:
git clone https://github.com/omar-steam/MCP-Server-with-HTTPS-and-GitHub-OAuth.git cd mcp-server
Install the required npm packages:
npm install
Generate self-signed SSL certificates using OpenSSL:
openssl genrsa -out key.pem 2048 openssl req -new -key key.pem -out csr.pem openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out cert.pem
This will create the following files in your project directory:
key.pem: Private keycert.pem: Self-signed certificate
Create a .env file in the root of your project and add the following variables:
CLIENT_ID=your-github-client-id CLIENT_SECRET=your-github-client-secret REDIRECT_URI=https://localhost:3000/auth/callback SESSION_SECRET=your-session-secret
Replace your-github-client-id and your-github-client-secret with the credentials from your GitHub OAuth App.
Run the server:
node server.js
You should see:
Secure server running on https://localhost:3000
Open your browser and navigate to:
https://localhost:3000
- Visit
/authto start the GitHub authentication process:
https://localhost:3000/auth
- After successful login, you’ll be redirected to
/success. - If authentication fails, you’ll be redirected to
/failure.
Access /secure-data to test a route that requires authentication:
https://localhost:3000/secure-data
If you’re not authenticated, you’ll see a 401 Unauthorized error.
mcp-server/ ├── key.pem # Private key for HTTPS ├── cert.pem # Self-signed certificate for HTTPS ├── server.js # Main server file ├── package.json # Project metadata and dependencies ├── .env # Environment variables (not included in version control) └── README.md # Project documentation (this file)
If port 3000 is already in use, stop any processes using it or change the port in server.js.
To find and kill processes using port 3000:
netstat -ano | findstr :3000 taskkill /PID <PID> /F
Self-signed certificates are not trusted by browsers. For production, use a trusted Certificate Authority like Let’s Encrypt.
Feel free to fork this repository, make improvements, and submit pull requests! Contributions are welcome.
This project is licensed under the MIT License. See the LICENSE file for details.
Special thanks to:
- Replace placeholders like
your-github-client-idwith your actual credentials. - Update the repository URL (
git clone) with your GitHub repository link if you’re hosting this code.