mcp_server_factory

haddock-development/mcp_server_factory

3.1

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

This project is a comprehensive Model Context Protocol (MCP) server with GitHub OAuth authentication, Cloudflare Workers deployment, and real PostgreSQL database integration via Supabase.

Tools
3
Resources
0
Prompts
0

GitHub Auth MCP Server mit PostgreSQL Integration

Ein vollständiger MCP (Model Context Protocol) Server mit GitHub OAuth Authentication, Cloudflare Workers Deployment und realer PostgreSQL-Datenbankanbindung über Supabase.

🚀 Was dieses Projekt kann

  • GitHub OAuth Authentication: Sichere Benutzerauthentifizierung über GitHub
  • Device Flow Support: Programmatic Authentication ohne Browser-Interaktion
  • Cloudflare Workers: Serverless Deployment mit globaler Reichweite
  • PostgreSQL Integration: Echte Datenbankanbindung über Supabase
  • MCP Tools: Drei Datenbank-Tools mit Berechtigungsmanagement
  • TypeScript First: Vollständig in TypeScript implementiert

🛠️ Features

Authentication

  • OAuth Web Flow: Browser-basierte Authentifizierung
  • Device Flow: Command-line Authentication mit User Code
  • Session Management: Sichere Session-Verwaltung über KV Storage
  • Privileged Users: Rollenbasierte Zugriffssteuerung

Database Tools

  • listTables: Zeigt alle Datenbanktabellen mit Schema-Informationen
  • queryDatabase: Führt read-only SQL-Abfragen aus
  • executeDatabase: Führt write-Abfragen aus (nur für privilegierte Benutzer)

Deployment

  • Cloudflare Workers: Serverless Hosting
  • Global Edge Network: Weltweite Verfügbarkeit
  • Automatic Scaling: Skaliert automatisch mit der Nutzung

📋 Voraussetzungen

Benötigte Accounts

  • GitHub Account: Für OAuth App Erstellung
  • Cloudflare Account: Für Workers Deployment
  • Supabase Account: Für PostgreSQL Hosting

Benötigte Tools

# Node.js und npm
node -v  # >= 18.0.0
npm -v   # >= 8.0.0

# Cloudflare Wrangler
npm install -g wrangler

# Git für Versionskontrolle
git --version

🏗️ Setup Schritt für Schritt

Schritt 1: Repository klonen und vorbereiten

# Repository klonen
git clone <repository-url>
cd mcp_server_factory

# Abhängigkeiten installieren
npm install

Schritt 2: GitHub OAuth App erstellen

  1. GitHub Developer Settings öffnen

  2. OAuth App konfigurieren

    App name: GitHub Auth MCP Server
    Homepage URL: https://github-auth-mcp-server.deinname.workers.dev
    Authorization callback URL: https://github-auth-mcp-server.deinname.workers.dev/auth/callback
    
  3. Client ID und Secret kopieren

    • Client ID: Wird sofort angezeigt
    • Client Secret: Klicke auf "Generate a new client secret"

Schritt 3: Cloudflare Workers einrichten

  1. Wrangler einloggen

    wrangler login
    
  2. Workers Subdomain konfigurieren

    # In wrangler.toml anpassen
    name = "github-auth-mcp-server"
    workers_dev = true
    
  3. KV Namespace erstellen

    wrangler kv namespace create "MCP_SESSIONS"
    # Die ID in wrangler.toml eintragen
    

Schritt 4: Supabase PostgreSQL einrichten

  1. Supabase Projekt erstellen

  2. Datenbank-Verbindung details kopieren

    • Database Name: Standardmäßig "postgres"
    • Host: Unter Project Settings → Database
    • Password: Wird bei Erstellung generiert
  3. Service Role Key erstellen

    • Gehe zu Project Settings → API
    • Unter "Project API keys" → "service_role" kopieren

Schritt 5: Environment Variables konfigurieren

Erstelle .dev.vars im Projektverzeichnis:

# GitHub OAuth
GITHUB_CLIENT_ID=deine_github_client_id
GITHUB_CLIENT_SECRET=dein_github_client_secret

# Session Management
COOKIE_ENCRYPTION_KEY=ein_langer_zufälliger_string_mindestens_32_zeichen

# Database Connection
DATABASE_URL=postgresql://postgres:dein_passwort@dein_host.supabase.co:5432/deine_datenbank
SUPABASE_SERVICE_KEY=dein_supabase_service_role_key

# Privileged Users (komma-getrennt)
PRIVILEGED_USERS=dein_github_username

# Environment
ENVIRONMENT=development

Schritt 6: Deployment

# TypeScript Type-Checking
npm run type-check

# Lokale Entwicklung
npm run dev

# Deployment zu Cloudflare
npm run deploy

🧪 Testing

Health Check

curl https://github-auth-mcp-server.deinname.workers.dev/health

Device Flow Test

# Device Flow initiieren
npx ts-node demo.ts

# User Code und URL werden angezeigt
# Besuche die URL und gib den Code ein

Full Endpoint Test

# Alle Endpunkte testen
npx ts-node tests/test-endpoints.ts

🔧 Konfiguration

TypeScript Konfiguration (tsconfig.json)

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "lib": ["ES2022"],
    "strict": false,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "declaration": true,
    "sourceMap": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist", "tests"]
}

Wrangler Konfiguration (wrangler.toml)

name = "github-auth-mcp-server"
main = "src/index.ts"
compatibility_date = "2024-01-01"
workers_dev = true

[[kv_namespaces]]
binding = "MCP_SESSIONS"
id = "dein_kv_namespace_id"

🚨 Wichtige Fallstricke und Lösungen

1. TypeScript statt JavaScript für MCP Server

Problem: Viele MCP Tutorials verwenden JavaScript, aber für professionelle Projekte ist TypeScript besser.

Lösung:

  • Verwende TypeScript für Typsicherheit und bessere Entwicklung
  • Konfiguriere tsconfig.json mit noImplicitAny: false für Flexibilität
  • Verwende tsc --noEmit für Type-Checking ohne JavaScript-Generierung

2. Cloudflare Workers kann nicht auf localhost zugreifen

Problem: Lokale PostgreSQL-Datenbanken sind von Cloudflare Workers nicht erreichbar.

Lösung:

  • Verwende Cloud-PostgreSQL-Anbieter wie Supabase
  • Supabase bietet externe Verbindungen und ist Cloudflare-kompatibel

3. GitHub OAuth Callback URLs

Problem: OAuth Callback URLs müssen exakt übereinstimmen.

Lösung:

  • Verwende die korrekte Format: https://dein-subdomain.workers.dev/auth/callback
  • Teste die Callback URL nach dem Deployment

4. Environment Variables in Production

Problem: Lokale .dev.vars funktionieren nicht in Production.

Lösung:

  • Konfiguriere Environment Variables im Cloudflare Dashboard
  • Oder verwende wrangler secret put für sensible Daten

5. Session Management in Serverless

Problem: Serverless Functions sind stateless, benötigen aber Session-Management.

Lösung:

  • Verwende Cloudflare KV Storage für Sessions
  • Implementiere Cookie-basierte Session-Verwaltung

6. SQL Injection Protection

Problem: MCP Tools könnten für SQL Injection missbraucht werden.

Lösung:

  • Implementiere Keyword-Filter für read-only Abfragen
  • Beschränke write-Operationen auf privilegierte Benutzer

📚 MCP Client Konfiguration

Claude Desktop

{
  "mcpServers": {
    "github-auth-postgres": {
      "command": "npx",
      "args": ["ts-node", "/pfad/zum/projekt/demo.ts"],
      "env": {
        "GITHUB_CLIENT_ID": "deine_client_id",
        "GITHUB_CLIENT_SECRET": "dein_client_secret"
      }
    }
  }
}

VS Code mit MCP Extension

{
  "mcpServers": {
    "github-auth-postgres": {
      "command": "npx",
      "args": ["ts-node", "/pfad/zum/projekt/demo.ts"]
    }
  }
}

🔍 Troubleshooting

Häufige Fehler

  1. "Authentication required"

    • Stelle sicher, dass du eine gültige Session hast
    • Führe den Device Flow aus und autorisiere die App
  2. "Database connection failed"

    • Überprüfe die Supabase Connection Details
    • Stelle sicher, dass die Datenbank externe Verbindungen erlaubt
  3. "TypeScript compilation errors"

    • Führe npm run type-check aus
    • Überprüfe die TypeScript-Konfiguration
  4. "Deployment failed"

    • Überprüfe die Wrangler-Konfiguration
    • Stelle sicher, dass alle Secrets konfiguriert sind

Debugging

# Lokale Entwicklung mit Debugging
npm run dev

# Logs in Cloudflare Dashboard ansehen
wrangler tail

# TypeScript-Debugging
npx ts-node --inspect demo.ts

🏗️ Projektstruktur

├── src/
│   ├── index.ts                    # Haupt-MCP Server
│   └── device-flow-auth.ts         # Device Flow Implementation
├── tests/
│   ├── test-endpoints.ts          # Endpunkt-Tests
│   ├── test-device-flow-endpoint.ts # Device Flow Tests
│   ├── test-browser-session-tools.ts # Browser Session Tests
│   ├── test-database-tools.ts      # Datenbank-Tool Tests
│   └── test-supabase-postgresql.ts # Supabase Integration Tests
├── demo.ts                        # Demo und Beispiele
├── .dev.vars                      # Environment Variables (dev)
├── wrangler.toml                  # Cloudflare Konfiguration
├── tsconfig.json                  # TypeScript Konfiguration
├── package.json                   # Dependencies und Scripts
└── README.md                      # Diese Datei

🚀 Deployment zu anderen Environments

Staging

wrangler deploy --env staging

Production

wrangler deploy --env production

🤝 Contributing

  1. Fork das Repository
  2. Erstelle einen Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit deine Changes (git commit -m 'Add amazing feature')
  4. Push zum Branch (git push origin feature/amazing-feature)
  5. Öffne ein Pull Request

📄 License

Dieses Projekt ist MIT lizenziert - siehe die Datei für Details.

🙏 Danksagungen

📞 Support

Bei Fragen oder Problemen:

  1. Überprüfe die Troubleshooting Sektion
  2. Suche in existing Issues
  3. Erstelle ein neues Issue mit详细的 Beschreibung

Hinweis: Dieses Projekt wurde als Referenzimplementierung für MCP Server mit GitHub Auth und PostgreSQL Integration entwickelt. Es kann als Grundlage für eigene MCP Server-Projekte dienen.