Harbor容器注册表MCP服务器

MCP Harbor是一个Node.js应用程序,提供用于与Harbor容器注册表交互的模型上下文协议(MCP)服务器。

  • by nomagicln
  • TypeScript
  • 本地部署
  • 7 星标
  • 更新于
在 GitHub 查看 nomagicln/mcp-harbor

使用说明

MCP港口

MCP Harbor是一个Node.js应用程序,它提供了一个模型上下文协议(MCP)服务器,用于与Harbor容器注册表进行交互。

目录

特性

  • MCP服务器:公开通过模型上下文协议与Harbor交互的工具
  • 港口运营:支持项目、存储库、标签和Helm图表的操作
  • TypeScript:用TypeScript编写,以获得更好的类型安全性和开发人员体验
  • 自动化测试:功能可靠的综合测试套件

先决条件

安装MCP Harbor之前,请确保:

  • Node.js 18.x或更高版本
  • npm 8.x或更高版本
  • 访问Harbor注册表实例
  • Git(用于克隆存储库)

安装

  1. 克隆存储库:

    git clone https://github.com/nomagicln/mcp-harbor.git
    
  2. 导航到项目目录:

    cd mcp-harbor
    
  3. 安装依赖项:

    npm install
    
  4. 构建项目:

    npm run build
    

用法

命令行参数

应用程序接受以下命令行参数:

Options:
  --url       Harbor API URL                     [string] [required]
  --username  Harbor username                    [string] [required]
  --password  Harbor password                    [string] [required]
  --debug     Enable debug mode          [boolean] [default: false]
  --help      Show help                                  [boolean]

环境变量

除了命令行参数,您还可以使用环境变量。创建一个 .env 根目录中的文件:

# Harbor API Configuration
HARBOR_URL=https://harbor.example.com
HARBOR_USERNAME=admin
HARBOR_PASSWORD=Harbor12345

# Debug Mode (true/false)
DEBUG=false

MCP工具

MCP服务器公开了以下工具:

工具名称 描述 参数
list_projects 列出Harbor中的所有项目 无
get_project 按ID获取项目详细信息 projectId: string
create_project 创建新项目 project_name: string, metadata?: object
delete_project 删除项目 projectId: string
list_repositories 列出项目中的存储库 projectId: string
delete_repository 删除存储库 projectId: string, repositoryName: string
list_tags 列出存储库中的标签 projectId: string, repositoryName: string
delete_tag 删除标签 projectId: string, repositoryName: string, tag: string
list_charts 列出Helm图表 projectId: string
list_chart_versions 列出图表版本 projectId: string, chartName: string
delete_chart 删除图表版本 projectId: string, chartName: string, version: string

发展

以开发模式运行

npm run dev

运行测试

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

项目结构

mcp-harbor
├── src
│   ├── app.ts                 # Main application entry point (MCP server)
│   ├── definitions
│   │   └── tool.definitions.ts # Tool definitions for MCP
│   ├── services
│   │   └── harbor.service.ts  # Harbor service implementation
│   └── types
│       └── index.ts           # TypeScript type definitions
├── test
│   └── harbor.test.ts         # Tests for Harbor service
├── .env.example              # Example environment variables
├── .gitignore               # Git ignore file
├── .eslintrc.json           # ESLint configuration
├── package.json            # Project dependencies
├── jest.config.js           # Jest configuration
├── tsconfig.test.json      # TypeScript configuration for tests
├── tsconfig.json          # TypeScript configuration
├── LICENSE                # Project license
└── README.md             # Project documentation

故障排除

常见问题

  1. 连接失败

    Error: Unable to connect to Harbor instance
    
    • 验证HARBOR_URL是否正确且可访问
    • 检查网络连接
    • 确保Harbor实例正在运行
  2. 认证失败

    Error: Invalid credentials
    
    • 验证HARBOR_USERNAME和HARBOR_PASSWORD是否正确
    • 检查用户是否具有所需的权限
  3. 构建错误

    Error: TypeScript compilation failed
    
    • 跑 npm install 确保所有依赖项都已安装
    • 检查TypeScript版本兼容性
    • 清除 dist 目录和重建

调试模式

使用启用调试模式 --debug 标志或设置:

DEBUG=true

支持

如需更多帮助:

  1. 查看应用程序日志

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。