template-docker-oauth-postgresql

granular-software/template-docker-oauth-postgresql

3.2

If you are the rightful owner of template-docker-oauth-postgresql and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This template provides a production-ready MCP server with OAuth2.1 authentication and PostgreSQL database, containerized with Docker.

{{PROJECT_NAME}}

{{PROJECT_DESCRIPTION}}

Quick Start

  1. Install dependencies

    npm install
    
  2. Set up environment variables

    cp .env.example .env
    # Edit .env with your configuration
    
  3. Initialize the database

    npm run db:init
    

    This will create the PostgreSQL database with all necessary tables, functions, and indexes.

  4. Start development server

    npm run dev
    
  5. Build for production

    npm run build
    npm start
    

Database Setup

This template uses PostgreSQL for data storage. Before running the application, you need to initialize the database:

npm run db:init

Database Structure

The initialization script creates the following tables:

  • users - User accounts with UUID primary keys
  • sessions - OAuth sessions and tokens
  • notes - User notes with author relationships

Database Features

  • āœ… PostgreSQL with UUID primary keys - Scalable and secure
  • āœ… Foreign key constraints - Maintains data integrity
  • āœ… Optimized indexes - Fast lookups for common queries
  • āœ… Automatic timestamps - Created/updated tracking with triggers
  • āœ… OAuth integration - Session and token management
  • āœ… Database functions and triggers - Automatic updated_at maintenance

Database Requirements

  • PostgreSQL 12+ with UUID extension
  • Connection string in DATABASE_URL environment variable
  • SSL support for production deployments

Features

  • OAuth2.1 authentication with PostgreSQL
  • User management and sessions
  • Notes resource with author relationships
  • TypeScript support
  • Development and production builds
  • Environment variable configuration
  • Docker support with docker-compose

Project Structure

src/
ā”œā”€ā”€ server.ts          # Main server file
ā”œā”€ā”€ resources/         # MCP resources
│   ā”œā”€ā”€ users.ts       # User management
│   └── notes.ts       # Notes with author relationships
└── auth/              # OAuth configuration
    └── oauth.ts

Environment Variables

VariableDescriptionRequiredDefault
PORTServer portNo3000
SERVER_URLBase URL of your serverYes-
JWT_SECRETSecret key for JWT tokensYes-
DATABASE_URLPostgreSQL connection stringYes-
NODE_ENVEnvironment modeNodevelopment

Development

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm run typecheck - Type check without building
  • npm run db:init - Initialize database tables, functions, and indexes

Docker Deployment

This template includes Docker support:

# Build and run with Docker Compose
docker-compose up --build

# Or build manually
npm run docker:build
npm run docker:run

License

MIT