gitlab-mcp-server

gitlab-mcp-server

A TypeScript-based MCP server that enables code search, file reading, and project management via the GitLab API.

Category
Visit Server

README

<!-- 自動產生的 README,若需調整請編輯此檔。 -->

gitlab-mcp-server

簡短說明

  • 用途:此專案是一個以 TypeScript 撰寫的 Node.js 伺服器範例,主要入口為 src/index.ts。
  • 專案類型:TypeScript + Node.js

專案結構

開始(本地開發)

建議步驟(以常見設定為例,實際以 package.json 為準):

  1. 安裝相依套件
npm install
  1. 本地建置(TypeScript → JavaScript)
npm run build
# 或: npx tsc -p tsconfig.json
  1. 啟動伺服器
npm start
# 或直接執行編譯後的檔案,例如: node dist/index.js

開發流程(開發時可用)

  • 使用 ts-node 或 nodemon + ts-node 來熱重載:
npm run dev

MCP 連線模式與常見錯誤

  • 伺服器同時支援兩種模式:
    • Stateful:客戶端帶 mcp-session-id,伺服器維護 session。
    • Stateless:客戶端未帶 mcp-session-id,伺服器會以無 session 模式處理請求。
  • 若遇到 Request failed with status code 400,通常代表請求不是 initialize 且 session 無效。
  • 若遇到 Session not found,請讓客戶端重新 initialize(重新連線)。

環境變數設定

  • GITLAB_API:GitLab API Base URL(例如 https://gitlab.example.com/api/v4)
  • GITLAB_GROUP_TOKEN:GitLab Token(建議至少有 read_api)
  • PLATFORM_GROUP_ID:選填
    • 有填:只查詢該群組(含子群組)底下專案
    • 未填:查詢 token 可存取的專案(membership=true)
  • PORT:伺服器埠號(選填)
  • URL:伺服器對外位址

search_code(無 Elasticsearch)調校建議

  • 可用 mode 控制掃描策略:
    • fast:較快(掃描範圍較小)
    • balanced:預設(速度與完整度平衡)
    • deep:較完整(掃描範圍較大)
    • hybrid:先 fast 再 deep 補抓(建議查漏時使用)
  • 強烈建議指定 projectId(專案 ID 或 group/project 路徑):
    • 會優先使用 GitLab projects/:id/search,速度通常明顯快於群組或全域搜尋
    • fallback 內容掃描也只會掃該專案,避免掃到整個可存取範圍
  • 若 未指定 projectId 且未傳入 maxProjects:
    • 系統會自動套用 maxProjects=10 保護值,降低慢查詢風險
    • 回應會提示目前為未指定專案的受限搜尋
  • 可選參數:
    • projectId:指定單一專案(建議優先使用)
    • maxProjects:最多掃描專案數
    • maxFilesPerProject:每個專案最多讀取檔案數
    • maxResults:最多回傳結果數
  • 多關鍵字請用 | 分隔,例如:臺銀|台銀|繳費|virtual_account|bank_code

範例:

{
  "query": "PaymentService|virtual_account",
  "projectId": "platform/tc-gaizan",
  "mode": "fast",
  "maxResults": 50
}

GitLab Token 權限建議(GITLAB_GROUP_TOKEN)

  • 建議類型:
    • 有設定 PLATFORM_GROUP_ID:Group Access Token
    • 未設定 PLATFORM_GROUP_ID:建議 Personal Access Token
  • 最小 Scope:read_api
  • 建議角色:至少 Reporter(可讀取可存取範圍內專案與 repository 內容)
  • 不需要開啟:write_repository、read_registry、write_registry

說明:本專案目前僅使用 GitLab 讀取型 API(GET/HEAD),包含:

  • 列出可存取專案(群組範圍或 membership 範圍)
  • 搜尋程式碼
  • 讀取檔案內容
  • 讀取分支與目錄樹

因此以 read_api 為最小且安全的預設即可;若你的 GitLab 環境策略較嚴格導致 403,再視需要升級為 api。

Token 安全檢查清單

  • 不要把 token 寫進版本控制(避免提交 .env)
  • 使用部署環境變數或 Secret 管理服務保存 token
  • 以最小權限原則設定 scope(優先 read_api)
  • 設定到期日並定期輪替 token
  • 若懷疑外洩,立即 revoke 與重發 token

相依與建議工具

  • Node.js (v16+ 建議)
  • TypeScript
  • 建議安裝 VS Code 的 TypeScript/Node 開發相關外掛

貢獻指南

  1. Fork 專案並建立 branch
  2. 撰寫或修改 src/ 下的程式
  3. 送出 PR 並描述變更重點

授權

此專案未指定授權(請視需求加入 LICENSE 檔)。

聯絡

若有問題或需求,請在 repository 中開 issue。

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured