Zum Inhalt springen
MCP ThesaurusMCP Thesaurus

ScopeGate

CommunityIncomplete39/100Beanspruchen

streamable-httpMITupdated 7d ago

Never hand an AI agent a full OAuth scope again.

QuellcodeWebsite15

Was kannst du mit ScopeGate machen?

ScopeGate

Never hand an AI agent a full OAuth scope again.

ScopeGate sits between your agents and the accounts they reach β€” yours or your clients'. You connect a service once, tick the exact actions an agent may call, and hand it an MCP endpoint that can do nothing else. Every call is logged; one click kills the key without touching the connection.

  • Per-action permissions β€” gmail:read_emails yes, gmail:send_email no. Finer than any provider's OAuth scopes.
  • Audit trail β€” who, which tool, what outcome, how long. Per project, exportable.
  • One-click revocation β€” regenerate an endpoint key; the service connection stays.
  • Tokens never leave β€” AES-256-GCM at rest, refreshed automatically, agents only ever see sg_….

Run it yourself in one command:

docker compose --profile local up

Open http://localhost:3000 β€” the admin login is printed in the container logs on first boot. Details in Quick Start.

Tech Stack

  • Framework: Next.js 16 (App Router)
  • Language: TypeScript
  • Database: PostgreSQL + Prisma 7
  • UI: Tailwind CSS v4, shadcn/ui
  • Auth: Better Auth (database-backed sessions, Prisma adapter)
  • MCP: @modelcontextprotocol/sdk (Streamable HTTP)
  • Package Manager: pnpm

Quick Start (self-hosted)

Full feature parity with the hosted cloud version β€” nothing is cut for self-host.

git clone https://github.com/alifanov/scopegate.git
cd scopegate
docker compose --profile local up

Open http://localhost:3000. No .env file needed: a local Postgres and a fresh BETTER_AUTH_SECRET are provisioned automatically, and the generated admin login is printed once in the app container logs on first boot (look for Generated admin login) β€” search it with docker compose logs app | grep -A4 "First run". The password is also saved to the app_data volume so it survives restarts.

To connect real services (Gmail, LinkedIn, GitHub, …), copy .env.example to .env and fill in the OAuth client id/secret for the providers you want β€” every block is independent and optional, a provider without credentials simply doesn't show up.

Development Setup

Prerequisites

  • Node.js 20.19+, 22.12+ or 24+ (required by Prisma 7)
  • pnpm
  • PostgreSQL

Setup

  1. Clone the repository and install dependencies:
pnpm install
  1. Copy the environment file and fill in your values:
cp .env.example .env
Variable Description
DATABASE_URL PostgreSQL connection string
BETTER_AUTH_SECRET Secret key for session signing
BETTER_AUTH_URL App base URL (e.g. http://localhost:3000)
ADMIN_EMAIL Bootstrap admin email
ADMIN_PASSWORD Bootstrap admin password
  1. Run database migrations:
pnpm prisma migrate dev
  1. Start the development server:
pnpm dev

Open http://localhost:3000.

Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ (auth)/              # Login & register pages
β”‚   β”œβ”€β”€ (dashboard)/         # Protected dashboard pages
β”‚   β”‚   └── projects/        # Project management, endpoints, audit, settings
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ auth/[...all]/    # Better Auth catch-all handler
β”‚   β”‚   β”œβ”€β”€ projects/        # Projects CRUD, endpoints, services, audit
β”‚   β”‚   └── mcp/[apiKey]/    # MCP Streamable HTTP handler
β”‚   β”œβ”€β”€ layout.tsx
β”‚   └── page.tsx             # Landing page
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ui/                  # shadcn/ui components
β”‚   β”œβ”€β”€ layout/              # Sidebar, header
β”‚   └── shared/              # Reusable app components
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ db.ts                # Prisma client singleton
β”‚   β”œβ”€β”€ auth.ts              # Better Auth server instance
β”‚   β”œβ”€β”€ auth-client.ts       # Better Auth client SDK
β”‚   β”œβ”€β”€ auth-middleware.ts   # getCurrentUser() helper
β”‚   β”œβ”€β”€ bootstrap.ts         # Admin user bootstrap on empty DB
β”‚   β”œβ”€β”€ provider-registry.ts # Every supported provider β€” the one file to edit
β”‚   └── mcp/
β”‚       β”œβ”€β”€ permissions.ts   # Permission groups (derived from the registry)
β”‚       β”œβ”€β”€ tools/           # One file per service, aggregated in index.ts
β”‚       β”œβ”€β”€ service-fetch.ts # Unified, SSRF-safe transport for all providers
β”‚       └── handler.ts       # MCP server factory + audit logging
β”œβ”€β”€ generated/prisma/        # Generated Prisma client
└── middleware.ts             # Route protection

Available Scripts

pnpm dev              # Start development server
pnpm build            # Production build
pnpm start            # Start production server
pnpm lint             # Run ESLint
pnpm prisma generate  # Regenerate Prisma client
pnpm prisma migrate dev  # Create and apply migrations
pnpm prisma studio    # Open Prisma Studio (DB browser)

How It Works

  1. Login β€” sign in with admin credentials (bootstrapped from env vars on first run)
  2. Create a Project β€” organize endpoints and services by project
  3. Connect a Service β€” add a service connection to the project
  4. Create an MCP Endpoint β€” select a service connection and pick specific permissions (e.g. gmail:read_emails, calendar:create_event)
  5. Use the MCP URL β€” plug the endpoint URL into any MCP-compatible AI agent; only the allowed actions are exposed
  6. Monitor β€” track every request in the audit log

Permissions

A permission is a single action, not a service β€” gmail:read_emails can be granted without gmail:send_email. Groups are derived from src/lib/provider-registry.ts (27 providers: Google Workspace, Google Ads & Search Console, Meta, LinkedIn, Twitter, Slack, Notion, Jira, HubSpot, Salesforce, Stripe, Airtable, …) and listed in src/lib/mcp/permissions.ts. Adding a provider means editing the registry β€” transport, token strategy and permission groups are all derived from it.

A few Google examples:

Group Actions
Gmail gmail:read_emails, gmail:send_email, gmail:list_labels, gmail:search_emails
Google Calendar calendar:list_events, calendar:create_event, calendar:update_event, calendar:delete_event
Google Drive drive:list_files, drive:read_file, drive:create_file, drive:delete_file

Database Schema

  • User β€” authentication, team membership
  • Session β€” database-backed auth sessions
  • Account β€” auth provider credentials (email/password)
  • Project β€” logical grouping for services and endpoints
  • TeamMember β€” user-project relationship with roles (owner/member)
  • ServiceConnection β€” OAuth tokens for connected services
  • McpEndpoint β€” MCP endpoint with API key, rate limit, active status
  • EndpointPermission β€” allowed actions per endpoint
  • AuditLog β€” request log with action, status, duration, errors

License

See LICENSE.