summaryrefslogtreecommitdiff
path: root/cmd/gitlab/main.go
blob: 539aa1b6500ba0f2eea1f9c538571c7b38317ea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main

import (
	"context"
	"flag"
	"fmt"
	"log"
	"os"

	"github.com/xlgmokha/mcp/pkg/gitlab"
)

func main() {
	var (
		gitlabURL   = flag.String("gitlab-url", "https://gitlab.com", "GitLab instance URL")
		gitlabToken = flag.String("gitlab-token", "", "GitLab Personal Access Token (overrides GITLAB_TOKEN env var)")
		help        = flag.Bool("help", false, "Show help information")
	)
	flag.Parse()

	if *help {
		fmt.Printf(`GitLab MCP Server

This server provides access to GitLab APIs for issue management, project tracking,
and workflow automation designed for GitLab software engineers.

Usage: %s [options]

Options:
`, os.Args[0])
		flag.PrintDefaults()
		fmt.Print(`
Examples:
  # Use GITLAB_TOKEN environment variable (recommended)
  export-access-token && mcp-gitlab
  
  # Specify token directly
  mcp-gitlab --gitlab-token your_token_here
  
  # Use with self-hosted GitLab instance
  mcp-gitlab --gitlab-url https://gitlab.company.com

Tools:
  - gitlab_list_my_projects: List projects you have access to with activity info
  - gitlab_list_my_issues: Issues assigned/authored/mentioned, prioritized by activity
  - gitlab_get_issue_conversations: Full conversation threads with participants
  - gitlab_find_similar_issues: Cross-project similarity search using AI
  - gitlab_get_my_activity: Recent activity summary and triage assistance
  
Cache Management Tools:
  - gitlab_cache_stats: View cache performance and storage statistics
  - gitlab_cache_clear: Clear specific cache types or all cached data (requires confirmation)
  - gitlab_offline_query: Query cached data when network is unavailable

Environment Variables:
  - GITLAB_TOKEN: Personal Access Token (use with export-access-token script)
  - GITLAB_URL: GitLab instance URL (default: https://gitlab.com)

Caching Features:
  - Automatic local caching in ~/.mcp/gitlab/ for faster responses
  - 5-minute TTL (configurable) with intelligent cache invalidation
  - Offline mode: returns cached data when network is unavailable
  - Reduces API calls and improves performance for repeated queries
  - Sharded file storage with statistics tracking

For GitLab software engineers: This server integrates with your existing
export-access-token workflow and provides AI-assisted organization of your
GitLab work across multiple projects. Local caching ensures fast responses
and offline capability for improved productivity.

For more information, visit: https://github.com/xlgmokha/mcp
`)
		return
	}

	// Get GitLab token from flag or environment variable
	token := *gitlabToken
	if token == "" {
		token = os.Getenv("GITLAB_TOKEN")
		if token == "" {
			log.Fatal("GitLab token required. Set GITLAB_TOKEN environment variable or use --gitlab-token flag.\n" +
				"For GitLab employees: run 'export-access-token' first, then start the server.")
		}
	}

	// Get GitLab URL from flag or environment variable
	url := *gitlabURL
	if envURL := os.Getenv("GITLAB_URL"); envURL != "" {
		url = envURL
	}

	server, err := gitlab.New(url, token)
	if err != nil {
		log.Fatalf("Failed to create GitLab server: %v", err)
	}

	ctx := context.Background()
	if err := server.Run(ctx); err != nil {
		log.Fatalf("Server error: %v", err)
	}
}