Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfc1ff17da |
@@ -19,10 +19,10 @@ jobs:
|
|||||||
fetch-depth: 0 # all history for all branches and tags
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4
|
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4
|
||||||
|
|
||||||
- name: Set up Docker BuildX
|
- name: Set up Docker BuildX
|
||||||
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
||||||
|
|||||||
@@ -63,10 +63,10 @@ jobs:
|
|||||||
fetch-depth: 0 # all history for all branches and tags
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4
|
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4
|
||||||
|
|
||||||
- name: Set up Docker BuildX
|
- name: Set up Docker BuildX
|
||||||
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
||||||
|
|||||||
+2
-3
@@ -74,7 +74,7 @@ linters:
|
|||||||
arguments:
|
arguments:
|
||||||
- [] # AllowList - do not remove as args for the rule are positional and won't work without lists first
|
- [] # AllowList - do not remove as args for the rule are positional and won't work without lists first
|
||||||
- [] # DenyList
|
- [] # DenyList
|
||||||
- - skip-initialism-name-checks: true
|
- - skip-package-name-checks: true
|
||||||
staticcheck:
|
staticcheck:
|
||||||
checks:
|
checks:
|
||||||
- all
|
- all
|
||||||
@@ -110,8 +110,7 @@ formatters:
|
|||||||
- blank
|
- blank
|
||||||
- default
|
- default
|
||||||
gofumpt:
|
gofumpt:
|
||||||
extra:
|
extra-rules: true
|
||||||
group-params: true
|
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
generated: lax
|
||||||
run:
|
run:
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ This project includes PowerShell and batch scripts to build the gitea-mcp applic
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Go 1.27 or later
|
- Go 1.26 or later
|
||||||
- Git (for version information)
|
- Git (for version information)
|
||||||
- PowerShell 5.1 or later (included with Windows 10/11)
|
- PowerShell 5.1 or later (included with Windows 10/11)
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -1,7 +1,7 @@
|
|||||||
# syntax=docker/dockerfile:1.27
|
# syntax=docker/dockerfile:1.26
|
||||||
|
|
||||||
# Build stage
|
# Build stage
|
||||||
FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS builder
|
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
@@ -32,7 +32,4 @@ USER nonroot:nonroot
|
|||||||
LABEL org.opencontainers.image.version="${VERSION}"
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
LABEL org.opencontainers.image.source="https://gitea.com/gitea/gitea-mcp"
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/gitea-mcp"
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
||||||
CMD ["/app/gitea-mcp", "-healthcheck"] || exit 1
|
|
||||||
|
|
||||||
CMD ["/app/gitea-mcp"]
|
CMD ["/app/gitea-mcp"]
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ EXECUTABLE := gitea-mcp
|
|||||||
VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
||||||
LDFLAGS := -X "main.Version=$(VERSION)"
|
LDFLAGS := -X "main.Version=$(VERSION)"
|
||||||
|
|
||||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2 # renovate: datasource=go
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 # renovate: datasource=go
|
||||||
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.8.0 # renovate: datasource=go
|
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.6.0 # renovate: datasource=go
|
||||||
|
|
||||||
GOTEST_FLAGS ?= -race -timeout 20m
|
GOTEST_FLAGS ?= -race -timeout 20m
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Download a binary from the [releases page](https://gitea.com/gitea/gitea-mcp/releases) and put it in your `PATH`, use the `docker.gitea.com/gitea-mcp-server` image, or build from source into `$GOPATH/bin` with `make` and Go 1.27 or later:
|
Download a binary from the [releases page](https://gitea.com/gitea/gitea-mcp/releases) and put it in your `PATH`, use the `docker.gitea.com/gitea-mcp-server` image, or build from source into `$GOPATH/bin` with `make` and Go 1.26 or later:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||||
@@ -26,8 +26,6 @@ The server supports MCP up to `2026-07-28` and negotiates down to the client's v
|
|||||||
|
|
||||||
HTTP is always stateless: `/mcp` accepts POST only, without `Mcp-Session-Id`, standalone SSE or `Last-Event-ID` resumability. Origins are validated, and reverse proxies must forward `Mcp-Protocol-Version`, `Mcp-Method` and `Mcp-Name` unchanged. `Authorization: Bearer <token>` and `Authorization: token <token>` pass a Gitea credential per request, which is credential passthrough rather than MCP OAuth.
|
HTTP is always stateless: `/mcp` accepts POST only, without `Mcp-Session-Id`, standalone SSE or `Last-Event-ID` resumability. Origins are validated, and reverse proxies must forward `Mcp-Protocol-Version`, `Mcp-Method` and `Mcp-Name` unchanged. `Authorization: Bearer <token>` and `Authorization: token <token>` pass a Gitea credential per request, which is credential passthrough rather than MCP OAuth.
|
||||||
|
|
||||||
HTTP mode also serves `/healthz`, which returns `200 OK` when the server is up. The Docker image's built-in `HEALTHCHECK` runs `gitea-mcp -healthcheck`, which dials `http://127.0.0.1:<port>/healthz` using the same `-p`/`-port` value (or `8080` by default) and exits `0` on success or `1` on failure. Stdio deployments do not serve `/healthz`, so override or disable the image's `HEALTHCHECK` when running in stdio mode.
|
|
||||||
|
|
||||||
### Claude Code
|
### Claude Code
|
||||||
|
|
||||||
Runs the server through `go run` and requires [Go](https://go.dev):
|
Runs the server through `go run` and requires [Go](https://go.dev):
|
||||||
@@ -160,8 +158,8 @@ Once configured, try `list all my repositories` in the chat box.
|
|||||||
| package_write | packages | Write | Delete a package version (irreversible) |
|
| package_write | packages | Write | Delete a package version (irreversible) |
|
||||||
| list_issues | issue | Read | List repository issues |
|
| list_issues | issue | Read | List repository issues |
|
||||||
| attachment_read | issue | Read | Read issue/comment attachments: list metadata, get metadata, or download content |
|
| attachment_read | issue | Read | Read issue/comment attachments: list metadata, get metadata, or download content |
|
||||||
| issue_read | issue | Read | Read issue: details, comments, labels, or blocking relationships |
|
| issue_read | issue | Read | Read issue: details, comments, or labels |
|
||||||
| issue_write | issue | Write | Write issues: create, update, manage comments, labels, and blocking relationships |
|
| issue_write | issue | Write | Write issues: create, update, manage comments and labels |
|
||||||
| list_pull_requests | pull_request | Read | List repository pull requests |
|
| list_pull_requests | pull_request | Read | List repository pull requests |
|
||||||
| pull_request_read | pull_request | Read | Read pull request: details, diff, files, status, reviews, review comments |
|
| pull_request_read | pull_request | Read | Read pull request: details, diff, files, status, reviews, review comments |
|
||||||
| pull_request_write | pull_request | Write | Write pull requests: create, update, close, reopen, merge, update branch, manage reviewers |
|
| pull_request_write | pull_request | Write | Write pull requests: create, update, close, reopen, merge, update branch, manage reviewers |
|
||||||
@@ -182,7 +180,6 @@ Once configured, try `list all my repositories` in the chat box.
|
|||||||
| create_branch | branch | Write | Create a new branch |
|
| create_branch | branch | Write | Create a new branch |
|
||||||
| delete_branch | branch | Write | Delete a branch |
|
| delete_branch | branch | Write | Delete a branch |
|
||||||
| list_branches | branch | Read | List repository branches |
|
| list_branches | branch | Read | List repository branches |
|
||||||
| rename_branch | branch | Write | Rename a branch |
|
|
||||||
| create_tag | tag | Write | Create a tag |
|
| create_tag | tag | Write | Create a tag |
|
||||||
| delete_tag | tag | Write | Delete a tag |
|
| delete_tag | tag | Write | Delete a tag |
|
||||||
| get_tag | tag | Read | Get tag details |
|
| get_tag | tag | Read | Get tag details |
|
||||||
|
|||||||
+3
-6
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
可从 [发布页面](https://gitea.com/gitea/gitea-mcp/releases) 下载二进制文件并放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 镜像,也可用 `make` 和 Go 1.27 及以上从源码构建到 `$GOPATH/bin`:
|
可从 [发布页面](https://gitea.com/gitea/gitea-mcp/releases) 下载二进制文件并放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 镜像,也可用 `make` 和 Go 1.26 及以上从源码构建到 `$GOPATH/bin`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||||
@@ -26,8 +26,6 @@ Gitea 主机和访问令牌可通过命令行参数或环境变量提供,命
|
|||||||
|
|
||||||
HTTP 传输固定为无状态:`/mcp` 仅接受 POST,没有 `Mcp-Session-Id`、独立 SSE 和 `Last-Event-ID` 断点续传。服务器会验证来源,反向代理必须原样转发 `Mcp-Protocol-Version`、`Mcp-Method` 和 `Mcp-Name`。`Authorization: Bearer <令牌>` 和 `Authorization: token <令牌>` 会在每个请求中传递 Gitea 凭据,这是凭据透传,而不是 MCP OAuth。
|
HTTP 传输固定为无状态:`/mcp` 仅接受 POST,没有 `Mcp-Session-Id`、独立 SSE 和 `Last-Event-ID` 断点续传。服务器会验证来源,反向代理必须原样转发 `Mcp-Protocol-Version`、`Mcp-Method` 和 `Mcp-Name`。`Authorization: Bearer <令牌>` 和 `Authorization: token <令牌>` 会在每个请求中传递 Gitea 凭据,这是凭据透传,而不是 MCP OAuth。
|
||||||
|
|
||||||
HTTP 模式还提供 `/healthz` 端点,服务器正常运行时返回 `200 OK`。Docker 镜像内置的 `HEALTHCHECK` 会运行 `gitea-mcp -healthcheck`,它使用与 `-p`/`-port` 相同的端口(默认 `8080`)请求 `http://127.0.0.1:<端口>/healthz`,成功时退出码为 `0`,失败时为 `1`。stdio 部署不提供 `/healthz`,因此在 stdio 模式下运行时应覆盖或禁用镜像自带的 `HEALTHCHECK`。
|
|
||||||
|
|
||||||
### Claude Code
|
### Claude Code
|
||||||
|
|
||||||
通过 `go run` 运行服务器,需要安装 [Go](https://go.dev):
|
通过 `go run` 运行服务器,需要安装 [Go](https://go.dev):
|
||||||
@@ -160,8 +158,8 @@ Cursor 等客户端可使用 stdio 命令:
|
|||||||
| package_write | packages | 写入 | 删除软件包版本(不可恢复) |
|
| package_write | packages | 写入 | 删除软件包版本(不可恢复) |
|
||||||
| list_issues | issue | 读取 | 列出仓库问题 |
|
| list_issues | issue | 读取 | 列出仓库问题 |
|
||||||
| attachment_read | issue | 读取 | 读取问题/评论附件:列出元数据、获取元数据或下载内容 |
|
| attachment_read | issue | 读取 | 读取问题/评论附件:列出元数据、获取元数据或下载内容 |
|
||||||
| issue_read | issue | 读取 | 读取问题:详情、评论、标签或阻塞关系 |
|
| issue_read | issue | 读取 | 读取问题:详情、评论或标签 |
|
||||||
| issue_write | issue | 写入 | 写入问题:创建、更新、管理评论、标签和阻塞关系 |
|
| issue_write | issue | 写入 | 写入问题:创建、更新、管理评论和标签 |
|
||||||
| list_pull_requests | pull_request | 读取 | 列出仓库拉取请求 |
|
| list_pull_requests | pull_request | 读取 | 列出仓库拉取请求 |
|
||||||
| pull_request_read | pull_request | 读取 | 读取拉取请求:详情、差异、变更文件、头部提交状态、审查、审查评论 |
|
| pull_request_read | pull_request | 读取 | 读取拉取请求:详情、差异、变更文件、头部提交状态、审查、审查评论 |
|
||||||
| pull_request_write | pull_request | 写入 | 写入拉取请求:创建、更新、关闭、重新打开、合并、更新分支、管理审查者 |
|
| pull_request_write | pull_request | 写入 | 写入拉取请求:创建、更新、关闭、重新打开、合并、更新分支、管理审查者 |
|
||||||
@@ -182,7 +180,6 @@ Cursor 等客户端可使用 stdio 命令:
|
|||||||
| create_branch | branch | 写入 | 创建新分支 |
|
| create_branch | branch | 写入 | 创建新分支 |
|
||||||
| delete_branch | branch | 写入 | 删除分支 |
|
| delete_branch | branch | 写入 | 删除分支 |
|
||||||
| list_branches | branch | 读取 | 列出仓库分支 |
|
| list_branches | branch | 读取 | 列出仓库分支 |
|
||||||
| rename_branch | branch | 写入 | 重命名分支 |
|
|
||||||
| create_tag | tag | 写入 | 创建标签 |
|
| create_tag | tag | 写入 | 创建标签 |
|
||||||
| delete_tag | tag | 写入 | 删除标签 |
|
| delete_tag | tag | 写入 | 删除标签 |
|
||||||
| get_tag | tag | 读取 | 获取标签详情 |
|
| get_tag | tag | 读取 | 获取标签详情 |
|
||||||
|
|||||||
+3
-6
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
## 安裝
|
## 安裝
|
||||||
|
|
||||||
可從 [發布頁面](https://gitea.com/gitea/gitea-mcp/releases) 下載二進位檔並放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 映像檔,也可用 `make` 與 Go 1.27 以上從原始碼建置到 `$GOPATH/bin`:
|
可從 [發布頁面](https://gitea.com/gitea/gitea-mcp/releases) 下載二進位檔並放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 映像檔,也可用 `make` 與 Go 1.26 以上從原始碼建置到 `$GOPATH/bin`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||||
@@ -26,8 +26,6 @@ Gitea 主機與存取令牌可透過命令列參數或環境變數提供,命
|
|||||||
|
|
||||||
HTTP 傳輸固定為無狀態:`/mcp` 只接受 POST,沒有 `Mcp-Session-Id`、獨立 SSE 與 `Last-Event-ID` 斷點續傳。伺服器會驗證來源,反向代理必須原樣轉發 `Mcp-Protocol-Version`、`Mcp-Method` 與 `Mcp-Name`。`Authorization: Bearer <令牌>` 與 `Authorization: token <令牌>` 會在每次請求中傳遞 Gitea 憑證,這是憑證透傳,而不是 MCP OAuth。
|
HTTP 傳輸固定為無狀態:`/mcp` 只接受 POST,沒有 `Mcp-Session-Id`、獨立 SSE 與 `Last-Event-ID` 斷點續傳。伺服器會驗證來源,反向代理必須原樣轉發 `Mcp-Protocol-Version`、`Mcp-Method` 與 `Mcp-Name`。`Authorization: Bearer <令牌>` 與 `Authorization: token <令牌>` 會在每次請求中傳遞 Gitea 憑證,這是憑證透傳,而不是 MCP OAuth。
|
||||||
|
|
||||||
HTTP 模式也會提供 `/healthz` 端點,伺服器正常運作時回傳 `200 OK`。Docker 映像內建的 `HEALTHCHECK` 會執行 `gitea-mcp -healthcheck`,它使用與 `-p`/`-port` 相同的連接埠(預設 `8080`)連線 `http://127.0.0.1:<連接埠>/healthz`,成功時結束碼為 `0`,失敗時為 `1`。stdio 部署不會提供 `/healthz`,因此在 stdio 模式下運作時應覆寫或停用映像內建的 `HEALTHCHECK`。
|
|
||||||
|
|
||||||
### Claude Code
|
### Claude Code
|
||||||
|
|
||||||
透過 `go run` 執行伺服器,需要安裝 [Go](https://go.dev):
|
透過 `go run` 執行伺服器,需要安裝 [Go](https://go.dev):
|
||||||
@@ -160,8 +158,8 @@ Cursor 等客戶端可使用 stdio 命令:
|
|||||||
| package_write | packages | 寫入 | 刪除軟體套件版本(不可復原) |
|
| package_write | packages | 寫入 | 刪除軟體套件版本(不可復原) |
|
||||||
| list_issues | issue | 讀取 | 列出倉庫問題 |
|
| list_issues | issue | 讀取 | 列出倉庫問題 |
|
||||||
| attachment_read | issue | 讀取 | 讀取問題/評論附件:列出中繼資料、取得中繼資料或下載內容 |
|
| attachment_read | issue | 讀取 | 讀取問題/評論附件:列出中繼資料、取得中繼資料或下載內容 |
|
||||||
| issue_read | issue | 讀取 | 讀取問題:詳情、評論、標籤或阻塞關係 |
|
| issue_read | issue | 讀取 | 讀取問題:詳情、評論或標籤 |
|
||||||
| issue_write | issue | 寫入 | 寫入問題:創建、更新、管理評論、標籤和阻塞關係 |
|
| issue_write | issue | 寫入 | 寫入問題:創建、更新、管理評論和標籤 |
|
||||||
| list_pull_requests | pull_request | 讀取 | 列出倉庫拉取請求 |
|
| list_pull_requests | pull_request | 讀取 | 列出倉庫拉取請求 |
|
||||||
| pull_request_read | pull_request | 讀取 | 讀取拉取請求:詳情、差異、變更檔案、頭部提交狀態、審查、審查評論 |
|
| pull_request_read | pull_request | 讀取 | 讀取拉取請求:詳情、差異、變更檔案、頭部提交狀態、審查、審查評論 |
|
||||||
| pull_request_write | pull_request | 寫入 | 寫入拉取請求:創建、更新、關閉、重新開啟、合併、更新分支、管理審查者 |
|
| pull_request_write | pull_request | 寫入 | 寫入拉取請求:創建、更新、關閉、重新開啟、合併、更新分支、管理審查者 |
|
||||||
@@ -182,7 +180,6 @@ Cursor 等客戶端可使用 stdio 命令:
|
|||||||
| create_branch | branch | 寫入 | 創建新分支 |
|
| create_branch | branch | 寫入 | 創建新分支 |
|
||||||
| delete_branch | branch | 寫入 | 刪除分支 |
|
| delete_branch | branch | 寫入 | 刪除分支 |
|
||||||
| list_branches | branch | 讀取 | 列出倉庫分支 |
|
| list_branches | branch | 讀取 | 列出倉庫分支 |
|
||||||
| rename_branch | branch | 寫入 | 重新命名分支 |
|
|
||||||
| create_tag | tag | 寫入 | 創建標籤 |
|
| create_tag | tag | 寫入 | 創建標籤 |
|
||||||
| delete_tag | tag | 寫入 | 刪除標籤 |
|
| delete_tag | tag | 寫入 | 刪除標籤 |
|
||||||
| get_tag | tag | 讀取 | 取得標籤詳情 |
|
| get_tag | tag | 讀取 | 取得標籤詳情 |
|
||||||
|
|||||||
-13
@@ -5,7 +5,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -24,11 +23,9 @@ var (
|
|||||||
tools string
|
tools string
|
||||||
scopes string
|
scopes string
|
||||||
version bool
|
version bool
|
||||||
healthcheck bool
|
|
||||||
maxInlineAttachmentBytes int
|
maxInlineAttachmentBytes int
|
||||||
maxInlineAttachmentBytesFlagSet bool
|
maxInlineAttachmentBytesFlagSet bool
|
||||||
osExit = os.Exit
|
osExit = os.Exit
|
||||||
healthcheckClient = http.DefaultClient
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func initFlagSet(fs *flag.FlagSet, args []string, getenv func(string) string, readFile func(string) ([]byte, error), stderr io.Writer) {
|
func initFlagSet(fs *flag.FlagSet, args []string, getenv func(string) string, readFile func(string) ([]byte, error), stderr io.Writer) {
|
||||||
@@ -56,7 +53,6 @@ func initFlagSet(fs *flag.FlagSet, args []string, getenv func(string) string, re
|
|||||||
fs.BoolVar(&flagPkg.Insecure, "insecure", false, "")
|
fs.BoolVar(&flagPkg.Insecure, "insecure", false, "")
|
||||||
fs.BoolVar(&version, "v", false, "")
|
fs.BoolVar(&version, "v", false, "")
|
||||||
fs.BoolVar(&version, "version", false, "")
|
fs.BoolVar(&version, "version", false, "")
|
||||||
fs.BoolVar(&healthcheck, "healthcheck", false, "")
|
|
||||||
maxInlineAttachmentBytes = 5 * 1024 * 1024
|
maxInlineAttachmentBytes = 5 * 1024 * 1024
|
||||||
fs.Func("max-inline-attachment-bytes", "", func(val string) error {
|
fs.Func("max-inline-attachment-bytes", "", func(val string) error {
|
||||||
parsed, err := strconv.Atoi(val)
|
parsed, err := strconv.Atoi(val)
|
||||||
@@ -85,7 +81,6 @@ func initFlagSet(fs *flag.FlagSet, args []string, getenv func(string) string, re
|
|||||||
fmt.Fprintf(w, " -k, -insecure\tIgnore TLS certificate errors\n")
|
fmt.Fprintf(w, " -k, -insecure\tIgnore TLS certificate errors\n")
|
||||||
fmt.Fprintf(w, " -max-inline-attachment-bytes <bytes>\tInline image attachments up to this size (default: 5242880)\n")
|
fmt.Fprintf(w, " -max-inline-attachment-bytes <bytes>\tInline image attachments up to this size (default: 5242880)\n")
|
||||||
fmt.Fprintf(w, " -v, -version\tPrint version and exit\n")
|
fmt.Fprintf(w, " -v, -version\tPrint version and exit\n")
|
||||||
fmt.Fprintf(w, " -healthcheck\tCheck a running HTTP server's /healthz endpoint and exit\n")
|
|
||||||
fmt.Fprintln(w)
|
fmt.Fprintln(w)
|
||||||
fmt.Fprintln(w, "Environment variables:")
|
fmt.Fprintln(w, "Environment variables:")
|
||||||
fmt.Fprintf(w, " GITEA_ACCESS_TOKEN\tProvide access token\n")
|
fmt.Fprintf(w, " GITEA_ACCESS_TOKEN\tProvide access token\n")
|
||||||
@@ -188,14 +183,6 @@ func Execute() {
|
|||||||
fmt.Fprintln(os.Stdout, flagPkg.Version)
|
fmt.Fprintln(os.Stdout, flagPkg.Version)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if healthcheck {
|
|
||||||
if runHealthcheck(healthcheckClient, flagPkg.Port, os.Stdout, os.Stderr) {
|
|
||||||
osExit(0)
|
|
||||||
} else {
|
|
||||||
osExit(1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := operation.Run(); err != nil {
|
if err := operation.Run(); err != nil {
|
||||||
if err == context.Canceled {
|
if err == context.Canceled {
|
||||||
log.Info("Server shutdown due to context cancellation")
|
log.Info("Server shutdown due to context cancellation")
|
||||||
|
|||||||
@@ -95,12 +95,3 @@ func TestInitFlagSetScopes(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitFlagSetHealthcheck(t *testing.T) {
|
|
||||||
t.Cleanup(func() { healthcheck = false })
|
|
||||||
fs := flag.NewFlagSet("test", flag.ContinueOnError)
|
|
||||||
initFlagSet(fs, []string{"-healthcheck"}, func(string) string { return "" }, func(string) ([]byte, error) { return nil, nil }, &bytes.Buffer{})
|
|
||||||
if !healthcheck {
|
|
||||||
t.Error("healthcheck = false, want true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// runHealthcheck dials the /healthz endpoint on 127.0.0.1:port and reports
|
|
||||||
// success or failure. It returns true when the server responds with a 2xx
|
|
||||||
// status.
|
|
||||||
func runHealthcheck(client *http.Client, port int, stdout, stderr io.Writer) bool {
|
|
||||||
url := fmt.Sprintf("http://127.0.0.1:%d/healthz", port)
|
|
||||||
|
|
||||||
resp, err := client.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(stderr, "healthcheck failed: %v\n", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
|
||||||
fmt.Fprintf(stderr, "healthcheck failed: unexpected status %s\n", resp.Status)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintln(stdout, "healthy")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRunHealthcheck(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
handler http.HandlerFunc
|
|
||||||
port func(server *httptest.Server) int
|
|
||||||
wantOK bool
|
|
||||||
wantStdout string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "server responds 200 OK",
|
|
||||||
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
},
|
|
||||||
port: serverPort,
|
|
||||||
wantOK: true,
|
|
||||||
wantStdout: "healthy",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "server responds with an error status",
|
|
||||||
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
},
|
|
||||||
port: serverPort,
|
|
||||||
wantOK: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "nothing listening on the port",
|
|
||||||
port: func(*httptest.Server) int { return 1 },
|
|
||||||
wantOK: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
var server *httptest.Server
|
|
||||||
if tt.handler != nil {
|
|
||||||
server = httptest.NewServer(tt.handler)
|
|
||||||
defer server.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
var stdout, stderr bytes.Buffer
|
|
||||||
ok := runHealthcheck(http.DefaultClient, tt.port(server), &stdout, &stderr)
|
|
||||||
|
|
||||||
if ok != tt.wantOK {
|
|
||||||
t.Errorf("runHealthcheck() = %v, want %v", ok, tt.wantOK)
|
|
||||||
}
|
|
||||||
if tt.wantStdout != "" && !strings.Contains(stdout.String(), tt.wantStdout) {
|
|
||||||
t.Errorf("stdout = %q, want it to contain %q", stdout.String(), tt.wantStdout)
|
|
||||||
}
|
|
||||||
if tt.wantOK && stderr.Len() != 0 {
|
|
||||||
t.Errorf("stderr = %q, want empty on success", stderr.String())
|
|
||||||
}
|
|
||||||
if !tt.wantOK && stderr.Len() == 0 {
|
|
||||||
t.Error("stderr is empty, want a failure message")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func serverPort(server *httptest.Server) int {
|
|
||||||
_, portStr, err := net.SplitHostPort(server.Listener.Addr().String())
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
port, err := strconv.Atoi(portStr)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return port
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
module gitea.com/gitea/gitea-mcp
|
module gitea.com/gitea/gitea-mcp
|
||||||
|
|
||||||
go 1.27
|
go 1.26.0
|
||||||
|
|
||||||
toolchain go1.27.1
|
toolchain go1.26.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.dev/sdk v1.2.0
|
gitea.dev/sdk v1.2.0
|
||||||
@@ -17,14 +17,14 @@ require (
|
|||||||
github.com/davidmz/go-pageant v1.0.2 // indirect
|
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||||
github.com/google/jsonschema-go v0.4.3 // indirect
|
github.com/google/jsonschema-go v0.4.3 // indirect
|
||||||
github.com/hashicorp/go-version v1.9.0 // indirect
|
github.com/hashicorp/go-version v1.9.0 // indirect
|
||||||
github.com/segmentio/asm v1.2.1 // indirect
|
github.com/segmentio/asm v1.1.3 // indirect
|
||||||
github.com/segmentio/encoding v0.5.4 // indirect
|
github.com/segmentio/encoding v0.5.4 // indirect
|
||||||
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
|
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/crypto v0.56.0 // indirect
|
golang.org/x/crypto v0.54.0 // indirect
|
||||||
golang.org/x/oauth2 v0.36.0 // indirect
|
golang.org/x/oauth2 v0.35.0 // indirect
|
||||||
golang.org/x/sync v0.22.0 // indirect
|
golang.org/x/sync v0.22.0 // indirect
|
||||||
golang.org/x/sys v0.47.0 // indirect
|
golang.org/x/sys v0.47.0 // indirect
|
||||||
golang.org/x/time v0.15.0 // indirect
|
golang.org/x/time v0.15.0 // indirect
|
||||||
golang.org/x/tools v0.49.0 // indirect
|
golang.org/x/tools v0.47.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ github.com/modelcontextprotocol/go-sdk v1.7.0 h1:yqjY2dsbKAC0LSuWZVBMrHgiG8ukXv6
|
|||||||
github.com/modelcontextprotocol/go-sdk v1.7.0/go.mod h1:dL7u98E/zjJTGzEq+j30jQ8K2k1mb6LeAH4inEcSGts=
|
github.com/modelcontextprotocol/go-sdk v1.7.0/go.mod h1:dL7u98E/zjJTGzEq+j30jQ8K2k1mb6LeAH4inEcSGts=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0=
|
github.com/segmentio/asm v1.1.3 h1:WM03sfUOENvvKexOLp+pCqgb/WDjsi7EK8gIsICtzhc=
|
||||||
github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
|
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
|
||||||
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
|
github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0=
|
||||||
github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
|
github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
@@ -37,11 +37,11 @@ go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ
|
|||||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||||
golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y=
|
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
|
||||||
golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I=
|
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
|
||||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||||
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
||||||
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -54,8 +54,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|||||||
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
||||||
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
|
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
|
||||||
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
|
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func listRepoActionSecretsFn(ctx context.Context, args map[string]any) (*mcp.Cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
secrets, _, err := client.Actions.ListRepoSecrets(ctx, owner, repo, gitea_sdk.ListRepoActionsSecretOption{
|
secrets, _, err := client.Actions.ListRepoSecrets(ctx, owner, repo, gitea_sdk.ListRepoActionsSecretOption{
|
||||||
Page: page, PageSize: pageSize,
|
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: pageSize},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list repo action secrets err: %v", err))
|
return to.ErrorResult(fmt.Errorf("list repo action secrets err: %v", err))
|
||||||
@@ -228,7 +228,7 @@ func listOrgActionSecretsFn(ctx context.Context, args map[string]any) (*mcp.Call
|
|||||||
}
|
}
|
||||||
|
|
||||||
secrets, _, err := client.Actions.ListOrgSecrets(ctx, org, gitea_sdk.ListOrgActionsSecretOption{
|
secrets, _, err := client.Actions.ListOrgSecrets(ctx, org, gitea_sdk.ListOrgActionsSecretOption{
|
||||||
Page: page, PageSize: pageSize,
|
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: pageSize},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list org action secrets err: %v", err))
|
return to.ErrorResult(fmt.Errorf("list org action secrets err: %v", err))
|
||||||
@@ -428,7 +428,7 @@ func listOrgActionVariablesFn(ctx context.Context, args map[string]any) (*mcp.Ca
|
|||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
}
|
}
|
||||||
variables, _, err := client.Actions.ListOrgVariables(ctx, org, gitea_sdk.ListOrgActionsVariableOption{
|
variables, _, err := client.Actions.ListOrgVariables(ctx, org, gitea_sdk.ListOrgActionsVariableOption{
|
||||||
Page: page, PageSize: pageSize,
|
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: pageSize},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list org action variables err: %v", err))
|
return to.ErrorResult(fmt.Errorf("list org action variables err: %v", err))
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
package issue
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/params"
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/to"
|
|
||||||
|
|
||||||
gitea_sdk "gitea.dev/sdk"
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func listIssueBlocksFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
owner, repo, index, err := issueRef(args)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
||||||
}
|
|
||||||
listOpt := gitea_sdk.ListOptions{Page: page, PageSize: pageSize}
|
|
||||||
issues, _, err := client.Issues.ListIssueBlocks(ctx, owner, repo, index, gitea_sdk.ListIssueBlocksOptions{
|
|
||||||
ListOptions: listOpt,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("list %v/%v/issue/%v/blocks err: %v", owner, repo, index, err))
|
|
||||||
}
|
|
||||||
return to.TextResult(slimIssues(issues))
|
|
||||||
}
|
|
||||||
|
|
||||||
func blockIssueFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
return setIssueBlockingFn(ctx, args, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func unblockIssueFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
return setIssueBlockingFn(ctx, args, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIssueBlockingFn(ctx context.Context, args map[string]any, block bool) (*mcp.CallToolResult, error) {
|
|
||||||
owner, repo, index, err := issueRef(args)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
blocked, err := params.GetIndex(args, "blocked_issue")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
||||||
}
|
|
||||||
meta := gitea_sdk.IssueMeta{Index: blocked}
|
|
||||||
var issue *gitea_sdk.Issue
|
|
||||||
if block {
|
|
||||||
issue, _, err = client.Issues.CreateIssueBlocking(ctx, owner, repo, index, meta)
|
|
||||||
} else {
|
|
||||||
issue, _, err = client.Issues.RemoveIssueBlocking(ctx, owner, repo, index, meta)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("update %v/%v/issue/%v/blocks err: %v", owner, repo, index, err))
|
|
||||||
}
|
|
||||||
return to.TextResult(slimIssue(issue))
|
|
||||||
}
|
|
||||||
|
|
||||||
func listIssueDependenciesFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
owner, repo, index, err := issueRef(args)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
||||||
}
|
|
||||||
listOpt := gitea_sdk.ListOptions{Page: page, PageSize: pageSize}
|
|
||||||
issues, _, err := client.Issues.ListIssueDependencies(ctx, owner, repo, index, gitea_sdk.ListIssueDependenciesOptions{
|
|
||||||
ListOptions: listOpt,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("list %v/%v/issue/%v/dependencies err: %v", owner, repo, index, err))
|
|
||||||
}
|
|
||||||
return to.TextResult(slimIssues(issues))
|
|
||||||
}
|
|
||||||
|
|
||||||
func addIssueDependencyFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
return setIssueDependencyFn(ctx, args, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeIssueDependencyFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
return setIssueDependencyFn(ctx, args, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setIssueDependencyFn(ctx context.Context, args map[string]any, add bool) (*mcp.CallToolResult, error) {
|
|
||||||
owner, repo, index, err := issueRef(args)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
blocking, err := params.GetIndex(args, "blocking_issue")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
||||||
}
|
|
||||||
meta := gitea_sdk.IssueMeta{Index: blocking}
|
|
||||||
var issue *gitea_sdk.Issue
|
|
||||||
if add {
|
|
||||||
issue, _, err = client.Issues.CreateIssueDependency(ctx, owner, repo, index, meta)
|
|
||||||
} else {
|
|
||||||
issue, _, err = client.Issues.RemoveIssueDependency(ctx, owner, repo, index, meta)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("update %v/%v/issue/%v/dependencies err: %v", owner, repo, index, err))
|
|
||||||
}
|
|
||||||
return to.TextResult(slimIssue(issue))
|
|
||||||
}
|
|
||||||
|
|
||||||
func issueRef(args map[string]any) (owner, repo string, index int64, err error) {
|
|
||||||
if owner, err = params.GetString(args, "owner"); err != nil {
|
|
||||||
return "", "", 0, err
|
|
||||||
}
|
|
||||||
if repo, err = params.GetString(args, "repo"); err != nil {
|
|
||||||
return "", "", 0, err
|
|
||||||
}
|
|
||||||
if index, err = params.GetIndex(args, "issue_number"); err != nil {
|
|
||||||
return "", "", 0, err
|
|
||||||
}
|
|
||||||
return owner, repo, index, nil
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
package issue
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"maps"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
|
||||||
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_issueBlocking(t *testing.T) {
|
|
||||||
const (
|
|
||||||
owner = "octo"
|
|
||||||
repo = "demo"
|
|
||||||
)
|
|
||||||
blocksPath := fmt.Sprintf("/api/v1/repos/%s/%s/issues/42/blocks", owner, repo)
|
|
||||||
depsPath := fmt.Sprintf("/api/v1/repos/%s/%s/issues/42/dependencies", owner, repo)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
fn func(context.Context, map[string]any) (*mcp.CallToolResult, error)
|
|
||||||
args map[string]any
|
|
||||||
wantPath string
|
|
||||||
wantMethod string
|
|
||||||
wantQuery string
|
|
||||||
wantIndex float64
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "list blocks paginates",
|
|
||||||
fn: listIssueBlocksFn,
|
|
||||||
args: map[string]any{"page": float64(2), "per_page": float64(10)},
|
|
||||||
wantPath: blocksPath,
|
|
||||||
wantMethod: http.MethodGet,
|
|
||||||
wantQuery: "limit=10&page=2",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "block issue posts index",
|
|
||||||
fn: blockIssueFn,
|
|
||||||
args: map[string]any{"blocked_issue": float64(7)},
|
|
||||||
wantPath: blocksPath,
|
|
||||||
wantMethod: http.MethodPost,
|
|
||||||
wantIndex: 7,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "unblock issue deletes with index",
|
|
||||||
fn: unblockIssueFn,
|
|
||||||
args: map[string]any{"blocked_issue": float64(7)},
|
|
||||||
wantPath: blocksPath,
|
|
||||||
wantMethod: http.MethodDelete,
|
|
||||||
wantIndex: 7,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "list dependencies paginates",
|
|
||||||
fn: listIssueDependenciesFn,
|
|
||||||
args: map[string]any{"page": float64(3), "per_page": float64(5)},
|
|
||||||
wantPath: depsPath,
|
|
||||||
wantMethod: http.MethodGet,
|
|
||||||
wantQuery: "limit=5&page=3",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "add dependency posts index",
|
|
||||||
fn: addIssueDependencyFn,
|
|
||||||
args: map[string]any{"blocking_issue": float64(9)},
|
|
||||||
wantPath: depsPath,
|
|
||||||
wantMethod: http.MethodPost,
|
|
||||||
wantIndex: 9,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "remove dependency deletes with index",
|
|
||||||
fn: removeIssueDependencyFn,
|
|
||||||
args: map[string]any{"blocking_issue": float64(9)},
|
|
||||||
wantPath: depsPath,
|
|
||||||
wantMethod: http.MethodDelete,
|
|
||||||
wantIndex: 9,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
var (
|
|
||||||
gotMethod string
|
|
||||||
gotPath string
|
|
||||||
gotQuery string
|
|
||||||
gotBody map[string]any
|
|
||||||
)
|
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.URL.Path {
|
|
||||||
case "/api/v1/version":
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
_, _ = w.Write([]byte(`{"version":"1.27.2"}`))
|
|
||||||
case blocksPath, depsPath:
|
|
||||||
gotMethod = r.Method
|
|
||||||
gotPath = r.URL.Path
|
|
||||||
gotQuery = r.URL.RawQuery
|
|
||||||
_ = json.NewDecoder(r.Body).Decode(&gotBody)
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
if r.Method == http.MethodGet {
|
|
||||||
_, _ = w.Write([]byte(`[{"number":7,"title":"blocked","state":"open"}]`))
|
|
||||||
} else {
|
|
||||||
_, _ = w.Write([]byte(`{"number":7,"title":"blocked","state":"open"}`))
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
http.NotFound(w, r)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
server := httptest.NewServer(handler)
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
origHost, origToken, origVersion := flag.Host, flag.Token, flag.Version
|
|
||||||
flag.Host, flag.Token, flag.Version = server.URL, "", "test"
|
|
||||||
defer func() { flag.Host, flag.Token, flag.Version = origHost, origToken, origVersion }()
|
|
||||||
|
|
||||||
args := map[string]any{"owner": owner, "repo": repo, "issue_number": float64(42)}
|
|
||||||
maps.Copy(args, tt.args)
|
|
||||||
res, err := tt.fn(context.Background(), args)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("handler error = %v", err)
|
|
||||||
}
|
|
||||||
if res.IsError {
|
|
||||||
t.Fatalf("unexpected error result: %v", res.Content)
|
|
||||||
}
|
|
||||||
if gotMethod != tt.wantMethod {
|
|
||||||
t.Fatalf("method = %s, want %s", gotMethod, tt.wantMethod)
|
|
||||||
}
|
|
||||||
if gotPath != tt.wantPath {
|
|
||||||
t.Fatalf("path = %s, want %s", gotPath, tt.wantPath)
|
|
||||||
}
|
|
||||||
if tt.wantQuery != "" && gotQuery != tt.wantQuery {
|
|
||||||
t.Fatalf("query = %s, want %s", gotQuery, tt.wantQuery)
|
|
||||||
}
|
|
||||||
if tt.wantIndex != 0 && gotBody["index"] != tt.wantIndex {
|
|
||||||
t.Fatalf("body index = %v, want %v", gotBody["index"], tt.wantIndex)
|
|
||||||
}
|
|
||||||
body := res.Content[0].(*mcp.TextContent).Text
|
|
||||||
if !strings.Contains(body, `"number":7`) && !strings.Contains(body, `"number": 7`) {
|
|
||||||
t.Fatalf("expected slim issue in output, got: %s", body)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+12
-22
@@ -49,27 +49,26 @@ var (
|
|||||||
tool.Array("milestones", tool.Description("milestone name or ID filter"), tool.Items(map[string]any{"type": "string"})),
|
tool.Array("milestones", tool.Description("milestone name or ID filter"), tool.Items(map[string]any{"type": "string"})),
|
||||||
tool.String("since", tool.Description("updated after ISO 8601")),
|
tool.String("since", tool.Description("updated after ISO 8601")),
|
||||||
tool.String("before", tool.Description("updated before ISO 8601")),
|
tool.String("before", tool.Description("updated before ISO 8601")),
|
||||||
|
tool.String("assigned_by", tool.Description("filter by the user who assigned the issue")),
|
||||||
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
||||||
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
||||||
)
|
)
|
||||||
|
|
||||||
IssueReadTool = tool.NewDefinition(
|
IssueReadTool = tool.NewDefinition(
|
||||||
IssueReadToolName,
|
IssueReadToolName,
|
||||||
"Read issue: details, comments, labels, or blocking relationships.",
|
"Read issue: details, comments, or labels.",
|
||||||
annotation.ReadOnly("Read issue details"),
|
annotation.ReadOnly("Read issue details"),
|
||||||
tool.String("method", tool.Required(), tool.Enum("get", "get_comments", "get_labels", "list_blocks", "list_dependencies")),
|
tool.String("method", tool.Required(), tool.Enum("get", "get_comments", "get_labels")),
|
||||||
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
||||||
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
||||||
tool.Number("issue_number", tool.Required()),
|
tool.Number("issue_number", tool.Required()),
|
||||||
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
|
||||||
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
IssueWriteTool = tool.NewDefinition(
|
IssueWriteTool = tool.NewDefinition(
|
||||||
IssueWriteToolName,
|
IssueWriteToolName,
|
||||||
"Write issues: create, update, manage comments, labels, and blocking relationships.",
|
"Write issues: create, update, manage comments and labels.",
|
||||||
annotation.Write("Create or update issues, comments, and labels"),
|
annotation.Write("Create or update issues, comments, and labels"),
|
||||||
tool.String("method", tool.Required(), tool.Enum("create", "update", "add_comment", "edit_comment", "add_labels", "remove_label", "replace_labels", "clear_labels", "block_issue", "unblock_issue", "add_dependency", "remove_dependency")),
|
tool.String("method", tool.Required(), tool.Enum("create", "update", "add_comment", "edit_comment", "add_labels", "remove_label", "replace_labels", "clear_labels")),
|
||||||
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
||||||
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
||||||
tool.Number("issue_number", tool.Description("required except for 'create'")),
|
tool.Number("issue_number", tool.Description("required except for 'create'")),
|
||||||
@@ -84,8 +83,6 @@ var (
|
|||||||
tool.String("ref", tool.Description("branch to associate")),
|
tool.String("ref", tool.Description("branch to associate")),
|
||||||
tool.String("deadline", tool.Description("ISO 8601")),
|
tool.String("deadline", tool.Description("ISO 8601")),
|
||||||
tool.Boolean("remove_deadline"),
|
tool.Boolean("remove_deadline"),
|
||||||
tool.Number("blocked_issue", tool.Description("issue number that issue_number blocks (required for 'block_issue'/'unblock_issue')")),
|
|
||||||
tool.Number("blocking_issue", tool.Description("issue number that blocks issue_number (required for 'add_dependency'/'remove_dependency')")),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,10 +113,6 @@ func issueReadFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult,
|
|||||||
return getIssueCommentsByIndexFn(ctx, args)
|
return getIssueCommentsByIndexFn(ctx, args)
|
||||||
case "get_labels":
|
case "get_labels":
|
||||||
return getIssueLabelsFn(ctx, args)
|
return getIssueLabelsFn(ctx, args)
|
||||||
case "list_blocks":
|
|
||||||
return listIssueBlocksFn(ctx, args)
|
|
||||||
case "list_dependencies":
|
|
||||||
return listIssueDependenciesFn(ctx, args)
|
|
||||||
default:
|
default:
|
||||||
return to.ErrorResult(fmt.Errorf("unknown method: %s", method))
|
return to.ErrorResult(fmt.Errorf("unknown method: %s", method))
|
||||||
}
|
}
|
||||||
@@ -147,14 +140,6 @@ func issueWriteFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult
|
|||||||
return replaceIssueLabelsFn(ctx, args)
|
return replaceIssueLabelsFn(ctx, args)
|
||||||
case "clear_labels":
|
case "clear_labels":
|
||||||
return clearIssueLabelsFn(ctx, args)
|
return clearIssueLabelsFn(ctx, args)
|
||||||
case "block_issue":
|
|
||||||
return blockIssueFn(ctx, args)
|
|
||||||
case "unblock_issue":
|
|
||||||
return unblockIssueFn(ctx, args)
|
|
||||||
case "add_dependency":
|
|
||||||
return addIssueDependencyFn(ctx, args)
|
|
||||||
case "remove_dependency":
|
|
||||||
return removeIssueDependencyFn(ctx, args)
|
|
||||||
default:
|
default:
|
||||||
return to.ErrorResult(fmt.Errorf("unknown method: %s", method))
|
return to.ErrorResult(fmt.Errorf("unknown method: %s", method))
|
||||||
}
|
}
|
||||||
@@ -203,8 +188,10 @@ func listRepoIssuesFn(ctx context.Context, args map[string]any) (*mcp.CallToolRe
|
|||||||
State: gitea_sdk.StateType(state),
|
State: gitea_sdk.StateType(state),
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Milestones: milestones,
|
Milestones: milestones,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
switch args["type"] {
|
switch args["type"] {
|
||||||
case "issues":
|
case "issues":
|
||||||
@@ -218,6 +205,9 @@ func listRepoIssuesFn(ctx context.Context, args map[string]any) (*mcp.CallToolRe
|
|||||||
if t := params.GetOptionalTime(args, "before"); t != nil {
|
if t := params.GetOptionalTime(args, "before"); t != nil {
|
||||||
opt.Before = *t
|
opt.Before = *t
|
||||||
}
|
}
|
||||||
|
if assignedBy, ok := args["assigned_by"].(string); ok {
|
||||||
|
opt.AssignedBy = assignedBy
|
||||||
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ func Test_listRepoIssuesFn_filters(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
args := map[string]any{
|
args := map[string]any{
|
||||||
"owner": owner,
|
"owner": owner,
|
||||||
"repo": repo,
|
"repo": repo,
|
||||||
"type": "issues",
|
"type": "issues",
|
||||||
"labels": []any{"bug", "enhancement"},
|
"labels": []any{"bug", "enhancement"},
|
||||||
"milestones": []any{"v1.0", "2"},
|
"milestones": []any{"v1.0", "2"},
|
||||||
"since": "2026-01-01T00:00:00Z",
|
"since": "2026-01-01T00:00:00Z",
|
||||||
|
"assigned_by": "octocat",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := listRepoIssuesFn(context.Background(), args)
|
_, err := listRepoIssuesFn(context.Background(), args)
|
||||||
@@ -89,6 +90,9 @@ func Test_listRepoIssuesFn_filters(t *testing.T) {
|
|||||||
if !strings.Contains(gotQuery, "type=issues") {
|
if !strings.Contains(gotQuery, "type=issues") {
|
||||||
t.Fatalf("expected type query param, got %s", gotQuery)
|
t.Fatalf("expected type query param, got %s", gotQuery)
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(gotQuery, "assigned_by=octocat") {
|
||||||
|
t.Fatalf("expected assigned_by query param, got %s", gotQuery)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_listRepoIssuesFn_includesMilestone(t *testing.T) {
|
func Test_listRepoIssuesFn_includesMilestone(t *testing.T) {
|
||||||
@@ -138,6 +142,52 @@ func Test_listRepoIssuesFn_includesMilestone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_listRepoIssuesFn_includesAssignees(t *testing.T) {
|
||||||
|
const (
|
||||||
|
owner = "octo"
|
||||||
|
repo = "demo"
|
||||||
|
)
|
||||||
|
|
||||||
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/api/v1/version":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"version":"1.12.0"}`))
|
||||||
|
case fmt.Sprintf("/api/v1/repos/%s/%s", owner, repo):
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"private":false}`))
|
||||||
|
case fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner, repo):
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`[
|
||||||
|
{"number": 1, "title": "with assignees", "state": "open", "assignees": [{"login": "octocat"}]}
|
||||||
|
]`))
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
server := httptest.NewServer(handler)
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
origHost, origToken, origVersion := flag.Host, flag.Token, flag.Version
|
||||||
|
flag.Host, flag.Token, flag.Version = server.URL, "", "test"
|
||||||
|
defer func() { flag.Host, flag.Token, flag.Version = origHost, origToken, origVersion }()
|
||||||
|
|
||||||
|
args := map[string]any{
|
||||||
|
"owner": owner, "repo": repo,
|
||||||
|
}
|
||||||
|
res, err := listRepoIssuesFn(context.Background(), args)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("listRepoIssuesFn() error = %v", err)
|
||||||
|
}
|
||||||
|
if res.IsError {
|
||||||
|
t.Fatalf("unexpected error result: %v", res.Content)
|
||||||
|
}
|
||||||
|
body := res.Content[0].(*mcp.TextContent).Text
|
||||||
|
if !strings.Contains(body, `"assignees"`) || !strings.Contains(body, `"octocat"`) {
|
||||||
|
t.Fatalf("expected assignees in list output, got: %s", body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_createIssueFn_labels(t *testing.T) {
|
func Test_createIssueFn_labels(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
owner = "octo"
|
owner = "octo"
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func slimIssues(issues []*gitea_sdk.Issue) []map[string]any {
|
|||||||
if len(i.Labels) > 0 {
|
if len(i.Labels) > 0 {
|
||||||
m["labels"] = slim.LabelNames(i.Labels)
|
m["labels"] = slim.LabelNames(i.Labels)
|
||||||
}
|
}
|
||||||
|
if len(i.Assignees) > 0 {
|
||||||
|
m["assignees"] = slim.UserLogins(i.Assignees)
|
||||||
|
}
|
||||||
if i.Milestone != nil {
|
if i.Milestone != nil {
|
||||||
m["milestone"] = map[string]any{
|
m["milestone"] = map[string]any{
|
||||||
"id": i.Milestone.ID,
|
"id": i.Milestone.ID,
|
||||||
|
|||||||
@@ -116,8 +116,10 @@ func listRepoLabelsFn(ctx context.Context, args map[string]any) (*mcp.CallToolRe
|
|||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
|
|
||||||
opt := gitea_sdk.ListLabelsOptions{
|
opt := gitea_sdk.ListLabelsOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -259,8 +261,10 @@ func listOrgLabelsFn(ctx context.Context, args map[string]any) (*mcp.CallToolRes
|
|||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
|
|
||||||
opt := gitea_sdk.ListOrgLabelsOptions{
|
opt := gitea_sdk.ListOrgLabelsOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -134,10 +134,12 @@ func listMilestonesFn(ctx context.Context, args map[string]any) (*mcp.CallToolRe
|
|||||||
name := params.GetOptionalString(args, "name", "")
|
name := params.GetOptionalString(args, "name", "")
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
opt := gitea_sdk.ListMilestoneOption{
|
opt := gitea_sdk.ListMilestoneOption{
|
||||||
State: gitea_sdk.StateType(state),
|
State: gitea_sdk.StateType(state),
|
||||||
Name: name,
|
Name: name,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -95,8 +95,10 @@ func notificationWriteFn(ctx context.Context, args map[string]any) (*mcp.CallToo
|
|||||||
func listNotificationsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
func listNotificationsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
opt := gitea_sdk.ListNotificationOptions{
|
opt := gitea_sdk.ListNotificationOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if status, ok := args["status"].(string); ok {
|
if status, ok := args["status"].(string); ok {
|
||||||
opt.Status = []gitea_sdk.NotificationStatus{gitea_sdk.NotificationStatus(status)}
|
opt.Status = []gitea_sdk.NotificationStatus{gitea_sdk.NotificationStatus(status)}
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ func newHTTPServer(addr string, s *mcp.Server) *http.Server {
|
|||||||
PropagateRequestCancellation: true,
|
PropagateRequestCancellation: true,
|
||||||
},
|
},
|
||||||
)))
|
)))
|
||||||
mux.HandleFunc("/healthz", handleHealthz)
|
|
||||||
return &http.Server{
|
return &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
@@ -141,12 +140,6 @@ func newHTTPServer(addr string, s *mcp.Server) *http.Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleHealthz(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
_, _ = w.Write([]byte("ok\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func Run() error {
|
func Run() error {
|
||||||
mcpServer = newMCPServer(flag.Version)
|
mcpServer = newMCPServer(flag.Version)
|
||||||
RegisterTool(mcpServer)
|
RegisterTool(mcpServer)
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package operation
|
package operation
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewHTTPServerConfig(t *testing.T) {
|
func TestNewHTTPServerConfig(t *testing.T) {
|
||||||
server := newHTTPServer(":12345", newMCPServer("test"))
|
server := newHTTPServer(":12345", newMCPServer("test"))
|
||||||
@@ -22,21 +18,6 @@ func TestNewHTTPServerConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthzEndpoint(t *testing.T) {
|
|
||||||
server := newHTTPServer(":0", newMCPServer("test"))
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
server.Handler.ServeHTTP(rec, req)
|
|
||||||
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Errorf("status = %d, want %d", rec.Code, http.StatusOK)
|
|
||||||
}
|
|
||||||
if body := rec.Body.String(); body == "" {
|
|
||||||
t.Error("body is empty, want a non-empty health message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseAuthToken(t *testing.T) {
|
func TestParseAuthToken(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
+10
-6
@@ -349,8 +349,10 @@ func listRepoPullRequestsFn(ctx context.Context, args map[string]any) (*mcp.Call
|
|||||||
State: gitea_sdk.StateType(state),
|
State: gitea_sdk.StateType(state),
|
||||||
Sort: sort,
|
Sort: sort,
|
||||||
Milestone: milestone,
|
Milestone: milestone,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -507,8 +509,10 @@ func listPullRequestReviewsFn(ctx context.Context, args map[string]any) (*mcp.Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
reviews, _, err := client.PullRequests.ListPullReviews(ctx, owner, repo, index, gitea_sdk.ListPullReviewsOptions{
|
reviews, _, err := client.PullRequests.ListPullReviews(ctx, owner, repo, index, gitea_sdk.ListPullReviewsOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list reviews for %v/%v/pr/%v err: %v", owner, repo, index, err))
|
return to.ErrorResult(fmt.Errorf("list reviews for %v/%v/pr/%v err: %v", owner, repo, index, err))
|
||||||
@@ -574,7 +578,7 @@ func listPullRequestReviewCommentsFn(ctx context.Context, args map[string]any) (
|
|||||||
} else {
|
} else {
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
reviews, _, err := client.PullRequests.ListPullReviews(ctx, owner, repo, index, gitea_sdk.ListPullReviewsOptions{
|
reviews, _, err := client.PullRequests.ListPullReviews(ctx, owner, repo, index, gitea_sdk.ListPullReviewsOptions{
|
||||||
Page: page, PageSize: pageSize,
|
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: pageSize},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list reviews for %v/%v/pr/%v err: %v", owner, repo, index, err))
|
return to.ErrorResult(fmt.Errorf("list reviews for %v/%v/pr/%v err: %v", owner, repo, index, err))
|
||||||
@@ -1045,7 +1049,7 @@ func getPullRequestFilesFn(ctx context.Context, args map[string]any) (*mcp.CallT
|
|||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
}
|
}
|
||||||
files, _, err := client.PullRequests.ListPullRequestFiles(ctx, owner, repo, index, gitea_sdk.ListPullRequestFilesOptions{
|
files, _, err := client.PullRequests.ListPullRequestFiles(ctx, owner, repo, index, gitea_sdk.ListPullRequestFilesOptions{
|
||||||
Page: page, PageSize: pageSize,
|
ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: pageSize},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("get %v/%v/pr/%v files err: %v", owner, repo, index, err))
|
return to.ErrorResult(fmt.Errorf("get %v/%v/pr/%v files err: %v", owner, repo, index, err))
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package repo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/annotation"
|
"gitea.com/gitea/gitea-mcp/pkg/annotation"
|
||||||
@@ -22,7 +21,6 @@ const (
|
|||||||
CreateBranchToolName = "create_branch"
|
CreateBranchToolName = "create_branch"
|
||||||
DeleteBranchToolName = "delete_branch"
|
DeleteBranchToolName = "delete_branch"
|
||||||
ListBranchesToolName = "list_branches"
|
ListBranchesToolName = "list_branches"
|
||||||
RenameBranchToolName = "rename_branch"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -54,16 +52,6 @@ var (
|
|||||||
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
||||||
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
||||||
)
|
)
|
||||||
|
|
||||||
RenameBranchTool = tool.NewDefinition(
|
|
||||||
RenameBranchToolName,
|
|
||||||
"Rename an existing branch in a repository.",
|
|
||||||
annotation.Write("Rename a branch"),
|
|
||||||
tool.String("owner", tool.Required(), tool.Description(params.OwnerDesc)),
|
|
||||||
tool.String("repo", tool.Required(), tool.Description(params.RepoDesc)),
|
|
||||||
tool.String("branch", tool.Required()),
|
|
||||||
tool.String("new_name", tool.Required()),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -79,10 +67,6 @@ func init() {
|
|||||||
Tool: ListBranchesTool,
|
Tool: ListBranchesTool,
|
||||||
Handler: ListBranchesFn,
|
Handler: ListBranchesFn,
|
||||||
})
|
})
|
||||||
BranchTool.RegisterWrite(tool.ServerTool{
|
|
||||||
Tool: RenameBranchTool,
|
|
||||||
Handler: RenameBranchFn,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateBranchFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
func CreateBranchFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
||||||
@@ -151,8 +135,10 @@ func ListBranchesFn(ctx context.Context, args map[string]any) (*mcp.CallToolResu
|
|||||||
}
|
}
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
opt := gitea_sdk.ListRepoBranchesOptions{
|
opt := gitea_sdk.ListRepoBranchesOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -165,36 +151,3 @@ func ListBranchesFn(ctx context.Context, args map[string]any) (*mcp.CallToolResu
|
|||||||
|
|
||||||
return to.TextResult(slimBranches(branches))
|
return to.TextResult(slimBranches(branches))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenameBranchFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
||||||
owner, err := params.GetString(args, "owner")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
repo, err := params.GetString(args, "repo")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
branch, err := params.GetString(args, "branch")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
newName, err := params.GetString(args, "new_name")
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
||||||
}
|
|
||||||
successful, _, err := client.Repositories.RenameRepoBranch(ctx, owner, repo, branch, gitea_sdk.RenameRepoBranchOption{Name: newName})
|
|
||||||
if err != nil {
|
|
||||||
return to.ErrorResult(fmt.Errorf("rename branch error: %v", err))
|
|
||||||
}
|
|
||||||
if !successful {
|
|
||||||
return to.ErrorResult(errors.New("rename branch error: unsuccessful"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return to.TextResult("Branch renamed")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
package repo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
|
||||||
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRenameBranchFnMissingArgs(t *testing.T) {
|
|
||||||
fullArgs := map[string]any{
|
|
||||||
"owner": "octo",
|
|
||||||
"repo": "demo",
|
|
||||||
"branch": "old-name",
|
|
||||||
"new_name": "new-name",
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, missing := range []string{"owner", "repo", "branch", "new_name"} {
|
|
||||||
t.Run(missing, func(t *testing.T) {
|
|
||||||
args := map[string]any{}
|
|
||||||
for k, v := range fullArgs {
|
|
||||||
if k != missing {
|
|
||||||
args[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := RenameBranchFn(context.Background(), args)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("RenameBranchFn() error = %v", err)
|
|
||||||
}
|
|
||||||
if !result.IsError {
|
|
||||||
t.Fatalf("RenameBranchFn() with missing %q, want error result", missing)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRenameBranchFn(t *testing.T) {
|
|
||||||
const (
|
|
||||||
owner = "octo"
|
|
||||||
repo = "demo"
|
|
||||||
branch = "old-name"
|
|
||||||
newName = "new-name"
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, tc := range []struct {
|
|
||||||
name string
|
|
||||||
serverStatus int
|
|
||||||
wantErr bool
|
|
||||||
wantContains string
|
|
||||||
}{
|
|
||||||
{"success", http.StatusNoContent, false, "Branch renamed"},
|
|
||||||
{"server error", http.StatusInternalServerError, true, "rename branch error"},
|
|
||||||
} {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
var (
|
|
||||||
mu sync.Mutex
|
|
||||||
gotBody map[string]any
|
|
||||||
)
|
|
||||||
|
|
||||||
renamePath := fmt.Sprintf("/api/v1/repos/%s/%s/branches/%s", owner, repo, branch)
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.URL.Path {
|
|
||||||
case "/api/v1/version":
|
|
||||||
_, _ = w.Write([]byte(`{"version":"1.24.0"}`))
|
|
||||||
case renamePath:
|
|
||||||
mu.Lock()
|
|
||||||
_ = json.NewDecoder(r.Body).Decode(&gotBody)
|
|
||||||
mu.Unlock()
|
|
||||||
w.WriteHeader(tc.serverStatus)
|
|
||||||
default:
|
|
||||||
http.NotFound(w, r)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
origHost, origToken := flag.Host, flag.Token
|
|
||||||
flag.Host, flag.Token = server.URL, ""
|
|
||||||
defer func() { flag.Host, flag.Token = origHost, origToken }()
|
|
||||||
|
|
||||||
result, err := RenameBranchFn(context.Background(), map[string]any{
|
|
||||||
"owner": owner,
|
|
||||||
"repo": repo,
|
|
||||||
"branch": branch,
|
|
||||||
"new_name": newName,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("RenameBranchFn() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if result.IsError != tc.wantErr {
|
|
||||||
t.Fatalf("RenameBranchFn() IsError = %v, want %v (result: %v)", result.IsError, tc.wantErr, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
text := result.Content[0].(*mcp.TextContent).Text
|
|
||||||
if !strings.Contains(text, tc.wantContains) {
|
|
||||||
t.Fatalf("result = %s, want it to contain %q", text, tc.wantContains)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !tc.wantErr {
|
|
||||||
mu.Lock()
|
|
||||||
defer mu.Unlock()
|
|
||||||
if gotBody["name"] != newName {
|
|
||||||
t.Fatalf("request body name = %v, want %s", gotBody["name"], newName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRenameBranchToolRegistration(t *testing.T) {
|
|
||||||
found := false
|
|
||||||
for _, registered := range BranchTool.WriteTools() {
|
|
||||||
if registered.Tool.Name == RenameBranchToolName {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Fatalf("%q is not registered as a write tool", RenameBranchToolName)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, registered := range BranchTool.ReadTools() {
|
|
||||||
if registered.Tool.Name == RenameBranchToolName {
|
|
||||||
t.Fatalf("%q is registered as a read tool, want write only", RenameBranchToolName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -69,10 +69,12 @@ func ListRepoCommitsFn(ctx context.Context, args map[string]any) (*mcp.CallToolR
|
|||||||
sha, _ := args["sha"].(string)
|
sha, _ := args["sha"].(string)
|
||||||
path, _ := args["path"].(string)
|
path, _ := args["path"].(string)
|
||||||
opt := gitea_sdk.ListCommitOptions{
|
opt := gitea_sdk.ListCommitOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
SHA: sha,
|
PageSize: pageSize,
|
||||||
Path: path,
|
},
|
||||||
|
SHA: sha,
|
||||||
|
Path: path,
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -266,9 +266,11 @@ func DeleteFileFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult
|
|||||||
return to.ErrorResult(err)
|
return to.ErrorResult(err)
|
||||||
}
|
}
|
||||||
opt := gitea_sdk.DeleteFileOptions{
|
opt := gitea_sdk.DeleteFileOptions{
|
||||||
Message: message,
|
FileOptions: gitea_sdk.FileOptions{
|
||||||
BranchName: branchName,
|
Message: message,
|
||||||
SHA: sha,
|
BranchName: branchName,
|
||||||
|
},
|
||||||
|
SHA: sha,
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -236,8 +236,10 @@ func ListReleasesFn(ctx context.Context, args map[string]any) (*mcp.CallToolResu
|
|||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
}
|
}
|
||||||
releases, _, err := client.Releases.ListReleases(ctx, owner, repo, gitea_sdk.ListReleasesOptions{
|
releases, _, err := client.Releases.ListReleases(ctx, owner, repo, gitea_sdk.ListReleasesOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
IsDraft: params.GetOptionalBoolPtr(args, "is_draft"),
|
IsDraft: params.GetOptionalBoolPtr(args, "is_draft"),
|
||||||
IsPreRelease: params.GetOptionalBoolPtr(args, "is_pre_release"),
|
IsPreRelease: params.GetOptionalBoolPtr(args, "is_pre_release"),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -170,8 +170,10 @@ func ForkRepoFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult,
|
|||||||
func ListMyReposFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
func ListMyReposFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
opt := gitea_sdk.ListReposOptions{
|
opt := gitea_sdk.ListReposOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -192,8 +194,10 @@ func ListOrgReposFn(ctx context.Context, args map[string]any) (*mcp.CallToolResu
|
|||||||
}
|
}
|
||||||
page, pageSize := params.GetPagination(args, 100)
|
page, pageSize := params.GetPagination(args, 100)
|
||||||
opt := gitea_sdk.ListOrgReposOptions{
|
opt := gitea_sdk.ListOrgReposOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -185,8 +185,10 @@ func ListTagsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult,
|
|||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
}
|
}
|
||||||
tags, _, err := client.Repositories.ListRepoTags(ctx, owner, repo, gitea_sdk.ListRepoTagsOptions{
|
tags, _, err := client.Repositories.ListRepoTags(ctx, owner, repo, gitea_sdk.ListRepoTagsOptions{
|
||||||
Page: int(page),
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: int(pageSize),
|
Page: int(page),
|
||||||
|
PageSize: int(pageSize),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list tags error: %v", err))
|
return to.ErrorResult(fmt.Errorf("list tags error: %v", err))
|
||||||
|
|||||||
@@ -54,8 +54,10 @@ func GetRepoTreeFn(ctx context.Context, args map[string]any) (*mcp.CallToolResul
|
|||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
|
|
||||||
opt := gitea_sdk.ListTreeOptions{
|
opt := gitea_sdk.ListTreeOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
Ref: treeSHA,
|
Ref: treeSHA,
|
||||||
Recursive: recursive,
|
Recursive: recursive,
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-10
@@ -102,9 +102,11 @@ func UsersFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, err
|
|||||||
}
|
}
|
||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
opt := gitea_sdk.SearchUsersOption{
|
opt := gitea_sdk.SearchUsersOption{
|
||||||
KeyWord: keyword,
|
KeyWord: keyword,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -131,8 +133,10 @@ func OrgTeamsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult,
|
|||||||
opt := gitea_sdk.SearchTeamsOptions{
|
opt := gitea_sdk.SearchTeamsOptions{
|
||||||
Query: query,
|
Query: query,
|
||||||
IncludeDescription: includeDescription,
|
IncludeDescription: includeDescription,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,8 +168,10 @@ func ReposFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, err
|
|||||||
IsArchived: params.GetOptionalBoolPtr(args, "isArchived"),
|
IsArchived: params.GetOptionalBoolPtr(args, "isArchived"),
|
||||||
Sort: sort,
|
Sort: sort,
|
||||||
Order: order,
|
Order: order,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -186,9 +192,11 @@ func IssuesFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, er
|
|||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
|
|
||||||
opt := gitea_sdk.ListIssueOption{
|
opt := gitea_sdk.ListIssueOption{
|
||||||
KeyWord: query,
|
KeyWord: query,
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if state, ok := args["state"].(string); ok {
|
if state, ok := args["state"].(string); ok {
|
||||||
opt.State = gitea_sdk.StateType(state)
|
opt.State = gitea_sdk.StateType(state)
|
||||||
|
|||||||
@@ -200,8 +200,10 @@ func listTrackedTimesFn(ctx context.Context, args map[string]any) (*mcp.CallTool
|
|||||||
}
|
}
|
||||||
|
|
||||||
times, _, err := client.Issues.ListIssueTrackedTimes(ctx, owner, repo, index, gitea_sdk.ListTrackedTimesOptions{
|
times, _, err := client.Issues.ListIssueTrackedTimes(ctx, owner, repo, index, gitea_sdk.ListTrackedTimesOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list tracked times for %s/%s#%d err: %v", owner, repo, index, err))
|
return to.ErrorResult(fmt.Errorf("list tracked times for %s/%s#%d err: %v", owner, repo, index, err))
|
||||||
@@ -288,8 +290,10 @@ func listRepoTimesFn(ctx context.Context, args map[string]any) (*mcp.CallToolRes
|
|||||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||||
}
|
}
|
||||||
times, _, err := client.Issues.ListRepoTrackedTimes(ctx, owner, repo, gitea_sdk.ListTrackedTimesOptions{
|
times, _, err := client.Issues.ListRepoTrackedTimes(ctx, owner, repo, gitea_sdk.ListTrackedTimesOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return to.ErrorResult(fmt.Errorf("list repo tracked times for %s/%s err: %v", owner, repo, err))
|
return to.ErrorResult(fmt.Errorf("list repo tracked times for %s/%s err: %v", owner, repo, err))
|
||||||
|
|||||||
@@ -59,8 +59,10 @@ func GetUserOrgsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResul
|
|||||||
page, pageSize := params.GetPagination(args, 30)
|
page, pageSize := params.GetPagination(args, 30)
|
||||||
|
|
||||||
opt := gitea_sdk.ListOrgsOptions{
|
opt := gitea_sdk.ListOrgsOptions{
|
||||||
Page: page,
|
ListOptions: gitea_sdk.ListOptions{
|
||||||
PageSize: pageSize,
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client, err := gitea.ClientFromContext(ctx)
|
client, err := gitea.ClientFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ func TestDownloadAttachmentErrorsOnNon2xx(t *testing.T) {
|
|||||||
if status != http.StatusForbidden {
|
if status != http.StatusForbidden {
|
||||||
t.Fatalf("status = %d, want %d", status, http.StatusForbidden)
|
t.Fatalf("status = %d, want %d", status, http.StatusForbidden)
|
||||||
}
|
}
|
||||||
if _, ok := errors.AsType[*HTTPError](err); !ok {
|
var httpErr *HTTPError
|
||||||
|
if !errors.As(err, &httpErr) {
|
||||||
t.Fatalf("expected HTTPError, got %T", err)
|
t.Fatalf("expected HTTPError, got %T", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -236,7 +236,8 @@ func OpenAttachment(ctx context.Context, attachmentPath, accept string) (*Attach
|
|||||||
func DownloadAttachment(ctx context.Context, attachmentPath, accept string) ([]byte, string, int, error) {
|
func DownloadAttachment(ctx context.Context, attachmentPath, accept string) ([]byte, string, int, error) {
|
||||||
resp, err := OpenAttachment(ctx, attachmentPath, accept)
|
resp, err := OpenAttachment(ctx, attachmentPath, accept)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if httpErr, ok := errors.AsType[*HTTPError](err); ok {
|
var httpErr *HTTPError
|
||||||
|
if errors.As(err, &httpErr) {
|
||||||
return nil, "", httpErr.StatusCode, err
|
return nil, "", httpErr.StatusCode, err
|
||||||
}
|
}
|
||||||
return nil, "", 0, err
|
return nil, "", 0, err
|
||||||
|
|||||||
+2
-1
@@ -102,7 +102,8 @@ func (s ServerTool) MCPHandler() mcp.ToolHandler {
|
|||||||
|
|
||||||
result, err = s.Handler(ctx, arguments)
|
result, err = s.Handler(ctx, arguments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := errors.AsType[*jsonrpc.Error](err); ok {
|
var protocolErr *jsonrpc.Error
|
||||||
|
if errors.As(err, &protocolErr) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return to.ErrorResult(err)
|
return to.ErrorResult(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user