Skip to main content
Glama

GitLab MCP 服务器

✨ 特点

  • 全面的 GitLab API 集成- 访问存储库、问题、合并请求、wiki 等

  • 支持两种传输方式- 与 stdio 或服务器发送事件 (SSE) 一起使用

  • 一致的响应格式——标准化的分页和响应结构

  • 强 TypeScript 类型- 使用 MCP SDK 构建以确保类型安全

  • 完整的文档——所有可用工具的示例

🔍 支持的操作

  • 存储库管理——搜索、创建、分叉存储库

  • 文件处理——读取、创建、更新文件

  • 分支运营——创建和管理分支

  • 问题跟踪- 创建、列出、过滤问题

  • 合并请求- 创建、列出、审查合并请求

  • 小组管理——列出小组项目和成员

  • 项目活动- 跟踪事件和提交历史记录

  • 维基管理——全面支持带有附件的项目和群组维基

  • 成员管理——列出并管理项目/小组成员

Related MCP server: gitlab mcp

🚀 入门

安装

来自 npm(推荐)

npm install @yoda.digital/gitlab-mcp-server

来自源

# Clone the repository
git clone https://github.com/yoda-digital/mcp-gitlab-server.git
cd mcp-gitlab-server

# Install dependencies
npm install

# Build the project
npm run build

配置

环境变量

服务器需要以下环境变量:

多变的

必需的

默认

描述

GITLAB_PERSONAL_ACCESS_TOKEN

是的

-

您的 GitLab 个人访问令牌

GITLAB_API_URL

https://gitlab.com/api/v4

GitLab API URL

PORT

3000

SSE运输港口

USE_SSE

false

设置为“true”以使用 SSE 传输

GITLAB_READ_ONLY_MODE

false

设置为“true”以启用只读模式(见下文)

只读模式

GITLAB_READ_ONLY_MODE设置为true时,服务器将仅公开读取操作。这对于不应具有 GitLab 资源写访问权限的客户端应用程序非常有用。在只读模式下,以下工具将可用:

  • search_repositories

  • get_file_contents

  • list_group_projects

  • get_project_events

  • list_commits

  • list_issues

  • list_merge_requests

  • list_project_wiki_pages

  • get_project_wiki_page

  • list_group_wiki_pages

  • get_group_wiki_page

  • list_project_members

  • list_group_members

在只读模式下,任何尝试使用写入操作(创建、更新、删除)都会导致错误。

MCP 设置配置

将 GitLab MCP 服务器添加到您的 MCP 设置文件:

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": ["-y", "@yoda.digital/gitlab-mcp-server"],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
        "GITLAB_API_URL": "https://gitlab.com/api/v4"
      },
      "alwaysAllow": [],
      "disabled": false
    }
  }
}

对于只读模式,添加GITLAB_READ_ONLY_MODE环境变量:

{
  "mcpServers": {
    "gitlab-readonly": {
      "command": "npx",
      "args": ["-y", "@yoda.digital/gitlab-mcp-server"],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
        "GITLAB_API_URL": "https://gitlab.com/api/v4",
        "GITLAB_READ_ONLY_MODE": "true"
      },
      "alwaysAllow": [],
      "disabled": false
    }
  }
}

用法

使用 stdio 传输(默认)

# Set your GitLab personal access token
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here

# Run the server
npm start

使用 SSE 传输

# Set your GitLab personal access token and enable SSE
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here
export GITLAB_READ_ONLY_MODE=false
export USE_SSE=true
export PORT=3000  # Optional, defaults to 3000

# Run the server
npm start

使用 npx

# Run directly with npx
GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here npx @yoda.digital/gitlab-mcp-server

🛠️ 可用工具

存储库操作

{
  "search": "project-name",
  "page": 1,
  "per_page": 20
}
{
  "name": "new-project",
  "description": "A new project",
  "visibility": "private",
  "initialize_with_readme": true
}
{
  "project_id": "username/project",
  "namespace": "target-namespace"
}
{
  "group_id": "group-name",
  "archived": false,
  "visibility": "public",
  "include_subgroups": true,
  "page": 1,
  "per_page": 20
}

文件操作

{
  "project_id": "username/project",
  "file_path": "path/to/file.txt",
  "ref": "main"
}
{
  "project_id": "username/project",
  "file_path": "path/to/file.txt",
  "content": "File content here",
  "commit_message": "Add/update file",
  "branch": "main",
  "previous_path": "old/path/to/file.txt"
}
{
  "project_id": "username/project",
  "files": [
    {
      "path": "file1.txt",
      "content": "Content for file 1"
    },
    {
      "path": "file2.txt",
      "content": "Content for file 2"
    }
  ],
  "commit_message": "Add multiple files",
  "branch": "main"
}

分支机构运营

{
  "project_id": "username/project",
  "branch": "new-branch",
  "ref": "main"
}

发行操作

{
  "project_id": "username/project",
  "title": "Issue title",
  "description": "Issue description",
  "assignee_ids": [1, 2],
  "milestone_id": 1,
  "labels": ["bug", "critical"]
}
{
  "project_id": "username/project",
  "state": "opened",
  "labels": "bug,critical",
  "milestone": "v1.0",
  "author_id": 1,
  "assignee_id": 2,
  "search": "keyword",
  "created_after": "2023-01-01T00:00:00Z",
  "created_before": "2023-12-31T23:59:59Z",
  "updated_after": "2023-06-01T00:00:00Z",
  "updated_before": "2023-06-30T23:59:59Z",
  "page": 1,
  "per_page": 20
}
{
  "project_id": "username/project",
  "issue_iid": 42,
  "sort": "desc",
  "order_by": "created_at",
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 15,
  "notes": [
    {
      "id": 123456,
      "body": "This is a comment on the issue",
      "author": {
        "id": 1,
        "username": "username",
        "name": "User Name"
      },
      "created_at": "2023-01-01T00:00:00Z",
      "updated_at": "2023-01-01T00:00:00Z",
      "system": false,
      "type": "comment"
    },
    {
      "id": 123457,
      "body": "added label ~bug",
      "author": {
        "id": 1,
        "username": "username",
        "name": "User Name"
      },
      "created_at": "2023-01-02T00:00:00Z",
      "updated_at": "2023-01-02T00:00:00Z",
      "system": true,
      "type": "system"
    }
    // ... other notes
  ]
}
{
  "project_id": "username/project",
  "issue_iid": 42,
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 5,
  "discussions": [
    {
      "id": "discussion-123",
      "individual_note": true,
      "notes": [
        {
          "id": 123456,
          "body": "This is a comment on the issue",
          "author": {
            "id": 1,
            "username": "username",
            "name": "User Name"
          },
          "created_at": "2023-01-01T00:00:00Z",
          "updated_at": "2023-01-01T00:00:00Z",
          "system": false,
          "type": "comment"
        }
      ]
    },
    {
      "id": "discussion-124",
      "individual_note": false,
      "notes": [
        {
          "id": 123457,
          "body": "This is a thread starter",
          "author": {
            "id": 1,
            "username": "username",
            "name": "User Name"
          },
          "created_at": "2023-01-02T00:00:00Z",
          "updated_at": "2023-01-02T00:00:00Z",
          "system": false,
          "type": "comment"
        },
        {
          "id": 123458,
          "body": "This is a reply in the thread",
          "author": {
            "id": 2,
            "username": "username2",
            "name": "User Name 2"
          },
          "created_at": "2023-01-03T00:00:00Z",
          "updated_at": "2023-01-03T00:00:00Z",
          "system": false,
          "type": "comment"
        }
      ]
    }
    // ... other discussions
  ]
}

合并请求操作

{
  "project_id": "username/project",
  "title": "Merge request title",
  "description": "Merge request description",
  "source_branch": "feature-branch",
  "target_branch": "main",
  "allow_collaboration": true,
  "draft": false
}
{
  "project_id": "username/project",
  "state": "opened",
  "order_by": "created_at",
  "sort": "desc",
  "milestone": "v1.0",
  "labels": "feature,enhancement",
  "created_after": "2023-01-01T00:00:00Z",
  "created_before": "2023-12-31T23:59:59Z",
  "updated_after": "2023-06-01T00:00:00Z",
  "updated_before": "2023-06-30T23:59:59Z",
  "author_id": 1,
  "assignee_id": 2,
  "search": "keyword",
  "source_branch": "feature-branch",
  "target_branch": "main",
  "page": 1,
  "per_page": 20
}

项目活动

{
  "project_id": "username/project",
  "action": "pushed",
  "target_type": "issue",
  "before": "2023-12-31T23:59:59Z",
  "after": "2023-01-01T00:00:00Z",
  "sort": "desc",
  "page": 1,
  "per_page": 20
}
{
  "project_id": "username/project",
  "sha": "branch-or-commit-sha",
  "path": "path/to/file",
  "since": "2023-01-01T00:00:00Z",
  "until": "2023-12-31T23:59:59Z",
  "all": true,
  "with_stats": true,
  "first_parent": true,
  "page": 1,
  "per_page": 20
}

会员运营

{
  "project_id": "username/project",
  "query": "search term",
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 3,
  "items": [
    {
      "id": 123,
      "username": "username",
      "name": "User Name",
      "state": "active",
      "avatar_url": "https://gitlab.com/avatar.png",
      "web_url": "https://gitlab.com/username",
      "access_level": 50,
      "access_level_description": "Owner"
    }
    // ... other members
  ]
}
{
  "group_id": "group-name",
  "query": "search term",
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 5,
  "items": [
    {
      "id": 456,
      "username": "username",
      "name": "User Name",
      "state": "active",
      "avatar_url": "https://gitlab.com/avatar.png",
      "web_url": "https://gitlab.com/username",
      "access_level": 30,
      "access_level_description": "Developer"
    }
    // ... other members
  ]
}

项目 Wiki 运营

{
  "project_id": "username/project",
  "with_content": false
}
{
  "project_id": "username/project",
  "slug": "page-slug",
  "render_html": false,
  "version": "commit-sha"
}
{
  "project_id": "username/project",
  "title": "Page Title",
  "content": "Wiki page content",
  "format": "markdown"
}
{
  "project_id": "username/project",
  "slug": "page-slug",
  "title": "New Page Title",
  "content": "Updated wiki page content",
  "format": "markdown"
}
{
  "project_id": "username/project",
  "slug": "page-slug"
}
{
  "project_id": "username/project",
  "file_path": "path/to/attachment.png",
  "content": "base64-encoded-content",
  "branch": "main"
}

小组 Wiki 运营

{
  "group_id": "group-name",
  "with_content": false
}
{
  "group_id": "group-name",
  "slug": "page-slug",
  "render_html": false,
  "version": "commit-sha"
}
{
  "group_id": "group-name",
  "title": "Page Title",
  "content": "Wiki page content",
  "format": "markdown"
}
{
  "group_id": "group-name",
  "slug": "page-slug",
  "title": "New Page Title",
  "content": "Updated wiki page content",
  "format": "markdown"
}
{
  "group_id": "group-name",
  "slug": "page-slug"
}
{
  "group_id": "group-name",
  "file_path": "path/to/attachment.png",
  "content": "base64-encoded-content",
  "branch": "main"
}

🔧 开发

要求

  • Node.js 16+

  • npm 7+

  • 具有个人访问令牌的 GitLab 帐户

构建项目

npm run build

运行测试

npm test

代码风格和 Linting

npm run lint

发布流程

  1. 更新package.json中的版本

  2. 更新 CHANGELOG.md

  3. 在 GitHub 上创建新版本

  4. 使用npm publish发布到 npm

📖 文档

如需更详细的文档,请访问我们的文档网站或查看源代码中的 TypeScript 定义。

💼 用例

  • 人工智能驱动的开发工作流程- 使人工智能助手能够与您的 GitLab 存储库进行交互

  • 自动化问题和 PR 管理- 利用 AI 支持简化开发流程

  • Wiki 管理- 自动更新文档和知识库管理

  • 团队协作——将 AI 助手集成到团队的 GitLab 工作流程中

📊 路线图

  • [ ] GitLab CI/CD 集成

  • [ ] 高级项目分析

  • [ ] 综合测试套件

  • [ ] 支持 GitLab GraphQL API

  • [ ] 扩展的 Webhook 支持

🤝 贡献

欢迎并感谢大家的贡献!贡献方式如下:

  1. 分叉存储库

  2. 创建你的功能分支( git checkout -b feature/amazing-feature

  3. 提交您的更改( git commit -m 'Add some amazing feature'

  4. 推送到分支( git push origin feature/amazing-feature

  5. 打开拉取请求

请确保适当更新测试并遵循项目的代码风格。

📝 许可证

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

👥 贡献者

感谢所有帮助改进此项目的贡献者:

特别感谢:

  • thomasleveil - 为项目和组实现了 GitLab 成员列表功能,并采用一致的响应格式

📦 NPM 包

该软件包可在 npm 上找到:
https://www.npmjs.com/package/@yoda.digital/gitlab-mcp-server

Latest Blog Posts

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/yoda-digital/mcp-gitlab-server'

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