9 Commits

Author SHA1 Message Date
hiifong
001383142f fix typo 2025-04-08 14:01:14 +00:00
appleboy
b35919989f ci: update CI environment variables for better token management
- Replace `GITHUB_TOKEN` with `GITEA_TOKEN` and add `GORELEASER_FORCE_TOKEN` environment variable

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-08 21:41:04 +08:00
appleboy
d0225c4c24 build: enhance build process and release configuration
- Add build flags and ldflags for Go builds
- Add Gitea URLs and force token configuration for release

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-08 21:39:21 +08:00
appleboy
6993bb2b5d ci: integrate GoReleaser for streamlined release management
- Rename job from `release` to `goreleaser` in `release-tag.yml`
- Change the tag pattern from `' * '` to `" * "` in `release-tag.yml`
- Update job steps to better describe their actions in `release-tag.yml`
- Replace build steps with GoReleaser action steps in `release-tag.yml`
- Add configuration file `.goreleaser.yaml` for GoReleaser
- Include hooks, builds, archives, changelog sorting, and release footer in `.goreleaser.yaml`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-08 21:34:03 +08:00
Flynn Hou
f1b4a208a7 fix(cmd): ensure GITEA_HOST can be read (#23)
## Why

With the following configuration:

```bash
docker run -i --rm -e GITEA_HOST=<gitea_host> -e GITEA_ACCESS_TOKEN=<gitea_access_token_for_host> docker.gitea.com/gitea-mcp-server:latest
```

after mcp-client calling a tool, the gitea client will encounter the following fatal error:

```
FATAL gitea/gitea.go:47 create gitea client err: user does not exist [uid: 0, name: ]
  gitea.com/gitea/gitea-mcp/pkg/gitea.Client.func1
    /app/pkg/gitea/gitea.go:47
  sync.(*Once).doSlow
    /usr/local/go/src/sync/once.go:78
  sync.(*Once).Do
    /usr/local/go/src/sync/once.go:69
  gitea.com/gitea/gitea-mcp/pkg/gitea.Client
    /app/pkg/gitea/gitea.go:21
  gitea.com/gitea/gitea-mcp/operation/search.SearchReposFn
    /app/operation/search/search.go:161
  github.com/mark3labs/mcp-go/server.(*MCPServer).handleToolCall
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/server.go:717
  github.com/mark3labs/mcp-go/server.(*MCPServer).HandleMessage
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/request_handler.go:264
  github.com/mark3labs/mcp-go/server.(*StdioServer).processMessage
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/stdio.go:228
  github.com/mark3labs/mcp-go/server.(*StdioServer).processInputStream
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/stdio.go:143
  github.com/mark3labs/mcp-go/server.(*StdioServer).Listen
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/stdio.go:209
  github.com/mark3labs/mcp-go/server.ServeStdio
    /go/pkg/mod/github.com/mark3labs/mcp-go@v0.18.0/server/stdio.go:282
  gitea.com/gitea/gitea-mcp/operation.Run
    /app/operation/operation.go:48
  gitea.com/gitea/gitea-mcp/cmd.Execute
    /app/cmd/cmd.go:119
  main.main
    /app/main.go:12
  runtime.main
    /usr/local/go/src/runtime/proc.go:283
```

Turns out the root cause was because the `GITEA_HOST` environment variable wasn't overriding the default flag value, resulting in mismatch of host and access token.

The if statement won't be entered
7cfa1fa218/cmd/cmd.go (L74-L77)

Due to `host` could never be evaluated as an empty string from the default value `"http://gitea.com"`
7cfa1fa218/cmd/cmd.go (L35-L40)

Unless user specify `gitea-mcp ... --host <empty_string> ...` with environment `GITEA_HOST=<non_empty_string>` at the same time, which is very unlikely IMHO.

## How

- Set `host` flag default value from `GITEA_HOST` environment variable value
- Remove possible dead code if-statement

Co-authored-by: hiifong <i@hiif.ong>
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/23
Reviewed-by: hiifong <i@hiif.ong>
Co-authored-by: Flynn Hou <flynnhou7@gmail.com>
Co-committed-by: Flynn Hou <flynnhou7@gmail.com>
2025-04-08 13:08:50 +00:00
appleboy
d76f02a234 chore: refactor Docker configuration and update exclusion rules
- Add a `.dockerignore` file for Docker configuration
- Ignore git-related files and directories
- Exclude Dockerfile and `.dockerignore`
- Ignore build artifacts including binaries and shared libraries
- Add rules for Go-specific files and directories
- Exclude testing-related files and folders
- Ignore files from IDEs and editors
- Exclude OS-specific and temporary files
- Ignore documentation files and directories
- Add development tools configuration files
- Exclude debug files and directories

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-08 21:06:52 +08:00
appleboy
b2bde61882 chore: improve code quality and streamline configuration files
- Compact the features object in the devcontainer configuration

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-08 20:36:27 +08:00
Flynn Hou
7cfa1fa218 docs(readme): rename interactive with insecure (#22)
After https://gitea.com/gitea/gitea-mcp/pulls/20, `GITEA_INSECURE` flag is introduced. However, the READMEs referred to the wrong name.

Replace GITEA_INTERACTIVE terms with `GITEA_INSECURE`.

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/22
Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com>
Co-authored-by: Flynn Hou <flynnhou7@gmail.com>
Co-committed-by: Flynn Hou <flynnhou7@gmail.com>
2025-04-08 05:20:16 +00:00
Bo-Yi Wu
1fecc1df30 build: standardize build and installation process in documentation and Makefile (#21)
- Add install, uninstall, and clean targets to the Makefile
- Change README instructions from `make build` to `make install`
- Update README.zh-cn instructions from `make build` to `make install`
- Update README.zh-tw instructions from `make build` to `make install`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/21
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-04-08 01:33:33 +00:00
9 changed files with 199 additions and 54 deletions

View File

@@ -1,19 +1,18 @@
{
"name": "Gitea MCP DevContainer",
"image": "mcr.microsoft.com/devcontainers/go:1.24-bookworm",
"features": {
},
"customizations": {
"vscode": {
"settings": {},
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"golang.go",
"stylelint.vscode-stylelint",
"DavidAnson.vscode-markdownlint",
"github.copilot"
]
}
"name": "Gitea MCP DevContainer",
"image": "mcr.microsoft.com/devcontainers/go:1.24-bookworm",
"features": {},
"customizations": {
"vscode": {
"settings": {},
"extensions": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"golang.go",
"stylelint.vscode-stylelint",
"DavidAnson.vscode-markdownlint",
"github.copilot"
]
}
}
}
}

61
.dockerignore Normal file
View File

@@ -0,0 +1,61 @@
# Git
.git
.gitignore
.github/
.gitea/
# Docker
Dockerfile
.dockerignore
# Build artifacts
bin/
dist/
build/
*.exe
*.exe~
*.dll
*.so
*.dylib
# Go specific
vendor/
go.work
# Testing
*_test.go
**/test/
**/tests/
coverage.out
coverage.html
# IDE and editor files
.idea/
.vscode/
*.swp
*.swo
*~
# OS specific
.DS_Store
Thumbs.db
# Temporary files
tmp/
temp/
*.tmp
*.log
# Documentation
docs/
*.md
LICENSE
# Development tools
.air.toml
.golangci.yml
.goreleaser.yml
# Debug files
debug
__debug_bin

View File

@@ -1,41 +1,33 @@
name: release
on:
on:
push:
tags:
- '*'
- "*"
jobs:
release:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: release-build
run: go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-linux-amd64
- name: release-build-windows
run: GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-windows-amd64.exe
- name: release-build-darwin
run: GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-darwin-amd64
- name: release-build-arm64
run: GOARCH=arm64 go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-linux-arm64
- name: release-build-windows-arm64
run: GOOS=windows GOARCH=arm64 go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-windows-arm64.exe
- name: release-build-darwin-arm64
run: GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-darwin-arm64
- name: Use Go Action
id: use-go-action
uses: https://gitea.com/actions/gitea-release-action@main
go-version: stable
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
files: |-
bin/**
token: '${{secrets.RELEASE_TOKEN}}'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --clean
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_FORCE_TOKEN: "gitea"
release-image:
runs-on: ubuntu-latest
env:

76
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,76 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
main: .
goos:
- linux
- windows
- darwin
flags:
- -trimpath
ldflags:
- -s -w
- -X main.Version={{.Version}}
archives:
- formats: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
formats: zip
changelog:
sort: asc
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: "Bug fixes"
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: "Enhancements"
regexp: "^.*chore[(\\w)]*:+.*$"
order: 2
- title: "Refactor"
regexp: "^.*refactor[(\\w)]*:+.*$"
order: 3
- title: "Build process updates"
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
order: 4
- title: "Documentation updates"
regexp: ^.*?docs?(\(.+\))??!?:.+$
order: 4
- title: Others
order: 999
filters:
exclude:
- "^docs:"
- "^test:"
release:
footer: >-
---
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
gitea_urls:
api: https://gitea.com/api/v1
download: https://gitea.com
force_token: gitea

View File

@@ -11,6 +11,26 @@ help: ## Print this help message.
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: install
install: build ## Install the application.
@echo "Installing $(EXECUTABLE)..."
@mkdir -p $(GOPATH)/bin
@cp $(EXECUTABLE) $(GOPATH)/bin/$(EXECUTABLE)
@echo "Installed $(EXECUTABLE) to $(GOPATH)/bin/$(EXECUTABLE)"
@echo "Please add $(GOPATH)/bin to your PATH if it is not already there."
.PHONY: uninstall
uninstall: ## Uninstall the application.
@echo "Uninstalling $(EXECUTABLE)..."
@rm -f $(GOPATH)/bin/$(EXECUTABLE)
@echo "Uninstalled $(EXECUTABLE) from $(GOPATH)/bin/$(EXECUTABLE)"
.PHONY: clean
clean: ## Clean the build artifacts.
@echo "Cleaning up build artifacts..."
@rm -f $(EXECUTABLE)
@echo "Cleaned up $(EXECUTABLE)"
.PHONY: build
build: ## Build the application.
$(GO) build -v -ldflags '-s -w $(LDFLAGS)' -o $(EXECUTABLE)

View File

@@ -77,12 +77,12 @@ Before building, make sure you have the following installed:
Then run:
```bash
make build
make install
```
### 📁 Add to PATH
After building, copy the binary gitea-mcp to a directory included in your system's PATH. For example:
After installing, copy the binary gitea-mcp to a directory included in your system's PATH. For example:
```bash
cp gitea-mcp /usr/local/bin/
@@ -109,7 +109,7 @@ To configure the MCP server for Gitea, add the following to your MCP configurati
],
"env": {
// "GITEA_HOST": "https://gitea.com",
// "GITEA_INTERACTIVE": "true",
// "GITEA_INSECURE": "true",
"GITEA_ACCESS_TOKEN": "<your personal access token>"
}
}

View File

@@ -77,7 +77,7 @@ git clone https://gitea.com/gitea/gitea-mcp.git
然后运行:
```bash
make build
make install
```
### 📁 添加到 PATH
@@ -109,7 +109,7 @@ cp gitea-mcp /usr/local/bin/
],
"env": {
// "GITEA_HOST": "https://gitea.com",
// "GITEA_INTERACTIVE": "true",
// "GITEA_INSECURE": "true",
"GITEA_ACCESS_TOKEN": "<your personal access token>"
}
}

View File

@@ -77,12 +77,12 @@ git clone https://gitea.com/gitea/gitea-mcp.git
然後運行:
```bash
make build
make install
```
### 📁 添加到 PATH
構建後,將二進制文件 gitea-mcp 複製到系統 PATH 中包含的目錄。例如:
安裝後,將二進制文件 gitea-mcp 複製到系統 PATH 中包含的目錄。例如:
```bash
cp gitea-mcp /usr/local/bin/
@@ -109,7 +109,7 @@ cp gitea-mcp /usr/local/bin/
],
"env": {
// "GITEA_HOST": "https://gitea.com",
// "GITEA_INTERACTIVE": "true",
// "GITEA_INSECURE": "true",
"GITEA_ACCESS_TOKEN": "<your personal access token>"
}
}

View File

@@ -35,7 +35,7 @@ func init() {
flag.StringVar(
&host,
"host",
"https://gitea.com",
os.Getenv("GITEA_HOST"),
"Gitea host",
)
flag.IntVar(
@@ -72,9 +72,6 @@ func init() {
flag.Parse()
flagPkg.Host = host
if flagPkg.Host == "" {
flagPkg.Host = os.Getenv("GITEA_HOST")
}
if flagPkg.Host == "" {
flagPkg.Host = "https://gitea.com"
}