Add PostgreSQL support and setup for Playwright MCP server#3
Add PostgreSQL support and setup for Playwright MCP server#3
Conversation
- Introduced a new `docker-compose.yml` file for easy PostgreSQL and pgAdmin setup. - Added `env.example` for environment variable configuration related to PostgreSQL. - Created `setup-database.sh` script to automate database setup and migration execution. - Implemented database connection management in `src/database/config.ts` and migration handling in `src/database/migrate.ts`. - Developed `src/auth-manager.ts` for user and API key management, including authentication and permission handling. - Established an `AdminServer` in `src/admin-server.ts` for managing users and API keys through a dedicated interface. - Updated `package.json` and `package-lock.json` to include necessary dependencies for PostgreSQL integration. - Added initial database schema and migration files for user and API key management. - Enhanced the main server to initialize authentication and mount the admin interface. This commit lays the groundwork for a robust user management system within the Playwright MCP server, facilitating secure access and administration.
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive PostgreSQL support and authentication infrastructure to the Playwright MCP server, establishing a robust user management system with API key-based authentication and an admin dashboard.
- PostgreSQL integration with connection management, migrations, and database schema
- User and API key management system with role-based permissions
- Web-based admin dashboard for managing users and API keys
Reviewed Changes
Copilot reviewed 22 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/mcp-http-server.ts | Enhanced with authentication middleware, admin server integration, and database initialization |
| src/auth-manager.ts | Implements user and API key management with role-based permissions |
| src/admin-server.ts | Web-based admin interface for user and API key management |
| src/database/config.ts | Database connection management and configuration |
| src/database/migrate.ts | Migration system for database schema management |
| src/database/schema.sql | PostgreSQL schema definition for users and API keys |
| src/database/migrations/001_initial_schema.sql | Initial database migration |
| docker-compose.yml | PostgreSQL and pgAdmin services for development |
| setup-database.sh | Database setup automation script |
| env.example | Environment variable configuration template |
| package.json | Added PostgreSQL dependencies and migration scripts |
| POSTGRES_SETUP.md | Comprehensive setup documentation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| console.log('🛣️ Setting up admin server routes...'); | ||
|
|
||
| // Add request logging middleware | ||
| this.app.use((req: Request, res: Response, next: NextFunction) => { |
There was a problem hiding this comment.
Missing import for NextFunction. Add type NextFunction to the imports from express.
|
|
||
| // Admin authentication verification (no auth required for this endpoint) | ||
| console.log('🛣️ Registering POST /verify route'); | ||
| this.app.post('/verify', (req: Request, res: Response) => { |
There was a problem hiding this comment.
The authenticateAdminToken method is async but it's not being awaited here. Either await the call or make the entire function async.
|
|
||
| const token = authHeader.substring(7); | ||
| console.log(`🔍 Verifying admin token: ${token.substring(0, 8)}...`); | ||
| const isValid = this.authManager.authenticateAdminToken(token); |
There was a problem hiding this comment.
The authenticateAdminToken method is async but it's not being awaited here. Either await the call or make the entire function async.
|
|
||
| -- Create users table | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
There was a problem hiding this comment.
Function gen_random_uuid() requires PostgreSQL 13+. For better compatibility, use uuid_generate_v4() which is available with the uuid-ossp extension (already enabled in the migration).
|
|
||
| // Check if admin user exists, if not create one | ||
| const adminUser = await this.getUserByEmail("nate.lubeck@teamone-usa.com"); | ||
| if (!adminUser) { | ||
| const newAdminUser = await this.createUser({ | ||
| email: "nate.lubeck@teamone-usa.com", | ||
| name: "System Administrator", | ||
| role: "admin" | ||
| }); | ||
| console.log(`👤 Created default admin user: ${newAdminUser.email}`); | ||
| } | ||
|
|
There was a problem hiding this comment.
Hard-coded email address should be configurable via environment variable to avoid exposing personal information in code.
| // Check if admin user exists, if not create one | |
| const adminUser = await this.getUserByEmail("nate.lubeck@teamone-usa.com"); | |
| if (!adminUser) { | |
| const newAdminUser = await this.createUser({ | |
| email: "nate.lubeck@teamone-usa.com", | |
| name: "System Administrator", | |
| role: "admin" | |
| }); | |
| console.log(`👤 Created default admin user: ${newAdminUser.email}`); | |
| } | |
| // Get admin email from environment variable | |
| const adminEmail = process.env.ADMIN_EMAIL; | |
| if (!adminEmail) { | |
| throw new Error("ADMIN_EMAIL environment variable is not set. Please set it to the default admin user's email address."); | |
| } | |
| // Check if admin user exists, if not create one | |
| const adminUser = await this.getUserByEmail(adminEmail); | |
| if (!adminUser) { | |
| const newAdminUser = await this.createUser({ | |
| email: adminEmail, | |
| name: "System Administrator", | |
| role: "admin" | |
| }); | |
| console.log(`👤 Created default admin user: ${newAdminUser.email}`); | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
docker-compose.ymlfile for easy PostgreSQL and pgAdmin setup.env.examplefor environment variable configuration related to PostgreSQL.setup-database.shscript to automate database setup and migration execution.src/database/config.tsand migration handling insrc/database/migrate.ts.src/auth-manager.tsfor user and API key management, including authentication and permission handling.AdminServerinsrc/admin-server.tsfor managing users and API keys through a dedicated interface.package.jsonandpackage-lock.jsonto include necessary dependencies for PostgreSQL integration.This commit lays the groundwork for a robust user management system within the Playwright MCP server, facilitating secure access and administration.