forked from zereight/gitlab-mcp
-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(api): unified GitLab REST API client and lint fixes #17
Copy link
Copy link
Description
Summary
Introduces a unified GitLab REST API client, OAuth session storage backends, and fixes all ESLint errors.
Changes
Unified GitLab REST API Client
- Add
src/utils/gitlab-api.ts- unified client for GitLab API calls - Centralized URL building with base URL from config
- Query parameters serialization with undefined/null filtering
- Request body encoding (JSON or form-urlencoded)
- Automatic GID cleanup from responses
- Handle 204 No Content responses correctly
- Type-safe request/response handling
OAuth Session Storage Backends
New pluggable storage architecture for OAuth sessions:
- Memory Backend (default) - In-memory storage, sessions lost on restart
- File Backend - JSON file-based persistence with configurable save interval
- PostgreSQL Backend - Production-grade storage via Prisma ORM
Storage selection via environment:
```bash
OAUTH_STORAGE_TYPE=memory|file|postgresql
OAUTH_STORAGE_FILE_PATH=./data/oauth-sessions.json
OAUTH_STORAGE_POSTGRESQL_URL=postgresql://...
```
OAuth Flow Implementation (Dual Flow Support)
Authorization Code Flow (for Claude.ai Custom Connectors):
- Client redirects to `/authorize` with `redirect_uri`
- Server redirects to GitLab OAuth
- GitLab redirects back to `/oauth/callback`
- Server exchanges code for tokens
- Server redirects to client with authorization code
- Client exchanges code at `/token` endpoint
Device Flow (for CLI clients, Claude Desktop):
- Client requests `/authorize` without `redirect_uri`
- Server returns device code and verification URL
- User visits GitLab, enters device code
- Client polls `/oauth/poll` for completion
- Server exchanges GitLab token for MCP session token
Flow auto-selection based on `redirect_uri` presence in authorization request.
New OAuth Endpoints
- `/oauth/callback` - GitLab OAuth callback handler
- `/oauth/poll` - Device flow polling endpoint
- `/register` - Dynamic client registration (RFC 7591)
Registry Refactoring
- Refactor labels, wiki, variables, milestones registries
- Use new gitlab-api utility for cleaner request handling
- Consistent pattern across all entity registries
Lint Fixes
- Fix unnecessary type assertion in gitlab-api.ts
- Fix Prisma type resolution with explicit interfaces (GenericPrismaClient pattern)
- Fix logger mocks in integration and unit tests
- All 101 errors resolved with proper typing, zero eslint-disable comments
Benefits
- Cleaner, more consistent API calls
- Type-safe request/response handling
- Centralized error handling
- Production-ready OAuth session persistence
- Support for both web and CLI OAuth flows
- Zero lint errors
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels