mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-27 02:27:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e62d158cb |
@@ -31,5 +31,7 @@ USER nonroot:nonroot
|
||||
|
||||
LABEL org.opencontainers.image.version="${VERSION}"
|
||||
LABEL org.opencontainers.image.source="https://gitea.com/gitea/gitea-mcp"
|
||||
LABEL org.opencontainers.image.title="Gitea MCP Server"
|
||||
LABEL org.opencontainers.image.description="Model Context Protocol server connecting Gitea instances to MCP clients, published as docker.gitea.com/gitea-mcp-server."
|
||||
|
||||
CMD ["/app/gitea-mcp"]
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
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:
|
||||
|
||||
> The published Docker image is `docker.gitea.com/gitea-mcp-server`, which does not match the `gitea-mcp` repository name. This is a known mismatch, tracked in [issue #181](https://gitea.com/gitea/gitea-mcp/issues/181); the image name stays as-is for now to avoid breaking existing installs. See [docs/adr/docker-image-naming.md](docs/adr/docker-image-naming.md) for details.
|
||||
|
||||
```bash
|
||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||
cd gitea-mcp
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
可从 [发布页面](https://gitea.com/gitea/gitea-mcp/releases) 下载二进制文件并放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 镜像,也可用 `make` 和 Go 1.26 及以上从源码构建到 `$GOPATH/bin`:
|
||||
|
||||
> 已发布的 Docker 镜像名为 `docker.gitea.com/gitea-mcp-server`,与 `gitea-mcp` 仓库名不一致。这是 [issue #181](https://gitea.com/gitea/gitea-mcp/issues/181) 中记录的已知不一致,为避免破坏现有安装,镜像名暂不改动。详见 [docs/adr/docker-image-naming.md](docs/adr/docker-image-naming.md)。
|
||||
|
||||
```bash
|
||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||
cd gitea-mcp
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
可從 [發布頁面](https://gitea.com/gitea/gitea-mcp/releases) 下載二進位檔並放入 `PATH`,或使用 `docker.gitea.com/gitea-mcp-server` 映像檔,也可用 `make` 與 Go 1.26 以上從原始碼建置到 `$GOPATH/bin`:
|
||||
|
||||
> 已發布的 Docker 映像檔名稱為 `docker.gitea.com/gitea-mcp-server`,與 `gitea-mcp` 倉庫名稱不一致。這是 [issue #181](https://gitea.com/gitea/gitea-mcp/issues/181) 中記錄的已知不一致,為避免破壞現有安裝,映像檔名稱暫不變更。詳見 [docs/adr/docker-image-naming.md](docs/adr/docker-image-naming.md)。
|
||||
|
||||
```bash
|
||||
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||
cd gitea-mcp
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Docker image naming mismatch (issue #181)
|
||||
|
||||
## Current state
|
||||
|
||||
The project repository is `gitea.com/gitea/gitea-mcp`, but the Docker image is
|
||||
published as `docker.gitea.com/gitea-mcp-server`. This mismatch was raised in
|
||||
[issue #181](https://gitea.com/gitea/gitea-mcp/issues/181).
|
||||
|
||||
## Maintainers' direction
|
||||
|
||||
Per the issue discussion, the maintainers' preferred long-term name is
|
||||
`gitea/mcp-server`, matching the naming scheme used by `gitea/act_runner`
|
||||
(published as a `runner`-style short name) and by comparable projects such as
|
||||
`github/github-mcp-server`. The name `mcp-server` was preferred over
|
||||
`gitea-mcp-server` because the repository is primarily run as a local client
|
||||
process, not a traditional long-running server.
|
||||
|
||||
## Decision
|
||||
|
||||
No rename has happened yet; the discussion was explicitly left open in the
|
||||
issue. The current image name, `docker.gitea.com/gitea-mcp-server`, remains in
|
||||
use so that existing user configurations and documentation keep working.
|
||||
`org.opencontainers.image.title` and `org.opencontainers.image.description`
|
||||
labels were added to the `Dockerfile` to make the image self-describing
|
||||
regardless of the tag it is published under.
|
||||
|
||||
If the image is renamed in the future, update the `docker.gitea.com/gitea-mcp-server`
|
||||
references across `README.md`, `README.zh-cn.md` and `README.zh-tw.md` together
|
||||
with this document.
|
||||
@@ -1,193 +0,0 @@
|
||||
package label
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
func Test_Tool_Registration(t *testing.T) {
|
||||
if got := Tool.Scope(); got != "label" {
|
||||
t.Fatalf("Scope() = %q, want %q", got, "label")
|
||||
}
|
||||
|
||||
readTools := Tool.ReadTools()
|
||||
if len(readTools) != 1 || readTools[0].Tool.Name != LabelReadToolName {
|
||||
t.Fatalf("ReadTools() = %v, want exactly [%s]", toolNames(readTools), LabelReadToolName)
|
||||
}
|
||||
if !readTools[0].Tool.Annotations.ReadOnlyHint {
|
||||
t.Fatalf("%s must be marked read-only", LabelReadToolName)
|
||||
}
|
||||
|
||||
writeTools := Tool.WriteTools()
|
||||
if len(writeTools) != 1 || writeTools[0].Tool.Name != LabelWriteToolName {
|
||||
t.Fatalf("WriteTools() = %v, want exactly [%s]", toolNames(writeTools), LabelWriteToolName)
|
||||
}
|
||||
if writeTools[0].Tool.Annotations.ReadOnlyHint {
|
||||
t.Fatalf("%s must not be marked read-only", LabelWriteToolName)
|
||||
}
|
||||
|
||||
assertMethodEnum(t, LabelReadTool, []string{"list_repo_labels", "get_repo_label", "list_org_labels"})
|
||||
assertMethodEnum(t, LabelWriteTool, []string{
|
||||
"create_repo_label", "edit_repo_label", "delete_repo_label",
|
||||
"create_org_label", "edit_org_label", "delete_org_label",
|
||||
})
|
||||
}
|
||||
|
||||
func toolNames(tools []tool.ServerTool) []string {
|
||||
names := make([]string, len(tools))
|
||||
for i, serverTool := range tools {
|
||||
names[i] = serverTool.Tool.Name
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func assertMethodEnum(t *testing.T, definition *mcp.Tool, want []string) {
|
||||
t.Helper()
|
||||
|
||||
schema, ok := definition.InputSchema.(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: input schema = %T, want map[string]any", definition.Name, definition.InputSchema)
|
||||
}
|
||||
properties, ok := schema["properties"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: properties = %T, want map[string]any", definition.Name, schema["properties"])
|
||||
}
|
||||
method, ok := properties["method"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: method property = %T, want map[string]any", definition.Name, properties["method"])
|
||||
}
|
||||
enum, ok := method["enum"].([]string)
|
||||
if !ok {
|
||||
t.Fatalf("%s: method enum = %T, want []string", definition.Name, method["enum"])
|
||||
}
|
||||
|
||||
got := append([]string{}, enum...)
|
||||
sort.Strings(got)
|
||||
wantSorted := append([]string{}, want...)
|
||||
sort.Strings(wantSorted)
|
||||
if !reflect.DeepEqual(got, wantSorted) {
|
||||
t.Fatalf("%s: method enum = %v, want %v", definition.Name, enum, want)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_labelReadFn_listRepoLabels(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
repo = "demo"
|
||||
)
|
||||
|
||||
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.12.0"}`))
|
||||
case fmt.Sprintf("/api/v1/repos/%s/%s/labels", owner, repo):
|
||||
_, _ = w.Write([]byte(`[{"id":1,"name":"bug","color":"ff0000","description":"a bug"}]`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
withTestFlags(t, server.URL)
|
||||
|
||||
result, err := labelReadFn(context.Background(), map[string]any{
|
||||
"method": "list_repo_labels",
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
})
|
||||
if err != nil || result.IsError {
|
||||
t.Fatalf("list_repo_labels err=%v result=%v", err, result)
|
||||
}
|
||||
|
||||
var labels []map[string]any
|
||||
decodeResult(t, result, &labels)
|
||||
if len(labels) != 1 || labels[0]["name"] != "bug" {
|
||||
t.Fatalf("unexpected labels: %v", labels)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_labelWriteFn_createRepoLabel(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
repo = "demo"
|
||||
)
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
body map[string]any
|
||||
)
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.URL.Path == "/api/v1/version":
|
||||
_, _ = w.Write([]byte(`{"version":"1.12.0"}`))
|
||||
case r.URL.Path == fmt.Sprintf("/api/v1/repos/%s/%s/labels", owner, repo) && r.Method == http.MethodPost:
|
||||
mu.Lock()
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
mu.Unlock()
|
||||
_, _ = w.Write([]byte(`{"id":7,"name":"bug","color":"ff0000","description":"a bug"}`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
withTestFlags(t, server.URL)
|
||||
|
||||
result, err := labelWriteFn(context.Background(), map[string]any{
|
||||
"method": "create_repo_label",
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"name": "bug",
|
||||
"color": "ff0000",
|
||||
"description": "a bug",
|
||||
})
|
||||
if err != nil || result.IsError {
|
||||
t.Fatalf("create_repo_label err=%v result=%v", err, result)
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if body["name"] != "bug" || body["color"] != "ff0000" {
|
||||
t.Fatalf("unexpected request body: %v", body)
|
||||
}
|
||||
|
||||
var label map[string]any
|
||||
decodeResult(t, result, &label)
|
||||
if label["name"] != "bug" {
|
||||
t.Fatalf("unexpected label: %v", label)
|
||||
}
|
||||
}
|
||||
|
||||
func withTestFlags(t *testing.T, host string) {
|
||||
t.Helper()
|
||||
origHost, origToken, origVersion := flag.Host, flag.Token, flag.Version
|
||||
flag.Host, flag.Token, flag.Version = host, "", "test"
|
||||
t.Cleanup(func() { flag.Host, flag.Token, flag.Version = origHost, origToken, origVersion })
|
||||
}
|
||||
|
||||
func decodeResult(t *testing.T, result *mcp.CallToolResult, out any) {
|
||||
t.Helper()
|
||||
if len(result.Content) != 1 {
|
||||
t.Fatalf("result content = %v, want exactly one item", result.Content)
|
||||
}
|
||||
text, ok := result.Content[0].(*mcp.TextContent)
|
||||
if !ok {
|
||||
t.Fatalf("result content = %T, want *mcp.TextContent", result.Content[0])
|
||||
}
|
||||
if err := json.Unmarshal([]byte(text.Text), out); err != nil {
|
||||
t.Fatalf("decode result: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -7,122 +7,14 @@ import (
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
func Test_Tool_Registration(t *testing.T) {
|
||||
if got := Tool.Scope(); got != "milestone" {
|
||||
t.Fatalf("Scope() = %q, want %q", got, "milestone")
|
||||
}
|
||||
|
||||
readTools := Tool.ReadTools()
|
||||
if len(readTools) != 1 || readTools[0].Tool.Name != MilestoneReadToolName {
|
||||
t.Fatalf("ReadTools() = %v, want exactly [%s]", toolNames(readTools), MilestoneReadToolName)
|
||||
}
|
||||
if !readTools[0].Tool.Annotations.ReadOnlyHint {
|
||||
t.Fatalf("%s must be marked read-only", MilestoneReadToolName)
|
||||
}
|
||||
|
||||
writeTools := Tool.WriteTools()
|
||||
if len(writeTools) != 1 || writeTools[0].Tool.Name != MilestoneWriteToolName {
|
||||
t.Fatalf("WriteTools() = %v, want exactly [%s]", toolNames(writeTools), MilestoneWriteToolName)
|
||||
}
|
||||
if writeTools[0].Tool.Annotations.ReadOnlyHint {
|
||||
t.Fatalf("%s must not be marked read-only", MilestoneWriteToolName)
|
||||
}
|
||||
|
||||
assertMethodEnum(t, MilestoneReadTool, []string{"get", "list"})
|
||||
assertMethodEnum(t, MilestoneWriteTool, []string{"create", "update", "edit", "delete"})
|
||||
}
|
||||
|
||||
func toolNames(tools []tool.ServerTool) []string {
|
||||
names := make([]string, len(tools))
|
||||
for i, serverTool := range tools {
|
||||
names[i] = serverTool.Tool.Name
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func assertMethodEnum(t *testing.T, definition *mcp.Tool, want []string) {
|
||||
t.Helper()
|
||||
|
||||
schema, ok := definition.InputSchema.(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: input schema = %T, want map[string]any", definition.Name, definition.InputSchema)
|
||||
}
|
||||
properties, ok := schema["properties"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: properties = %T, want map[string]any", definition.Name, schema["properties"])
|
||||
}
|
||||
method, ok := properties["method"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("%s: method property = %T, want map[string]any", definition.Name, properties["method"])
|
||||
}
|
||||
enum, ok := method["enum"].([]string)
|
||||
if !ok {
|
||||
t.Fatalf("%s: method enum = %T, want []string", definition.Name, method["enum"])
|
||||
}
|
||||
|
||||
got := append([]string{}, enum...)
|
||||
sort.Strings(got)
|
||||
wantSorted := append([]string{}, want...)
|
||||
sort.Strings(wantSorted)
|
||||
if !reflect.DeepEqual(got, wantSorted) {
|
||||
t.Fatalf("%s: method enum = %v, want %v", definition.Name, enum, want)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_listMilestonesFn(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
repo = "demo"
|
||||
)
|
||||
|
||||
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.12.0"}`))
|
||||
case fmt.Sprintf("/api/v1/repos/%s/%s/milestones", owner, repo):
|
||||
_, _ = w.Write([]byte(`[{"id":1,"title":"v1","state":"open"}]`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
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 }()
|
||||
|
||||
result, err := listMilestonesFn(context.Background(), map[string]any{
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
})
|
||||
if err != nil || result.IsError {
|
||||
t.Fatalf("list err=%v result=%v", err, result)
|
||||
}
|
||||
|
||||
text, ok := result.Content[0].(*mcp.TextContent)
|
||||
if !ok {
|
||||
t.Fatalf("result content = %T, want *mcp.TextContent", result.Content[0])
|
||||
}
|
||||
var milestones []map[string]any
|
||||
if err := json.Unmarshal([]byte(text.Text), &milestones); err != nil {
|
||||
t.Fatalf("decode result: %v", err)
|
||||
}
|
||||
if len(milestones) != 1 || milestones[0]["title"] != "v1" {
|
||||
t.Fatalf("unexpected milestones: %v", milestones)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_milestoneWriteFn_dueOn(t *testing.T) {
|
||||
const (
|
||||
owner = "octo"
|
||||
|
||||
@@ -22,6 +22,38 @@ var readmeAccessLabels = map[string]map[string]string{
|
||||
"../README.zh-tw.md": {"讀取": "read", "寫入": "write"},
|
||||
}
|
||||
|
||||
// publishedDockerImage is the image name published for this project. See
|
||||
// docs/adr/docker-image-naming.md for why it differs from the repository name.
|
||||
const publishedDockerImage = "docker.gitea.com/gitea-mcp-server"
|
||||
|
||||
// dockerImageReference matches any docker.gitea.com/<name> image reference so
|
||||
// stray typos or partial renames in the README files can be caught.
|
||||
var dockerImageReference = regexp.MustCompile(`docker\.gitea\.com/[a-zA-Z0-9._-]+`)
|
||||
|
||||
// TestReadmeDockerImageReferencesAreConsistent ensures every README mentions
|
||||
// the same, currently published Docker image name. A partial rename, where
|
||||
// one example is updated but another is missed, would otherwise leave users
|
||||
// copying a command that pulls a nonexistent image.
|
||||
func TestReadmeDockerImageReferencesAreConsistent(t *testing.T) {
|
||||
for _, path := range []string{"../README.md", "../README.zh-cn.md", "../README.zh-tw.md"} {
|
||||
t.Run(filepath.Base(path), func(t *testing.T) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
references := dockerImageReference.FindAllString(string(content), -1)
|
||||
if len(references) == 0 {
|
||||
t.Fatalf("no docker.gitea.com image reference found in %s", path)
|
||||
}
|
||||
for _, ref := range references {
|
||||
if ref != publishedDockerImage {
|
||||
t.Errorf("found image reference %q in %s, want %q", ref, path, publishedDockerImage)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// toolInfo is what TestReadmeToolTables tracks per tool, both as registered
|
||||
// in code and as documented in a README, so the two can be compared.
|
||||
type toolInfo struct {
|
||||
|
||||
Reference in New Issue
Block a user