Skip to content

Add PostgreSQL support and setup for Playwright MCP server#3

Open
etnlbck wants to merge 2 commits intomainfrom
feature/authorization
Open

Add PostgreSQL support and setup for Playwright MCP server#3
etnlbck wants to merge 2 commits intomainfrom
feature/authorization

Conversation

@etnlbck
Copy link
Owner

@etnlbck etnlbck commented Oct 6, 2025

  • 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.

- 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.
Copilot AI review requested due to automatic review settings October 6, 2025 12:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for NextFunction. Add type NextFunction to the imports from express.

Copilot uses AI. Check for mistakes.

// Admin authentication verification (no auth required for this endpoint)
console.log('🛣️ Registering POST /verify route');
this.app.post('/verify', (req: Request, res: Response) => {
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authenticateAdminToken method is async but it's not being awaited here. Either await the call or make the entire function async.

Copilot uses AI. Check for mistakes.

const token = authHeader.substring(7);
console.log(`🔍 Verifying admin token: ${token.substring(0, 8)}...`);
const isValid = this.authManager.authenticateAdminToken(token);
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authenticateAdminToken method is async but it's not being awaited here. Either await the call or make the entire function async.

Copilot uses AI. Check for mistakes.

-- Create users table
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Comment on lines +104 to +115

// 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}`);
}

Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded email address should be configurable via environment variable to avoid exposing personal information in code.

Suggested change
// 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}`);
}

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants