diff --git a/servers/oeGitExt/README.md b/servers/oeGitExt/README.md index 0c9bbb9166b000f487857a2f99c18bfeb40b73f2..0e11de1b07d4540abd9e02bff9215cbade924d5a 100644 --- a/servers/oeGitExt/README.md +++ b/servers/oeGitExt/README.md @@ -4,13 +4,18 @@ oeGitExt 提供了管理 openEuler 社区 issue、repos、PR 和 project 的 MCP ## 1. 环境准备 -安装 python 依赖。为了更加直观,当前示例使用 `pip` 安装到系统的 python 目录,实际上更加推荐 `uv` 安装到虚拟环境。 +安装 python 依赖。为了更加直观,当前示例使用 `uv` 安装到虚拟环境: ```bash -pip install pydantic mcp requests gitpython --trusted-host mirrors.huaweicloud.com -i https://mirrors.huaweicloud.com/repository/pypi/simple +uv pip install pydantic mcp requests gitpython --trusted-host mirrors.huaweicloud.com -i https://mirrors.huaweicloud.com/repository/pypi/simple ``` -确保已安装 oegitext 命令行工具并配置好 openEuler 社区账号 +确保已安装 oegitext 命令行工具: + +```bash +oegitext --version +0.0.1 +``` ## 2. MCP 配置 @@ -19,13 +24,14 @@ pip install pydantic mcp requests gitpython --trusted-host mirrors.huaweicloud.c ```json { "mcpServers": { - "oeGitExt": { + "管理openEuler社区的issue,repos,pr,以及我的project": { "command": "uv", "args": [ "--directory", - "/your_path/mcp-servers/servers/oeGitExt/src", + "YOUR_PATH/mcp-servers/servers/oeGitExt/src", "run", - "oegitext_mcp.py" + "oegitext_mcp.py", + "--token=YOUR_GITEE_TOKEN" ], "disabled": false, "alwaysAllow": [ @@ -36,6 +42,11 @@ pip install pydantic mcp requests gitpython --trusted-host mirrors.huaweicloud.c } ``` +> **关于--token参数**: +> 这是Gitee的私人访问令牌(Personal Access Token),用于oeGitExt调用Gitee API进行认证。 +> 需要先在Gitee账号设置中创建令牌,并授予repo和user_info权限。 +> 令牌需要保密,不要直接提交到代码仓库中。 + 配置完成后,可以在 MCP 列表上看到 `oeGitExt` 服务,且状态正常。 > 如果出现报错,请根据提示信息检查 python 组件依赖是否满足。 @@ -47,7 +58,16 @@ oeGitExt 提供以下工具函数: 1. `get_my_openeuler_issue()` - 统计我在 openEuler 社区所负责的 issue 2. `get_my_openeuler_project()` - 查找我在 openEuler 社区的项目 3. `get_my_openeuler_pr(repo_type, repo_name)` - 查找我在 openEuler 对应仓库下的 PR + - `repo_type`: 仓库属性,有两种:制品仓:src-openeuler,源码仓:openeuler + - `repo_name`: 仓库名 4. `create_openeuler_pr(repo_type, repo_name, title, namespace, source_branch, base, body)` - 在 openEuler 社区仓库创建 PR + - `repo_type`: 仓库属性,有两种:制品仓:src-openeuler,源码仓:openeuler + - `repo_name`: 仓库名。如果未指定,则默认和本地仓库名相同 + - `title`: PR标题 + - `namespace`: Pull Request提交使用的源命名空间(一般是git用户名) + - `source_branch`: Pull Request提交的源分支 + - `base`: Pull Request提交目标分支的名称 + - `body`: PR描述(可选) ## 4. 使用示例 @@ -69,5 +89,3 @@ oeGitExt 提供以下工具函数: - 目标分支:master - 描述:版本新特性.. (可选) ``` - -MCP 会自动处理 PR 创建流程,包括检查源仓库是否存在、获取当前分支信息等。 \ No newline at end of file diff --git a/servers/oeGitExt/mcp_config.json b/servers/oeGitExt/mcp_config.json index ce664e9d79ba82fd39ed302e39e62fa780fc4d32..d8b5c20e8e5008743bb853dce48ae0974d786188 100644 --- a/servers/oeGitExt/mcp_config.json +++ b/servers/oeGitExt/mcp_config.json @@ -1,18 +1,18 @@ { - "mcpServers": { - "管理openEuler社区的issue,repos,pr,以及我的project": { - "command": "uv", - "args": [ - "--directory", - "/home/dev/mcp-servers/servers/oeGitExt/src", - "run", - "oegitext_mcp.py" - ], - "disabled": false, - "autoApprove": [], - "alwaysAllow": [ - "get_my_openeuler_project" - ] - } + "mcpServers": { + "管理openEuler社区的issue,repos,pr,以及我的project": { + "command": "uv", + "args": [ + "--directory", + "YOUR_PATH/mcp-servers/servers/oeGitExt/src", + "run", + "oegitext_mcp.py", + "--token=YOUR_GITEE_TOKEN" + ], + "disabled": false, + "alwaysAllow": [ + "get_my_openeuler_project" + ] } - } \ No newline at end of file + } +} diff --git a/servers/oeGitExt/src/oegitext_mcp.py b/servers/oeGitExt/src/oegitext_mcp.py index bf1663ef6ce13fb30b7206e4cf49ce251fe31f6a..e916ec2c828c34cb5b883d99f784a577c9a7e244 100644 --- a/servers/oeGitExt/src/oegitext_mcp.py +++ b/servers/oeGitExt/src/oegitext_mcp.py @@ -1,11 +1,36 @@ import subprocess import json +import argparse +from typing import Optional from pydantic import Field from mcp.server.fastmcp import FastMCP from git import Repo, Remote +# 在mcp初始化前添加参数解析 +parser = argparse.ArgumentParser() +parser.add_argument('--token', help='oegitext访问Gitee令牌') +args, _ = parser.parse_known_args() + mcp = FastMCP("管理openEuler社区的issue,repos,pr,以及我的project") +# 初始化oeGitExt,配置gitee私人令牌 +def configure_oegitext(token: Optional[str] = None): + """自动配置oegitext工具""" + try: + if token: + print(f"token: {token}") + subprocess.run( + ['oegitext', 'config', '-token', token], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + else: + print("未检测到token参数,请确保本地已预先配置") + except subprocess.CalledProcessError as e: + print(f"Token配置失败: {e.stderr.decode()}") + + @mcp.tool() def get_my_openeuler_issue() -> dict: """统计我在openEuler社区所负责的issue""" @@ -25,16 +50,19 @@ def get_my_openeuler_issue() -> dict: def get_my_openeuler_project() -> dict: """查找我在openEuler社区的项目""" try: - # 执行oegitext命令并解析JSON结果 - result = subprocess.check_output(['oegitext', 'show', 'proj', '-p'], - text=True, + # 先配置token + configure_oegitext(args.token) + + # 执行oegitext命令并获取结果 + result = subprocess.check_output(['oegitext', 'show', 'proj', '-p'], + text=True, stderr=subprocess.STDOUT) return result except subprocess.CalledProcessError as e: - return e + return {"error": e.output} except Exception as e: - return e + return {"error": str(e)} @mcp.tool() def get_my_openeuler_pr(repo_type:str = Field(description="仓库属性,有两种:制品仓:src-openeuler,源码仓:openeuler"), @@ -99,7 +127,9 @@ def create_openeuler_pr( except Exception as e: return {"error": str(e)} - if __name__ == "__main__": + # 配置oegitext的token,用于访问Gitee + configure_oegitext(args.token) + # Initialize and run the server mcp.run()