Skip to main content
Glama
gitlab.ts3.08 kB
import { AppError } from '../lib/errors.js'; import { requestJson } from '../lib/http.js'; type GitLabCfg = { url: string; token: string }; export class GitLabAdapter { constructor(private cfg: GitLabCfg) {} private headers() { return { 'PRIVATE-TOKEN': this.cfg.token }; } async listProjects(limit = 100): Promise<unknown[]> { const results: unknown[] = []; let page = 1; const perPage = 50; while (results.length < limit) { const u = new URL('/api/v4/projects', this.cfg.url); u.searchParams.set('per_page', String(perPage)); u.searchParams.set('page', String(page)); const { status, headers, data } = await requestJson(u.toString(), { headers: this.headers() }); if (status >= 400) throw new AppError('UPSTREAM_HTTP_ERROR', 'GitLab projects request failed', { status }); const arr = Array.isArray(data) ? data : []; results.push(...arr); const next = headers['x-next-page'] as string | string[] | undefined; const hasNext = Array.isArray(next) ? next[0] : next; if (!hasNext || arr.length === 0) break; page++; } return results.slice(0, limit); } async listMergeRequests(projectId: number | string, state?: 'opened' | 'closed' | 'merged', limit = 100) { const results: unknown[] = []; let page = 1; const perPage = 50; while (results.length < limit) { const u = new URL(`/api/v4/projects/${projectId}/merge_requests`, this.cfg.url); if (state) u.searchParams.set('state', state); u.searchParams.set('per_page', String(perPage)); u.searchParams.set('page', String(page)); const { status, headers, data } = await requestJson(u.toString(), { headers: this.headers() }); if (status >= 400) throw new AppError('UPSTREAM_HTTP_ERROR', 'GitLab merge requests failed', { status }); const arr = Array.isArray(data) ? data : []; results.push(...arr); const next = headers['x-next-page'] as string | string[] | undefined; const hasNext = Array.isArray(next) ? next[0] : next; if (!hasNext || arr.length === 0) break; page++; } return results.slice(0, limit); } async listIssues(projectId: number | string, limit = 100) { const results: unknown[] = []; let page = 1; const perPage = 50; while (results.length < limit) { const u = new URL(`/api/v4/projects/${projectId}/issues`, this.cfg.url); u.searchParams.set('per_page', String(perPage)); u.searchParams.set('page', String(page)); const { status, headers, data } = await requestJson(u.toString(), { headers: this.headers() }); if (status >= 400) throw new AppError('UPSTREAM_HTTP_ERROR', 'GitLab issues request failed', { status }); const arr = Array.isArray(data) ? data : []; results.push(...arr); const next = headers['x-next-page'] as string | string[] | undefined; const hasNext = Array.isArray(next) ? next[0] : next; if (!hasNext || arr.length === 0) break; page++; } return results.slice(0, limit); } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ashabbir/multi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server