mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2025-08-24 14:53:06 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
001383142f | ||
|
b35919989f | ||
|
d0225c4c24 | ||
|
6993bb2b5d | ||
|
f1b4a208a7 | ||
|
d76f02a234 | ||
|
b2bde61882 | ||
|
7cfa1fa218 | ||
|
1fecc1df30 | ||
|
8dc9ed9299 | ||
|
1965c9830b | ||
|
f377f06478 | ||
|
02fd91da86 | ||
|
55f32ef4f5 | ||
|
c9cada1a8d | ||
|
a784029828 | ||
|
f27c4c622d | ||
|
df47a0c9eb | ||
|
e3307adbdf | ||
|
afada4435e | ||
|
6285bd2467 | ||
|
5bbf8e0afb | ||
|
0535f5bab7 |
@@ -1,19 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "Gitea MCP DevContainer",
|
"name": "Gitea MCP DevContainer",
|
||||||
"image": "mcr.microsoft.com/devcontainers/go:1.24-bookworm",
|
"image": "mcr.microsoft.com/devcontainers/go:1.24-bookworm",
|
||||||
"features": {
|
"features": {},
|
||||||
},
|
"customizations": {
|
||||||
"customizations": {
|
"vscode": {
|
||||||
"vscode": {
|
"settings": {},
|
||||||
"settings": {},
|
"extensions": [
|
||||||
"extensions": [
|
"editorconfig.editorconfig",
|
||||||
"editorconfig.editorconfig",
|
"dbaeumer.vscode-eslint",
|
||||||
"dbaeumer.vscode-eslint",
|
"golang.go",
|
||||||
"golang.go",
|
"stylelint.vscode-stylelint",
|
||||||
"stylelint.vscode-stylelint",
|
"DavidAnson.vscode-markdownlint",
|
||||||
"DavidAnson.vscode-markdownlint",
|
"github.copilot"
|
||||||
"github.copilot"
|
]
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
61
.dockerignore
Normal file
61
.dockerignore
Normal 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
|
51
.gitea/workflows/release-nightly.yml
Normal file
51
.gitea/workflows/release-nightly.yml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
name: release-nightly
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_ORG: gitea
|
||||||
|
DOCKER_LATEST: nightly
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker BuildX
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get Meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||||
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/-/+/' | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}-server:${{ env.DOCKER_LATEST }}
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.meta.outputs.REPO_VERSION }}
|
@@ -3,36 +3,69 @@ name: release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- "*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: setup go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: 'go.mod'
|
go-version: stable
|
||||||
- name: release-build
|
- name: Run GoReleaser
|
||||||
run: go build -ldflags="-s -w -X 'main.Version=${{ gitea.ref_name }}'" -o bin/mcp-gitea-${{ gitea.ref_name }}-linux-amd64
|
uses: goreleaser/goreleaser-action@v6
|
||||||
- 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
|
|
||||||
with:
|
with:
|
||||||
files: |-
|
distribution: goreleaser
|
||||||
bin/**
|
# 'latest', 'nightly', or a semver
|
||||||
token: '${{secrets.RELEASE_TOKEN}}'
|
version: "~> v2"
|
||||||
|
args: release --clean
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GORELEASER_FORCE_TOKEN: "gitea"
|
||||||
|
|
||||||
|
release-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_ORG: gitea
|
||||||
|
DOCKER_LATEST: latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker BuildX
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USER }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get Meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||||
|
echo REPO_VERSION=${GITHUB_REF_NAME#v} >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}-server:${{ steps.meta.outputs.REPO_VERSION }}
|
||||||
|
${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}-server:${{ env.DOCKER_LATEST }}
|
||||||
|
76
.goreleaser.yaml
Normal file
76
.goreleaser.yaml
Normal 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
|
37
Dockerfile
Normal file
37
Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM golang:1.24-bullseye AS builder
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go.mod and go.sum files
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
# Download dependencies
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${VERSION}" -o gitea-mcp
|
||||||
|
|
||||||
|
# Final stage
|
||||||
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install ca-certificates for HTTPS requests
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Create a non-root user
|
||||||
|
RUN useradd -r -u 1000 -m gitea-mcp
|
||||||
|
|
||||||
|
COPY --from=builder --chown=1000:1000 /app/gitea-mcp .
|
||||||
|
|
||||||
|
# Use the non-root user
|
||||||
|
USER gitea-mcp
|
||||||
|
|
||||||
|
CMD ["/app/gitea-mcp", "-t", "stdio"]
|
39
Makefile
39
Makefile
@@ -3,25 +3,50 @@ 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)"
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help: ## Print this help message.
|
||||||
|
@echo "Usage: make [target]"
|
||||||
|
@echo ""
|
||||||
|
@echo "Targets:"
|
||||||
|
@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
|
.PHONY: build
|
||||||
build:
|
build: ## Build the application.
|
||||||
$(GO) build -v -ldflags '-s -w $(LDFLAGS)' -o $(EXECUTABLE)
|
$(GO) build -v -ldflags '-s -w $(LDFLAGS)' -o $(EXECUTABLE)
|
||||||
|
|
||||||
## air: install air for hot reload
|
|
||||||
.PHONY: air
|
.PHONY: air
|
||||||
air:
|
air: ## Install air for hot reload.
|
||||||
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
$(GO) install github.com/air-verse/air@latest; \
|
$(GO) install github.com/air-verse/air@latest; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## dev: run the application with hot reload
|
|
||||||
.PHONY: dev
|
.PHONY: dev
|
||||||
dev: air
|
dev: air ## run the application with hot reload
|
||||||
air --build.cmd "make build" --build.bin ./gitea-mcp
|
air --build.cmd "make build" --build.bin ./gitea-mcp
|
||||||
|
|
||||||
## vendor: tidy and verify module dependencies
|
|
||||||
.PHONY: vendor
|
.PHONY: vendor
|
||||||
vendor:
|
vendor: ## tidy and verify module dependencies
|
||||||
@echo 'Tidying and verifying module dependencies...'
|
@echo 'Tidying and verifying module dependencies...'
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod verify
|
go mod verify
|
139
README.md
139
README.md
@@ -1,14 +1,67 @@
|
|||||||
# Gitea MCP Server
|
# Gitea MCP Server
|
||||||
|
|
||||||
|
[繁體中文](README.zh-tw.md) | [简体中文](README.zh-cn.md)
|
||||||
|
|
||||||
**Gitea MCP Server** is an integration plugin designed to connect Gitea with Model Context Protocol (MCP) systems. This allows for seamless command execution and repository management through an MCP-compatible chat interface.
|
**Gitea MCP Server** is an integration plugin designed to connect Gitea with Model Context Protocol (MCP) systems. This allows for seamless command execution and repository management through an MCP-compatible chat interface.
|
||||||
|
|
||||||
## 🚧Installation
|
[](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}) [](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}&quality=insiders)
|
||||||
|
|
||||||
### 📥Download the official binary release
|
## What is Gitea?
|
||||||
|
|
||||||
|
Gitea is a community-managed lightweight code hosting solution written in Go. It is published under the MIT license. Gitea provides Git hosting including a repository viewer, issue tracking, pull requests, and more.
|
||||||
|
|
||||||
|
## What is MCP?
|
||||||
|
|
||||||
|
Model Context Protocol (MCP) is a protocol that allows for the integration of various tools and systems through a chat interface. It enables seamless command execution and management of repositories, users, and other resources.
|
||||||
|
|
||||||
|
## 🚧 Installation
|
||||||
|
|
||||||
|
### Usage with VS Code
|
||||||
|
|
||||||
|
For quick installation, use one of the one-click install buttons at the top of this README.
|
||||||
|
|
||||||
|
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing `Ctrl + Shift + P` and typing `Preferences: Open User Settings (JSON)`.
|
||||||
|
|
||||||
|
Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace. This will allow you to share the configuration with others.
|
||||||
|
|
||||||
|
> Note that the `mcp` key is not needed in the `.vscode/mcp.json` file.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcp": {
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"type": "promptString",
|
||||||
|
"id": "gitea_token",
|
||||||
|
"description": "Gitea Personal Access Token",
|
||||||
|
"password": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"servers": {
|
||||||
|
"github": {
|
||||||
|
"command": "docker",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"-i",
|
||||||
|
"--rm",
|
||||||
|
"-e",
|
||||||
|
"GITEA_ACCESS_TOKEN",
|
||||||
|
"docker.gitea.com/gitea-mcp-server"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"GITEA_ACCESS_TOKEN": "${input:gitea_token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📥 Download the official binary release
|
||||||
|
|
||||||
You can download the official release from [here](https://gitea.com/gitea/gitea-mcp/releases).
|
You can download the official release from [here](https://gitea.com/gitea/gitea-mcp/releases).
|
||||||
|
|
||||||
### 🔧Build from Source
|
### 🔧 Build from Source
|
||||||
|
|
||||||
You can download the source code by cloning the repository using Git:
|
You can download the source code by cloning the repository using Git:
|
||||||
|
|
||||||
@@ -24,18 +77,18 @@ Before building, make sure you have the following installed:
|
|||||||
Then run:
|
Then run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make build
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📁Add to PATH
|
### 📁 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
|
```bash
|
||||||
cp gitea-mcp /usr/local/bin/
|
cp gitea-mcp /usr/local/bin/
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🚀Usage
|
## 🚀 Usage
|
||||||
|
|
||||||
This example is for Cursor, you can also use plugins in VSCode.
|
This example is for Cursor, you can also use plugins in VSCode.
|
||||||
To configure the MCP server for Gitea, add the following to your MCP configuration file:
|
To configure the MCP server for Gitea, add the following to your MCP configuration file:
|
||||||
@@ -48,12 +101,15 @@ To configure the MCP server for Gitea, add the following to your MCP configurati
|
|||||||
"gitea": {
|
"gitea": {
|
||||||
"command": "gitea-mcp",
|
"command": "gitea-mcp",
|
||||||
"args": [
|
"args": [
|
||||||
"-t", "stdio",
|
"-t",
|
||||||
"--host", "https://gitea.com"
|
"stdio",
|
||||||
|
"--host",
|
||||||
|
"https://gitea.com"
|
||||||
// "--token", "<your personal access token>"
|
// "--token", "<your personal access token>"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
// "GITEA_HOST": "https://gitea.com",
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INSECURE": "true",
|
||||||
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +129,8 @@ To configure the MCP server for Gitea, add the following to your MCP configurati
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Default log path**: `$HOME/.gitea-mcp/gitea-mcp.log`
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> You can provide your Gitea host and access token either as command-line arguments or environment variables.
|
> You can provide your Gitea host and access token either as command-line arguments or environment variables.
|
||||||
> Command-line arguments have the highest priority
|
> Command-line arguments have the highest priority
|
||||||
@@ -83,37 +141,37 @@ Once everything is set up, try typing the following in your MCP-compatible chatb
|
|||||||
list all my repositories
|
list all my repositories
|
||||||
```
|
```
|
||||||
|
|
||||||
## ✅Available Tools
|
## ✅ Available Tools
|
||||||
|
|
||||||
The Gitea MCP Server supports the following tools:
|
The Gitea MCP Server supports the following tools:
|
||||||
|
|
||||||
| Tool | Scope | Description |
|
| Tool | Scope | Description |
|
||||||
|:------:|:-------:|:------------:|
|
| :--------------------------: | :----------: | :---------------------------------------------------: |
|
||||||
|get_my_user_info|User|Get the information of the authenticated user|
|
| get_my_user_info | User | Get the information of the authenticated user |
|
||||||
|create_repo|Repository|Create a new repository|
|
| create_repo | Repository | Create a new repository |
|
||||||
|fork_repo|Repository|Fork a repository|
|
| fork_repo | Repository | Fork a repository |
|
||||||
|list_my_repos|Repository|List all repositories owned by the authenticated user|
|
| list_my_repos | Repository | List all repositories owned by the authenticated user |
|
||||||
|create_branch|Branch|Create a new branch|
|
| create_branch | Branch | Create a new branch |
|
||||||
|delete_branch|Branch|Delete a branch|
|
| delete_branch | Branch | Delete a branch |
|
||||||
|list_branches|Branch|List all branches in a repository|
|
| list_branches | Branch | List all branches in a repository |
|
||||||
|list_repo_commits|Commit|List all commits in a repository|
|
| list_repo_commits | Commit | List all commits in a repository |
|
||||||
|get_file_content|File|Get the content and metadata of a file|
|
| get_file_content | File | Get the content and metadata of a file |
|
||||||
|create_file|File|Create a new file|
|
| create_file | File | Create a new file |
|
||||||
|update_file|File|Update an existing file|
|
| update_file | File | Update an existing file |
|
||||||
|delete_file|File|Delete a file|
|
| delete_file | File | Delete a file |
|
||||||
|get_issue_by_index|Issue|Get an issue by its index|
|
| get_issue_by_index | Issue | Get an issue by its index |
|
||||||
|list_repo_issues|Issue|List all issues in a repository|
|
| list_repo_issues | Issue | List all issues in a repository |
|
||||||
|create_issue|Issue|Create a new issue|
|
| create_issue | Issue | Create a new issue |
|
||||||
|create_issue_comment|Issue|Create a comment on an issue|
|
| create_issue_comment | Issue | Create a comment on an issue |
|
||||||
|get_pull_request_by_index|Pull Request|Get a pull request by its index|
|
| get_pull_request_by_index | Pull Request | Get a pull request by its index |
|
||||||
|list_repo_pull_requests|Pull Request|List all pull requests in a repository|
|
| list_repo_pull_requests | Pull Request | List all pull requests in a repository |
|
||||||
|create_pull_request|Pull Request|Create a new pull request|
|
| create_pull_request | Pull Request | Create a new pull request |
|
||||||
|search_users|User|Search for users|
|
| search_users | User | Search for users |
|
||||||
|search_org_teams|Organization|Search for teams in an organization|
|
| search_org_teams | Organization | Search for teams in an organization |
|
||||||
|search_repos|Repository|Search for repositories|
|
| search_repos | Repository | Search for repositories |
|
||||||
|get_gitea_mcp_server_version|Server|Get the version of the Gitea MCP Server|
|
| get_gitea_mcp_server_version | Server | Get the version of the Gitea MCP Server |
|
||||||
|
|
||||||
## 🐛Debugging
|
## 🐛 Debugging
|
||||||
|
|
||||||
To enable debug mode, add the `-d` flag when running the Gitea MCP Server with sse mode:
|
To enable debug mode, add the `-d` flag when running the Gitea MCP Server with sse mode:
|
||||||
|
|
||||||
@@ -121,4 +179,13 @@ To enable debug mode, add the `-d` flag when running the Gitea MCP Server with s
|
|||||||
./gitea-mcp -t sse [--port 8080] --token <your personal access token> -d
|
./gitea-mcp -t sse [--port 8080] --token <your personal access token> -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 🛠 Troubleshooting
|
||||||
|
|
||||||
|
If you encounter any issues, here are some common troubleshooting steps:
|
||||||
|
|
||||||
|
1. **Check your PATH**: Ensure that the `gitea-mcp` binary is in a directory included in your system's PATH.
|
||||||
|
2. **Verify dependencies**: Make sure you have all the required dependencies installed, such as `make` and `Golang`.
|
||||||
|
3. **Review configuration**: Double-check your MCP configuration file for any errors or missing information.
|
||||||
|
4. **Consult logs**: Check the logs for any error messages or warnings that can provide more information about the issue.
|
||||||
|
|
||||||
Enjoy exploring and managing your Gitea repositories via chat!
|
Enjoy exploring and managing your Gitea repositories via chat!
|
||||||
|
191
README.zh-cn.md
Normal file
191
README.zh-cn.md
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
# Gitea MCP 服务器
|
||||||
|
|
||||||
|
[English](README.md) | [繁體中文](README.zh-tw.md)
|
||||||
|
|
||||||
|
**Gitea MCP 服务器** 是一个集成插件,旨在将 Gitea 与 Model Context Protocol (MCP) 系统连接起来。这允许通过 MCP 兼容的聊天界面无缝执行命令和管理仓库。
|
||||||
|
|
||||||
|
[](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}) [](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}&quality=insiders)
|
||||||
|
|
||||||
|
## 什么是 Gitea?
|
||||||
|
|
||||||
|
Gitea 是一个由社区管理的轻量级代码托管解决方案,使用 Go 语言编写。它以 MIT 许可证发布。Gitea 提供 Git 托管,包括仓库查看器、问题追踪、拉取请求等功能。
|
||||||
|
|
||||||
|
## 什么是 MCP?
|
||||||
|
|
||||||
|
Model Context Protocol (MCP) 是一种协议,允许通过聊天界面整合各种工具和系统。它能够无缝执行命令和管理仓库、用户和其他资源。
|
||||||
|
|
||||||
|
## 🚧 安装
|
||||||
|
|
||||||
|
### 在 VS Code 中使用
|
||||||
|
|
||||||
|
要快速安装,请使用本 README 顶部的单击安装按钮之一。
|
||||||
|
|
||||||
|
要手动安装,请将以下 JSON 块添加到 VS Code 的用户设置 (JSON) 文件中。您可以通过按 `Ctrl + Shift + P` 并输入 `Preferences: Open User Settings (JSON)` 来完成此操作。
|
||||||
|
|
||||||
|
或者,您可以将其添加到工作区中的 `.vscode/mcp.json` 文件中。这将允许您与他人共享配置。
|
||||||
|
|
||||||
|
> 请注意,`.vscode/mcp.json` 文件中不需要 `mcp` 键。
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcp": {
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"type": "promptString",
|
||||||
|
"id": "gitea_token",
|
||||||
|
"description": "Gitea 个人访问令牌",
|
||||||
|
"password": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"servers": {
|
||||||
|
"github": {
|
||||||
|
"command": "docker",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"-i",
|
||||||
|
"--rm",
|
||||||
|
"-e",
|
||||||
|
"GITEA_ACCESS_TOKEN",
|
||||||
|
"docker.gitea.com/gitea-mcp-server"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"GITEA_ACCESS_TOKEN": "${input:gitea_token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📥 下载官方二进制版本
|
||||||
|
|
||||||
|
您可以从[这里](https://gitea.com/gitea/gitea-mcp/releases)下载官方版本。
|
||||||
|
|
||||||
|
### 🔧 从源代码构建
|
||||||
|
|
||||||
|
您可以使用 Git 克隆仓库来下载源代码:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||||
|
```
|
||||||
|
|
||||||
|
在构建之前,请确保您已安装以下内容:
|
||||||
|
|
||||||
|
- make
|
||||||
|
- Golang (建议使用 Go 1.24 或更高版本)
|
||||||
|
|
||||||
|
然后运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📁 添加到 PATH
|
||||||
|
|
||||||
|
构建后,将二进制文件 gitea-mcp 复制到系统 PATH 中包含的目录。例如:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp gitea-mcp /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 使用
|
||||||
|
|
||||||
|
此示例适用于 Cursor,您也可以在 VSCode 中使用插件。
|
||||||
|
要配置 Gitea 的 MCP 服务器,请将以下内容添加到您的 MCP 配置文件中:
|
||||||
|
|
||||||
|
- **stdio 模式**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"gitea": {
|
||||||
|
"command": "gitea-mcp",
|
||||||
|
"args": [
|
||||||
|
"-t",
|
||||||
|
"stdio",
|
||||||
|
"--host",
|
||||||
|
"https://gitea.com"
|
||||||
|
// "--token", "<your personal access token>"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INSECURE": "true",
|
||||||
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **sse 模式**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"gitea": {
|
||||||
|
"url": "http://localhost:8080/sse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**默认日志路径**: `$HOME/.gitea-mcp/gitea-mcp.log`
|
||||||
|
|
||||||
|
> [!注意]
|
||||||
|
> 您可以通过命令行参数或环境变量提供您的 Gitea 主机和访问令牌。
|
||||||
|
> 命令行参数具有最高优先级
|
||||||
|
|
||||||
|
一切设置完成后,请尝试在您的 MCP 兼容聊天框中输入以下内容:
|
||||||
|
|
||||||
|
```text
|
||||||
|
列出我所有的仓库
|
||||||
|
```
|
||||||
|
|
||||||
|
## ✅ 可用工具
|
||||||
|
|
||||||
|
Gitea MCP 服务器支持以下工具:
|
||||||
|
|
||||||
|
| 工具 | 范围 | 描述 |
|
||||||
|
| :--------------------------: | :------: | :--------------------------: |
|
||||||
|
| get_my_user_info | 用户 | 获取已认证用户的信息 |
|
||||||
|
| create_repo | 仓库 | 创建一个新仓库 |
|
||||||
|
| fork_repo | 仓库 | 复刻一个仓库 |
|
||||||
|
| list_my_repos | 仓库 | 列出已认证用户拥有的所有仓库 |
|
||||||
|
| create_branch | 分支 | 创建一个新分支 |
|
||||||
|
| delete_branch | 分支 | 删除一个分支 |
|
||||||
|
| list_branches | 分支 | 列出仓库中的所有分支 |
|
||||||
|
| list_repo_commits | 提交 | 列出仓库中的所有提交 |
|
||||||
|
| get_file_content | 文件 | 获取文件的内容和元数据 |
|
||||||
|
| create_file | 文件 | 创建一个新文件 |
|
||||||
|
| update_file | 文件 | 更新现有文件 |
|
||||||
|
| delete_file | 文件 | 删除一个文件 |
|
||||||
|
| get_issue_by_index | 问题 | 根据索引获取问题 |
|
||||||
|
| list_repo_issues | 问题 | 列出仓库中的所有问题 |
|
||||||
|
| create_issue | 问题 | 创建一个新问题 |
|
||||||
|
| create_issue_comment | 问题 | 在问题上创建评论 |
|
||||||
|
| get_pull_request_by_index | 拉取请求 | 根据索引获取拉取请求 |
|
||||||
|
| list_repo_pull_requests | 拉取请求 | 列出仓库中的所有拉取请求 |
|
||||||
|
| create_pull_request | 拉取请求 | 创建一个新拉取请求 |
|
||||||
|
| search_users | 用户 | 搜索用户 |
|
||||||
|
| search_org_teams | 组织 | 搜索组织中的团队 |
|
||||||
|
| search_repos | 仓库 | 搜索仓库 |
|
||||||
|
| get_gitea_mcp_server_version | 服务器 | 获取 Gitea MCP 服务器的版本 |
|
||||||
|
|
||||||
|
## 🐛 调试
|
||||||
|
|
||||||
|
要启用调试模式,请在使用 sse 模式运行 Gitea MCP 服务器时添加 `-d` 标志:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gitea-mcp -t sse [--port 8080] --token <your personal access token> -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🛠 疑难排解
|
||||||
|
|
||||||
|
如果您遇到任何问题,以下是一些常见的疑难排解步骤:
|
||||||
|
|
||||||
|
1. **检查您的 PATH**: 确保 `gitea-mcp` 二进制文件位于系统 PATH 中包含的目录中。
|
||||||
|
2. **验证依赖项**: 确保您已安装所有所需的依赖项,例如 `make` 和 `Golang`。
|
||||||
|
3. **检查配置**: 仔细检查您的 MCP 配置文件是否有任何错误或遗漏的信息。
|
||||||
|
4. **查看日志**: 检查日志中是否有任何错误消息或警告,可以提供有关问题的更多信息。
|
||||||
|
|
||||||
|
享受通过聊天探索和管理您的 Gitea 仓库的乐趣!
|
191
README.zh-tw.md
Normal file
191
README.zh-tw.md
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
# Gitea MCP 伺服器
|
||||||
|
|
||||||
|
[English](README.md) | [简体中文](README.zh-cn.md)
|
||||||
|
|
||||||
|
**Gitea MCP 伺服器** 是一個整合插件,旨在將 Gitea 與 Model Context Protocol (MCP) 系統連接起來。這允許通過 MCP 兼容的聊天界面無縫執行命令和管理倉庫。
|
||||||
|
|
||||||
|
[](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}) [](https://insiders.vscode.dev/redirect/mcp/install?name=gitea&inputs=[{%22id%22:%22gitea_token%22,%22type%22:%22promptString%22,%22description%22:%22Gitea%20Personal%20Access%20Token%22,%22password%22:true}]&config={%22command%22:%22docker%22,%22args%22:[%22run%22,%22-i%22,%22--rm%22,%22-e%22,%22GITEA_ACCESS_TOKEN%22,%22docker.gitea.com/gitea-mcp-server%22],%22env%22:{%22GITEA_ACCESS_TOKEN%22:%22${input:gitea_token}%22}}&quality=insiders)
|
||||||
|
|
||||||
|
## 什麼是 Gitea?
|
||||||
|
|
||||||
|
Gitea 是一個由社群管理的輕量級代碼託管解決方案,使用 Go 語言編寫。它以 MIT 許可證發布。Gitea 提供 Git 託管,包括倉庫查看器、問題追蹤、拉取請求等功能。
|
||||||
|
|
||||||
|
## 什麼是 MCP?
|
||||||
|
|
||||||
|
Model Context Protocol (MCP) 是一種協議,允許通過聊天界面整合各種工具和系統。它能夠無縫執行命令和管理倉庫、用戶和其他資源。
|
||||||
|
|
||||||
|
## 🚧 安裝
|
||||||
|
|
||||||
|
### 在 VS Code 中使用
|
||||||
|
|
||||||
|
要快速安裝,請使用本 README 頂部的單擊安裝按鈕之一。
|
||||||
|
|
||||||
|
要手動安裝,請將以下 JSON 塊添加到 VS Code 的用戶設置 (JSON) 文件中。您可以通過按 `Ctrl + Shift + P` 並輸入 `Preferences: Open User Settings (JSON)` 來完成此操作。
|
||||||
|
|
||||||
|
或者,您可以將其添加到工作區中的 `.vscode/mcp.json` 文件中。這將允許您與他人共享配置。
|
||||||
|
|
||||||
|
> 請注意,`.vscode/mcp.json` 文件中不需要 `mcp` 鍵。
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcp": {
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"type": "promptString",
|
||||||
|
"id": "gitea_token",
|
||||||
|
"description": "Gitea 個人訪問令牌",
|
||||||
|
"password": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"servers": {
|
||||||
|
"github": {
|
||||||
|
"command": "docker",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"-i",
|
||||||
|
"--rm",
|
||||||
|
"-e",
|
||||||
|
"GITEA_ACCESS_TOKEN",
|
||||||
|
"docker.gitea.com/gitea-mcp-server"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"GITEA_ACCESS_TOKEN": "${input:gitea_token}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📥 下載官方二進制版本
|
||||||
|
|
||||||
|
您可以從[這裡](https://gitea.com/gitea/gitea-mcp/releases)下載官方版本。
|
||||||
|
|
||||||
|
### 🔧 從源代碼構建
|
||||||
|
|
||||||
|
您可以使用 Git 克隆倉庫來下載源代碼:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://gitea.com/gitea/gitea-mcp.git
|
||||||
|
```
|
||||||
|
|
||||||
|
在構建之前,請確保您已安裝以下內容:
|
||||||
|
|
||||||
|
- make
|
||||||
|
- Golang (建議使用 Go 1.24 或更高版本)
|
||||||
|
|
||||||
|
然後運行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📁 添加到 PATH
|
||||||
|
|
||||||
|
安裝後,將二進制文件 gitea-mcp 複製到系統 PATH 中包含的目錄。例如:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp gitea-mcp /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 使用
|
||||||
|
|
||||||
|
此示例適用於 Cursor,您也可以在 VSCode 中使用插件。
|
||||||
|
要配置 Gitea 的 MCP 伺服器,請將以下內容添加到您的 MCP 配置文件中:
|
||||||
|
|
||||||
|
- **stdio 模式**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"gitea": {
|
||||||
|
"command": "gitea-mcp",
|
||||||
|
"args": [
|
||||||
|
"-t",
|
||||||
|
"stdio",
|
||||||
|
"--host",
|
||||||
|
"https://gitea.com"
|
||||||
|
// "--token", "<your personal access token>"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INSECURE": "true",
|
||||||
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **sse 模式**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"gitea": {
|
||||||
|
"url": "http://localhost:8080/sse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**默認日誌路徑**: `$HOME/.gitea-mcp/gitea-mcp.log`
|
||||||
|
|
||||||
|
> [!注意]
|
||||||
|
> 您可以通過命令行參數或環境變量提供您的 Gitea 主機和訪問令牌。
|
||||||
|
> 命令行參數具有最高優先級
|
||||||
|
|
||||||
|
一切設置完成後,請嘗試在您的 MCP 兼容聊天框中輸入以下內容:
|
||||||
|
|
||||||
|
```text
|
||||||
|
列出我所有的倉庫
|
||||||
|
```
|
||||||
|
|
||||||
|
## ✅ 可用工具
|
||||||
|
|
||||||
|
Gitea MCP 伺服器支持以下工具:
|
||||||
|
|
||||||
|
| 工具 | 範圍 | 描述 |
|
||||||
|
| :--------------------------: | :------: | :--------------------------: |
|
||||||
|
| get_my_user_info | 用戶 | 獲取已認證用戶的信息 |
|
||||||
|
| create_repo | 倉庫 | 創建一個新倉庫 |
|
||||||
|
| fork_repo | 倉庫 | 復刻一個倉庫 |
|
||||||
|
| list_my_repos | 倉庫 | 列出已認證用戶擁有的所有倉庫 |
|
||||||
|
| create_branch | 分支 | 創建一個新分支 |
|
||||||
|
| delete_branch | 分支 | 刪除一個分支 |
|
||||||
|
| list_branches | 分支 | 列出倉庫中的所有分支 |
|
||||||
|
| list_repo_commits | 提交 | 列出倉庫中的所有提交 |
|
||||||
|
| get_file_content | 文件 | 獲取文件的內容和元數據 |
|
||||||
|
| create_file | 文件 | 創建一個新文件 |
|
||||||
|
| update_file | 文件 | 更新現有文件 |
|
||||||
|
| delete_file | 文件 | 刪除一個文件 |
|
||||||
|
| get_issue_by_index | 問題 | 根據索引獲取問題 |
|
||||||
|
| list_repo_issues | 問題 | 列出倉庫中的所有問題 |
|
||||||
|
| create_issue | 問題 | 創建一個新問題 |
|
||||||
|
| create_issue_comment | 問題 | 在問題上創建評論 |
|
||||||
|
| get_pull_request_by_index | 拉取請求 | 根據索引獲取拉取請求 |
|
||||||
|
| list_repo_pull_requests | 拉取請求 | 列出倉庫中的所有拉取請求 |
|
||||||
|
| create_pull_request | 拉取請求 | 創建一個新拉取請求 |
|
||||||
|
| search_users | 用戶 | 搜索用戶 |
|
||||||
|
| search_org_teams | 組織 | 搜索組織中的團隊 |
|
||||||
|
| search_repos | 倉庫 | 搜索倉庫 |
|
||||||
|
| get_gitea_mcp_server_version | 伺服器 | 獲取 Gitea MCP 伺服器的版本 |
|
||||||
|
|
||||||
|
## 🐛 調試
|
||||||
|
|
||||||
|
要啟用調試模式,請在使用 sse 模式運行 Gitea MCP 伺服器時添加 `-d` 標誌:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gitea-mcp -t sse [--port 8080] --token <your personal access token> -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🛠 疑難排解
|
||||||
|
|
||||||
|
如果您遇到任何問題,以下是一些常見的疑難排解步驟:
|
||||||
|
|
||||||
|
1. **檢查您的 PATH**: 確保 `gitea-mcp` 二進制文件位於系統 PATH 中包含的目錄中。
|
||||||
|
2. **驗證依賴項**: 確保您已安裝所有所需的依賴項,例如 `make` 和 `Golang`。
|
||||||
|
3. **檢查配置**: 仔細檢查您的 MCP 配置文件是否有任何錯誤或遺漏的信息。
|
||||||
|
4. **查看日誌**: 檢查日誌中是否有任何錯誤消息或警告,可以提供有關問題的更多信息。
|
||||||
|
|
||||||
|
享受通過聊天探索和管理您的 Gitea 倉庫的樂趣!
|
18
cmd/cmd.go
18
cmd/cmd.go
@@ -35,7 +35,7 @@ func init() {
|
|||||||
flag.StringVar(
|
flag.StringVar(
|
||||||
&host,
|
&host,
|
||||||
"host",
|
"host",
|
||||||
"https://gitea.com",
|
os.Getenv("GITEA_HOST"),
|
||||||
"Gitea host",
|
"Gitea host",
|
||||||
)
|
)
|
||||||
flag.IntVar(
|
flag.IntVar(
|
||||||
@@ -62,13 +62,16 @@ func init() {
|
|||||||
true,
|
true,
|
||||||
"debug mode",
|
"debug mode",
|
||||||
)
|
)
|
||||||
|
flag.BoolVar(
|
||||||
|
&flagPkg.Insecure,
|
||||||
|
"insecure",
|
||||||
|
false,
|
||||||
|
"ignore TLS certificate errors",
|
||||||
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
flagPkg.Host = host
|
flagPkg.Host = host
|
||||||
if flagPkg.Host == "" {
|
|
||||||
flagPkg.Host = os.Getenv("GITEA_HOST")
|
|
||||||
}
|
|
||||||
if flagPkg.Host == "" {
|
if flagPkg.Host == "" {
|
||||||
flagPkg.Host = "https://gitea.com"
|
flagPkg.Host = "https://gitea.com"
|
||||||
}
|
}
|
||||||
@@ -80,12 +83,19 @@ func init() {
|
|||||||
flagPkg.Token = os.Getenv("GITEA_ACCESS_TOKEN")
|
flagPkg.Token = os.Getenv("GITEA_ACCESS_TOKEN")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flagPkg.Mode = transport
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
flagPkg.Debug = debug
|
flagPkg.Debug = debug
|
||||||
}
|
}
|
||||||
if !debug {
|
if !debug {
|
||||||
flagPkg.Debug = os.Getenv("GITEA_DEBUG") == "true"
|
flagPkg.Debug = os.Getenv("GITEA_DEBUG") == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set insecure mode based on environment variable
|
||||||
|
if os.Getenv("GITEA_INSECURE") == "true" {
|
||||||
|
flagPkg.Insecure = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(version string) {
|
func Execute(version string) {
|
||||||
|
7
go.mod
7
go.mod
@@ -3,9 +3,10 @@ module gitea.com/gitea/gitea-mcp
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
code.gitea.io/sdk/gitea v0.20.0
|
code.gitea.io/sdk/gitea v0.21.0
|
||||||
github.com/mark3labs/mcp-go v0.17.0
|
github.com/mark3labs/mcp-go v0.18.0
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -17,5 +18,5 @@ require (
|
|||||||
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.36.0 // indirect
|
golang.org/x/crypto v0.36.0 // indirect
|
||||||
golang.org/x/sys v0.31.0 // indirect
|
golang.org/x/sys v0.32.0 // indirect
|
||||||
)
|
)
|
||||||
|
20
go.sum
20
go.sum
@@ -1,5 +1,5 @@
|
|||||||
code.gitea.io/sdk/gitea v0.20.0 h1:Zm/QDwwZK1awoM4AxdjeAQbxolzx2rIP8dDfmKu+KoU=
|
code.gitea.io/sdk/gitea v0.21.0 h1:69n6oz6kEVHRo1+APQQyizkhrZrLsTLXey9142pfkD4=
|
||||||
code.gitea.io/sdk/gitea v0.20.0/go.mod h1:faouBHC/zyx5wLgjmRKR62ydyvMzwWf3QnU0bH7Cw6U=
|
code.gitea.io/sdk/gitea v0.21.0/go.mod h1:tnBjVhuKJCn8ibdyyhvUyxrR1Ca2KHEoTWoukNhXQPA=
|
||||||
github.com/42wim/httpsig v1.2.2 h1:ofAYoHUNs/MJOLqQ8hIxeyz2QxOz8qdSVvp3PX/oPgA=
|
github.com/42wim/httpsig v1.2.2 h1:ofAYoHUNs/MJOLqQ8hIxeyz2QxOz8qdSVvp3PX/oPgA=
|
||||||
github.com/42wim/httpsig v1.2.2/go.mod h1:P/UYo7ytNBFwc+dg35IubuAUIs8zj5zzFIgUCEl55WY=
|
github.com/42wim/httpsig v1.2.2/go.mod h1:P/UYo7ytNBFwc+dg35IubuAUIs8zj5zzFIgUCEl55WY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
@@ -12,14 +12,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
|
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
|
||||||
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/mark3labs/mcp-go v0.15.0 h1:lViiC4dk6chJHZccezaTzZLMOQVUXJDGNQPtzExr5NQ=
|
github.com/mark3labs/mcp-go v0.18.0 h1:YuhgIVjNlTG2ZOwmrkORWyPTp0dz1opPEqvsPtySXao=
|
||||||
github.com/mark3labs/mcp-go v0.15.0/go.mod h1:xBB350hekQsJAK7gJAii8bcEoWemboLm2mRm5/+KBaU=
|
github.com/mark3labs/mcp-go v0.18.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
|
||||||
github.com/mark3labs/mcp-go v0.17.0 h1:5Ps6T7qXr7De/2QTqs9h6BKeZ/qdeUeGrgM5lPzi930=
|
|
||||||
github.com/mark3labs/mcp-go v0.17.0/go.mod h1:KmJndYv7GIgcPVwEKJjNcbhVQ+hJGJhrCCB/9xITzpE=
|
|
||||||
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/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
|
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
|
||||||
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
|
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
@@ -38,13 +36,15 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
|||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
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=
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
|
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
|
||||||
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
|
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
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=
|
||||||
|
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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@@ -5,6 +5,8 @@ var (
|
|||||||
Port int
|
Port int
|
||||||
Token string
|
Token string
|
||||||
Version string
|
Version string
|
||||||
|
Mode string
|
||||||
|
|
||||||
Debug bool
|
Insecure bool
|
||||||
|
Debug bool
|
||||||
)
|
)
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||||
@@ -16,12 +18,26 @@ var (
|
|||||||
|
|
||||||
func Client() *gitea.Client {
|
func Client() *gitea.Client {
|
||||||
clientOnce.Do(func() {
|
clientOnce.Do(func() {
|
||||||
if client == nil {
|
var err error
|
||||||
c, err := gitea.NewClient(flag.Host, gitea.SetToken(flag.Token))
|
if client != nil {
|
||||||
if err != nil {
|
return
|
||||||
log.Fatalf("create gitea client err: %v", err)
|
}
|
||||||
|
opts := []gitea.ClientOption{
|
||||||
|
gitea.SetToken(flag.Token),
|
||||||
|
}
|
||||||
|
if flag.Insecure {
|
||||||
|
httpClient := &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
client = c
|
opts = append(opts, gitea.SetHTTPClient(httpClient))
|
||||||
|
}
|
||||||
|
client, err = gitea.NewClient(flag.Host, opts...)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("create gitea client err: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return client
|
return client
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -20,12 +22,27 @@ func Default() *zap.Logger {
|
|||||||
if defaultLogger == nil {
|
if defaultLogger == nil {
|
||||||
ec := zap.NewProductionEncoderConfig()
|
ec := zap.NewProductionEncoderConfig()
|
||||||
ec.EncodeTime = zapcore.TimeEncoderOfLayout(time.DateTime)
|
ec.EncodeTime = zapcore.TimeEncoderOfLayout(time.DateTime)
|
||||||
ec.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
ec.EncodeLevel = zapcore.CapitalLevelEncoder
|
||||||
|
|
||||||
var ws zapcore.WriteSyncer
|
var ws zapcore.WriteSyncer
|
||||||
var wss []zapcore.WriteSyncer
|
var wss []zapcore.WriteSyncer
|
||||||
|
|
||||||
wss = append(wss, zapcore.AddSync(os.Stdout))
|
home, _ := os.UserHomeDir()
|
||||||
|
if home == "" {
|
||||||
|
home = os.TempDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
wss = append(wss, zapcore.AddSync(&lumberjack.Logger{
|
||||||
|
Filename: fmt.Sprintf("%s/.gitea-mcp/gitea-mcp.log", home),
|
||||||
|
MaxSize: 100,
|
||||||
|
MaxBackups: 10,
|
||||||
|
MaxAge: 30,
|
||||||
|
}))
|
||||||
|
|
||||||
|
if flag.Mode == "sse" {
|
||||||
|
wss = append(wss, zapcore.AddSync(os.Stdout))
|
||||||
|
}
|
||||||
|
|
||||||
ws = zapcore.NewMultiWriteSyncer(wss...)
|
ws = zapcore.NewMultiWriteSyncer(wss...)
|
||||||
|
|
||||||
enc := zapcore.NewConsoleEncoder(ec)
|
enc := zapcore.NewConsoleEncoder(ec)
|
||||||
@@ -37,7 +54,7 @@ func Default() *zap.Logger {
|
|||||||
}
|
}
|
||||||
core := zapcore.NewCore(enc, ws, level)
|
core := zapcore.NewCore(enc, ws, level)
|
||||||
options := []zap.Option{
|
options := []zap.Option{
|
||||||
zap.AddStacktrace(zapcore.ErrorLevel),
|
zap.AddStacktrace(zapcore.DPanicLevel),
|
||||||
zap.AddCaller(),
|
zap.AddCaller(),
|
||||||
zap.AddCallerSkip(1),
|
zap.AddCallerSkip(1),
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user