gitlab-mcp-server
A TypeScript-based MCP server that enables code search, file reading, and project management via the GitLab API.
README
<!-- 自動產生的 README,若需調整請編輯此檔。 -->
gitlab-mcp-server
簡短說明
- 用途:此專案是一個以 TypeScript 撰寫的 Node.js 伺服器範例,主要入口為 src/index.ts。
- 專案類型:TypeScript + Node.js
專案結構
- package.json - 專案相依與 scripts 定義
- tsconfig.json - TypeScript 設定
- src/index.ts - 應用程式進入點
開始(本地開發)
建議步驟(以常見設定為例,實際以 package.json 為準):
- 安裝相依套件
npm install
- 本地建置(TypeScript → JavaScript)
npm run build
# 或: npx tsc -p tsconfig.json
- 啟動伺服器
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 模式處理請求。
- Stateful:客戶端帶
- 若遇到
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 內容掃描也只會掃該專案,避免掃到整個可存取範圍
- 會優先使用 GitLab
- 若 未指定
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 開發相關外掛
貢獻指南
- Fork 專案並建立 branch
- 撰寫或修改
src/下的程式 - 送出 PR 並描述變更重點
授權
此專案未指定授權(請視需求加入 LICENSE 檔)。
聯絡
若有問題或需求,請在 repository 中開 issue。
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.