main
1package main
2
3import (
4 "context"
5 "flag"
6 "fmt"
7 "log"
8 "os"
9
10 "github.com/xlgmokha/mcp/pkg/gitlab"
11)
12
13func main() {
14 var (
15 gitlabURL = flag.String("gitlab-url", "https://gitlab.com", "GitLab instance URL")
16 help = flag.Bool("help", false, "Show help information")
17 )
18 flag.Parse()
19
20 if *help {
21 fmt.Printf(`GitLab MCP Server
22
23This server provides access to GitLab APIs for issue management, project tracking,
24and workflow automation designed for GitLab software engineers.
25
26Usage: %s [options]
27
28Options:
29`, os.Args[0])
30 flag.PrintDefaults()
31 fmt.Print(`
32Examples:
33 # Use GITLAB_TOKEN environment variable (recommended)
34 export-access-token && mcp-gitlab
35
36 # Specify token directly
37 mcp-gitlab --gitlab-token your_token_here
38
39 # Use with self-hosted GitLab instance
40 mcp-gitlab --gitlab-url https://gitlab.company.com
41
42Tools:
43 - gitlab_list_my_projects: List projects you have access to with activity info
44 - gitlab_list_my_issues: Issues assigned/authored/mentioned, prioritized by activity
45 - gitlab_get_issue_conversations: Full conversation threads with participants
46 - gitlab_find_similar_issues: Cross-project similarity search using AI
47 - gitlab_get_my_activity: Recent activity summary and triage assistance
48
49Environment Variables:
50 - GITLAB_TOKEN: Personal Access Token (use with export-access-token script)
51 - GITLAB_URL: GitLab instance URL (default: https://gitlab.com)
52
53Caching Features:
54 - Automatic local caching in ~/.mcp/gitlab/ for faster responses
55 - 5-minute TTL (configurable) with intelligent cache invalidation
56 - Offline mode: returns cached data when network is unavailable
57 - Reduces API calls and improves performance for repeated queries
58 - Sharded file storage with statistics tracking
59
60For GitLab software engineers: This server integrates with your existing
61export-access-token workflow and provides AI-assisted organization of your
62GitLab work across multiple projects. Local caching ensures fast responses
63and offline capability for improved productivity.
64
65For more information, visit: https://github.com/xlgmokha/mcp
66`)
67 return
68 }
69
70 token := os.Getenv("GITLAB_TOKEN")
71 if token == "" {
72 log.Fatal("GitLab token required. Set GITLAB_TOKEN environment variable.\n")
73 }
74
75 url := *gitlabURL
76 if envURL := os.Getenv("GITLAB_URL"); envURL != "" {
77 url = envURL
78 }
79
80 server, err := gitlab.New(url, token)
81 if err != nil {
82 log.Fatalf("Failed to create GitLab server: %v", err)
83 }
84
85 ctx := context.Background()
86 if err := server.Run(ctx); err != nil {
87 log.Fatalf("Server error: %v", err)
88 }
89}