Skip to content

feat: enhance MCP server support with authentication and environment variables #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .env

This file was deleted.

68 changes: 67 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
.vscode
# Environment files
.env
.env.*
!.env.example

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
.venv
venv/
ENV/

# IDE
.vscode/
.idea/
*.swp
*.swo
.DS_Store

# Testing
.coverage
htmlcov/
.pytest_cache/
.tox/

# Logs
logs/
*.log

# Node.js
node_modules/

# Local development
.env.local
.env.development.local
.env.test.local
.env.production.local

# Debug logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Misc
.DS_Store
*.pem

# Playwright
/test-results/
/playwright-report/
/blob-report/
Expand Down
43 changes: 43 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/copilot
ASYNC_DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/copilot

# Security
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

# First superuser
[email protected]
FIRST_SUPERUSER_PASSWORD=changeme

# Email (for password reset, etc.)
SMTP_TLS=True
SMTP_PORT=587
SMTP_HOST=smtp.example.com
[email protected]
SMTP_PASSWORD=your-email-password
[email protected]
EMAILS_FROM_NAME="Copilot"

# OAuth (Google)
GOOGLE_OAUTH_CLIENT_ID=your-google-client-id
GOOGLE_OAUTH_CLIENT_SECRET=your-google-client-secret
GOOGLE_OAUTH_REDIRECT_URI=http://localhost:8000/auth/google/callback

# OAuth (Microsoft)
MICROSOFT_OAUTH_CLIENT_ID=your-microsoft-client-id
MICROSOFT_OAUTH_CLIENT_SECRET=your-microsoft-client-secret
MICROSOFT_OAUTH_REDIRECT_URI=http://localhost:8000/auth/microsoft/callback
MICROSOFT_OAUTH_TENANT=common

# CORS (comma-separated list of origins, or * for all)
BACKEND_CORS_ORIGINS=["http://localhost:3000", "http://localhost:8000"]

# Logging
LOG_LEVEL=INFO
SQL_ECHO=False

# Environment (development, staging, production)
ENVIRONMENT=development
118 changes: 118 additions & 0 deletions backend/DB_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Database Setup and Migrations

This document explains how to set up the database and manage migrations for the Copilot backend.

## Prerequisites

- Python 3.8+
- PostgreSQL 13+
- pip
- virtualenv (recommended)

## Setup

1. **Create a virtual environment** (recommended):
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```

2. **Install dependencies**:
```bash
pip install -e ".[dev]"
```

3. **Set up environment variables**:
Copy `.env.example` to `.env` and update the values:
```bash
cp .env.example .env
```

## Database Configuration

Update the following environment variables in your `.env` file:

```
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/copilot
ASYNC_DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/copilot
```

## Running Migrations

### Create a new migration

To create a new migration after making changes to your models:

```bash
python -m scripts.migrate create --message "your migration message"
```

### Apply migrations

To apply all pending migrations:

```bash
python -m scripts.migrate upgrade head
```

### Rollback a migration

To rollback to a previous migration:

```bash
python -m scripts.migrate downgrade <revision>
```

### Show current migration

To show the current migration:

```bash
python -m scripts.migrate current
```

### Show migration history

To show the migration history:

```bash
python -m scripts.migrate history
```

## Initial Setup

To set up the database and run all migrations:

```bash
./scripts/setup_db.sh
```

This will:
1. Check if the database is accessible
2. Run all pending migrations
3. Create an initial admin user if it doesn't exist

## Database Models

The database models are defined in `app/models/`:

- `base.py`: Base model classes and mixins
- `user.py`: User-related models and schemas

## Common Issues

### Database Connection Issues

If you encounter connection issues:

1. Ensure PostgreSQL is running
2. Check that the database exists and the user has the correct permissions
3. Verify the connection string in your `.env` file

### Migration Issues

If you encounter issues with migrations:

1. Make sure all models are properly imported in `app/models/__init__.py`
2. Check for any syntax errors in your models
3. If needed, you can delete the migration files in `app/alembic/versions/` and create a new initial migration
25 changes: 15 additions & 10 deletions backend/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
script_location = app/alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =
timezone = UTC

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40
truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false
sourceless = false

# version location specification; this defaults
# to alembic/versions. When using multiple version
Expand All @@ -33,7 +33,12 @@ script_location = app/alembic

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8
output_encoding = utf-8

# Database connection string
# IMPORTANT: This value is overridden by env.py which uses the database URL from environment variables
# The value below is just a placeholder and should NOT contain production credentials
sqlalchemy.url = postgresql://user:pass@localhost/dbname

# Logging configuration
[loggers]
Expand All @@ -46,18 +51,18 @@ keys = console
keys = generic

[logger_root]
level = WARN
level = INFO
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
handlers =
qualname = alembic

[handler_console]
Expand Down
Loading
Loading