12 Commits

Author SHA1 Message Date
appleboy
da08718e24 style: refactor code formatting for clarity and conciseness
- Remove extra blank lines for cleaner code formatting
- Combine variable declaration of GetGiteaMCPServerVersionTool into a single line for clarity

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-06-15 19:44:28 +08:00
Bo-Yi Wu
44ea8969f4 refactor: migrate environment config from GITEA_MODE to MCP_MODE (#62)
- Remove the GITEA_MODE environment variable from the Dockerfile
- Switch environment variable usage from GITEA_MODE to MCP_MODE in the Go command initialization

fix https://gitea.com/gitea/gitea-mcp/issues/55

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

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/62
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-06-15 11:40:59 +00:00
Bo-Yi Wu
94aa8dc572 fix: harden log directory creation and path resolution (#61)
- Ensure the log directory is created with secure permissions, falling back to the temp directory if creation fails
- Update log file path to use the resolved log directory

fix https://gitea.com/gitea/gitea-mcp/issues/58

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/61
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-06-13 19:30:14 +00:00
appleboy
05194ffc1c chore: add live reload config and update editor and git settings (#57)
- Add .air.toml configuration file for Air live reloading with specific build and file watch settings
- Ignore the tmp directory in .gitignore
- Rename the gitea server configuration to gitea-mcp-stdio in the VSCode config and add separate configuration for gitea-mcp-http

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/57
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-06-08 03:55:10 +00:00
appleboy
5c329129f8 docs: standardize server configuration naming in documentation (#56)
- Rename the example "github" server configuration to "gitea-mcp" in all README files

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/56
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-06-08 02:51:32 +00:00
natchanonnn
52ccf92761 Add edit issue comment and list issue comments tools (#48)
- Add tools:
  - `edit_issue_comment` for edit issue comments
  - `get_issue_comments_by_index` for getting issue's comment by its index

Co-authored-by: hiifong <i@hiif.ong>
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/48
Co-authored-by: natchanonnn <natchanon.w@loolootech.com>
Co-committed-by: natchanonnn <natchanon.w@loolootech.com>
2025-06-03 10:24:50 +00:00
ZRE
061ea86b0b feat: add GetDirContent tool for retrieving directory entries (#53)
### 🚀 What's Changed
This PR introduces a new MCP tool `get_dir_content` that allows users to retrieve a list of entries (files and subdirectories) from a specified directory in a Gitea repository.

###  Features Added
- **New Tool**: `GetDirContent` tool for directory listing functionality
- **Tool Registration**: Properly registered as a read operation in the MCP server
- **Parameter Validation**: Comprehensive input validation for required parameters
- **Error Handling**: Robust error handling with descriptive error messages

### 🔧 Technical Details
- **Tool Name**: `get_dir_content`
- **Required Parameters**:
  - `owner`: Repository owner
  - `repo`: Repository name
  - `ref`: Branch, tag, or commit reference
  - `filePath`: Directory path to list

### 📁 Files Modified
- file.go: Added tool definition, registration, and handler function

### 🎯 Use Cases
This tool enables users to:
- Browse repository directory structures
- List files and folders in specific directories
- Navigate repository contents programmatically
- Support file management workflows in MCP clients

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/53
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: ZRE <chy853@gmail.com>
Co-committed-by: ZRE <chy853@gmail.com>
2025-05-31 19:37:11 +00:00
appleboy
f14b60fe56 build: update base image to distroless/static-debian12:nonroot (#52)
- Update base image from distroless/static-debian11:nonroot to distroless/static-debian12:nonroot

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/52
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-05-30 07:47:50 +00:00
appleboy
94782a85b6 build: streamline container configuration and metadata (#51)
- Remove the container healthcheck definition
- Delete the image authors label from the build

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/51
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-05-30 06:47:28 +00:00
appleboy
e94dd26b30 build: refactor Dockerfile for security, performance, and flexibility (#50)
- Switch build base image to Alpine and set platform dynamically
- Use distroless nonroot image for final stage to enhance security
- Add build arguments for VERSION, TARGETOS, and TARGETARCH with defaults
- Cache Go module and build dependencies to improve build performance
- Remove manual installation of ca-certificates and user creation (handled by base image)
- Set nonroot user for running the application
- Add healthcheck for the built binary
- Add OCI-compliant author and version labels

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/50
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-05-30 04:58:24 +00:00
appleboy
da49bdeb96 feat: integrate server recovery middleware into MCP server initialization (#49)
- Add server recovery middleware to the MCP server initialization

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/49
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-05-30 04:21:12 +00:00
appleboy
3f61299f72 refactor: refactor HTTP client setup to enhance configuration flexibility (#47)
- Refactor HTTP client initialization to always create a custom http.Client
- Move TLS config modification into the default HTTP client when insecure flag is set
- Ensure the HTTP client is always included in client options

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

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/47
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-05-27 12:52:19 +00:00
14 changed files with 235 additions and 53 deletions

52
.air.toml Normal file
View File

@@ -0,0 +1,52 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = ["-t", "http"]
bin = "./gitea-mcp"
cmd = "make build"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
silent = false
time = false
[misc]
clean_on_exit = false
[proxy]
app_port = 0
enabled = false
proxy_port = 0
[screen]
clear_on_rebuild = false
keep_scroll = true

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
gitea-mcp gitea-mcp
gitea-mcp.exe gitea-mcp.exe
*.log *.log
tmp

16
.vscode/mcp.json vendored
View File

@@ -21,15 +21,19 @@
} }
], ],
"servers": { "servers": {
"gitea": { "gitea-mcp-stdio": {
"type": "stdio", "type": "stdio",
"command": "gitea-mcp", "command": "gitea-mcp",
"args": ["-t", "stdio"], "args": ["-t", "stdio"],
"env": { "env": {
"GITEA_HOST": "${input:gitea-host}", "GITEA_HOST": "${input:gitea-host}",
"GITEA_ACCESS_TOKEN": "${input:gitea-token}", "GITEA_ACCESS_TOKEN": "${input:gitea-token}",
"GITEA_INSECURE": "${input:gitea-insecure}" "GITEA_INSECURE": "${input:gitea-insecure}"
} }
},
"gitea-mcp-http": {
"type": "http",
"url": "http://localhost:8080/mcp",
} }
} }
} }

View File

@@ -1,39 +1,32 @@
# syntax=docker/dockerfile:1.4
# Build stage # Build stage
FROM golang:1.24-bullseye AS builder FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
ARG VERSION ARG VERSION=dev
ARG TARGETOS
ARG TARGETARCH
# Set the working directory
WORKDIR /app WORKDIR /app
# Copy go.mod and go.sum files
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Download dependencies
RUN go mod download
# Copy the source code
COPY . . COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${VERSION}" -o gitea-mcp --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
go build -trimpath -ldflags="-s -w -X main.Version=${VERSION}" -o gitea-mcp
# Final stage # Final stage
FROM debian:bullseye-slim FROM gcr.io/distroless/static-debian12:nonroot
ENV GITEA_MODE=stdio
WORKDIR /app WORKDIR /app
COPY --from=builder --chown=nonroot:nonroot /app/gitea-mcp .
# Install ca-certificates for HTTPS requests USER nonroot:nonroot
RUN apt-get update && \
apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
# Create a non-root user LABEL org.opencontainers.image.version="${VERSION}"
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"] CMD ["/app/gitea-mcp"]

View File

@@ -54,7 +54,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
} }
], ],
"servers": { "servers": {
"github": { "gitea-mcp": {
"command": "docker", "command": "docker",
"args": [ "args": [
"run", "run",
@@ -194,6 +194,7 @@ The Gitea MCP Server supports the following tools:
| list_tags | Tag | List all tags in a repository | | list_tags | Tag | List all tags 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 |
| get_dir_content | File | Get a list of entries in a directory |
| 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 |
@@ -202,6 +203,8 @@ The Gitea MCP Server supports the following tools:
| 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 |
| edit_issue | Issue | Edit a issue | | edit_issue | Issue | Edit a issue |
| edit_issue_comment | Issue | Edit a comment on an issue |
| get_issue_comments_by_index | Issue | Get comments of an issue by its index |
| 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 |

View File

@@ -54,7 +54,7 @@ Model Context Protocol (MCP) 是一种协议,允许通过聊天界面整合各
} }
], ],
"servers": { "servers": {
"github": { "gitea-mcp": {
"command": "docker", "command": "docker",
"args": [ "args": [
"run", "run",
@@ -194,6 +194,7 @@ Gitea MCP 服务器支持以下工具:
| list_tags | 标签 | 列出所有标签 | | list_tags | 标签 | 列出所有标签 |
| list_repo_commits | 提交 | 列出仓库中的所有提交 | | list_repo_commits | 提交 | 列出仓库中的所有提交 |
| get_file_content | 文件 | 获取文件的内容和元数据 | | get_file_content | 文件 | 获取文件的内容和元数据 |
| get_dir_content | 文件 | 获取目录的内容列表 |
| create_file | 文件 | 创建一个新文件 | | create_file | 文件 | 创建一个新文件 |
| update_file | 文件 | 更新现有文件 | | update_file | 文件 | 更新现有文件 |
| delete_file | 文件 | 删除一个文件 | | delete_file | 文件 | 删除一个文件 |
@@ -202,6 +203,8 @@ Gitea MCP 服务器支持以下工具:
| create_issue | 问题 | 创建一个新问题 | | create_issue | 问题 | 创建一个新问题 |
| create_issue_comment | 问题 | 在问题上创建评论 | | create_issue_comment | 问题 | 在问题上创建评论 |
| edit_issue | 问题 | 编辑一个问题 | | edit_issue | 问题 | 编辑一个问题 |
| edit_issue_comment | 问题 | 在问题上编辑评论 |
| get_issue_comments_by_index | 问题 | 根据索引获取问题的评论 |
| get_pull_request_by_index | 拉取请求 | 根据索引获取拉取请求 | | get_pull_request_by_index | 拉取请求 | 根据索引获取拉取请求 |
| list_repo_pull_requests | 拉取请求 | 列出仓库中的所有拉取请求 | | list_repo_pull_requests | 拉取请求 | 列出仓库中的所有拉取请求 |
| create_pull_request | 拉取请求 | 创建一个新拉取请求 | | create_pull_request | 拉取请求 | 创建一个新拉取请求 |

View File

@@ -54,7 +54,7 @@ Model Context Protocol (MCP) 是一種協議,允許通過聊天界面整合各
} }
], ],
"servers": { "servers": {
"github": { "gitea-mcp": {
"command": "docker", "command": "docker",
"args": [ "args": [
"run", "run",
@@ -194,6 +194,7 @@ Gitea MCP 伺服器支持以下工具:
| list_tags | 標籤 | 列出所有標籤 | | list_tags | 標籤 | 列出所有標籤 |
| list_repo_commits | 提交 | 列出倉庫中的所有提交 | | list_repo_commits | 提交 | 列出倉庫中的所有提交 |
| get_file_content | 文件 | 獲取文件的內容和元數據 | | get_file_content | 文件 | 獲取文件的內容和元數據 |
| get_dir_content | 文件 | 獲取目錄的內容列表 |
| create_file | 文件 | 創建一個新文件 | | create_file | 文件 | 創建一個新文件 |
| update_file | 文件 | 更新現有文件 | | update_file | 文件 | 更新現有文件 |
| delete_file | 文件 | 刪除一個文件 | | delete_file | 文件 | 刪除一個文件 |
@@ -202,6 +203,8 @@ Gitea MCP 伺服器支持以下工具:
| create_issue | 問題 | 創建一個新問題 | | create_issue | 問題 | 創建一個新問題 |
| create_issue_comment | 問題 | 在問題上創建評論 | | create_issue_comment | 問題 | 在問題上創建評論 |
| edit_issue | 問題 | 編輯一個問題 | | edit_issue | 問題 | 編輯一個問題 |
| edit_issue_comment | 問題 | 在問題上編輯評論 |
| get_issue_comments_by_index | 问题 | 根據索引獲取問題的評論 |
| get_pull_request_by_index | 拉取請求 | 根據索引獲取拉取請求 | | get_pull_request_by_index | 拉取請求 | 根據索引獲取拉取請求 |
| list_repo_pull_requests | 拉取請求 | 列出倉庫中的所有拉取請求 | | list_repo_pull_requests | 拉取請求 | 列出倉庫中的所有拉取請求 |
| create_pull_request | 拉取請求 | 創建一個新拉取請求 | | create_pull_request | 拉取請求 | 創建一個新拉取請求 |

View File

@@ -80,8 +80,8 @@ func init() {
flagPkg.Token = os.Getenv("GITEA_ACCESS_TOKEN") flagPkg.Token = os.Getenv("GITEA_ACCESS_TOKEN")
} }
if os.Getenv("GITEA_MODE") != "" { if os.Getenv("MCP_MODE") != "" {
flagPkg.Mode = os.Getenv("GITEA_MODE") flagPkg.Mode = os.Getenv("MCP_MODE")
} }
if os.Getenv("GITEA_READONLY") == "true" { if os.Getenv("GITEA_READONLY") == "true" {

View File

@@ -18,11 +18,13 @@ import (
var Tool = tool.New() var Tool = tool.New()
const ( const (
GetIssueByIndexToolName = "get_issue_by_index" GetIssueByIndexToolName = "get_issue_by_index"
ListRepoIssuesToolName = "list_repo_issues" ListRepoIssuesToolName = "list_repo_issues"
CreateIssueToolName = "create_issue" CreateIssueToolName = "create_issue"
CreateIssueCommentToolName = "create_issue_comment" CreateIssueCommentToolName = "create_issue_comment"
EditIssueToolName = "edit_issue" EditIssueToolName = "edit_issue"
EditIssueCommentToolName = "edit_issue_comment"
GetIssueCommentsByIndexToolName = "get_issue_comments_by_index"
) )
var ( var (
@@ -52,6 +54,7 @@ var (
mcp.WithString("title", mcp.Required(), mcp.Description("issue title")), mcp.WithString("title", mcp.Required(), mcp.Description("issue title")),
mcp.WithString("body", mcp.Required(), mcp.Description("issue body")), mcp.WithString("body", mcp.Required(), mcp.Description("issue body")),
) )
CreateIssueCommentTool = mcp.NewTool( CreateIssueCommentTool = mcp.NewTool(
CreateIssueCommentToolName, CreateIssueCommentToolName,
mcp.WithDescription("create issue comment"), mcp.WithDescription("create issue comment"),
@@ -60,6 +63,7 @@ var (
mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")), mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")), mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")),
) )
EditIssueTool = mcp.NewTool( EditIssueTool = mcp.NewTool(
EditIssueToolName, EditIssueToolName,
mcp.WithDescription("edit issue"), mcp.WithDescription("edit issue"),
@@ -72,6 +76,23 @@ var (
mcp.WithNumber("milestone", mcp.Description("milestone number")), mcp.WithNumber("milestone", mcp.Description("milestone number")),
mcp.WithString("state", mcp.Description("issue state, one of open, closed, all")), mcp.WithString("state", mcp.Description("issue state, one of open, closed, all")),
) )
EditIssueCommentTool = mcp.NewTool(
EditIssueCommentToolName,
mcp.WithDescription("edit issue comment"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithNumber("commentID", mcp.Required(), mcp.Description("id of issue comment")),
mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")),
)
GetIssueCommentsByIndexTool = mcp.NewTool(
GetIssueCommentsByIndexToolName,
mcp.WithDescription("get issue comment by index"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
)
) )
func init() { func init() {
@@ -95,6 +116,14 @@ func init() {
Tool: EditIssueTool, Tool: EditIssueTool,
Handler: EditIssueFn, Handler: EditIssueFn,
}) })
Tool.RegisterWrite(server.ServerTool{
Tool: EditIssueCommentTool,
Handler: EditIssueCommentFn,
})
Tool.RegisterRead(server.ServerTool{
Tool: GetIssueCommentsByIndexTool,
Handler: GetIssueCommentsByIndexFn,
})
} }
func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
@@ -258,3 +287,55 @@ func EditIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRes
return to.TextResult(issue) return to.TextResult(issue)
} }
func EditIssueCommentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called EditIssueCommentFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("repo is required"))
}
commentID, ok := req.GetArguments()["commentID"].(float64)
if !ok {
return to.ErrorResult(fmt.Errorf("comment ID is required"))
}
body, ok := req.GetArguments()["body"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("body is required"))
}
opt := gitea_sdk.EditIssueCommentOption{
Body: body,
}
issueComment, _, err := gitea.Client().EditIssueComment(owner, repo, int64(commentID), opt)
if err != nil {
return to.ErrorResult(fmt.Errorf("edit %v/%v/issues/comments/%v err: %v", owner, repo, int64(commentID), err))
}
return to.TextResult(issueComment)
}
func GetIssueCommentsByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called GetIssueCommentsByIndexFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("repo is required"))
}
index, ok := req.GetArguments()["index"].(float64)
if !ok {
return to.ErrorResult(fmt.Errorf("index is required"))
}
opt := gitea_sdk.ListIssueCommentOptions{}
issue, _, err := gitea.Client().ListIssueComments(owner, repo, int64(index), opt)
if err != nil {
return to.ErrorResult(fmt.Errorf("get %v/%v/issues/%v/comments err: %v", owner, repo, int64(index), err))
}
return to.TextResult(issue)
}

View File

@@ -71,5 +71,6 @@ func newMCPServer(version string) *server.MCPServer {
version, version,
server.WithToolCapabilities(true), server.WithToolCapabilities(true),
server.WithLogging(), server.WithLogging(),
server.WithRecovery(),
) )
} }

View File

@@ -16,6 +16,7 @@ import (
const ( const (
GetFileToolName = "get_file_content" GetFileToolName = "get_file_content"
GetDirToolName = "get_dir_content"
CreateFileToolName = "create_file" CreateFileToolName = "create_file"
UpdateFileToolName = "update_file" UpdateFileToolName = "update_file"
DeleteFileToolName = "delete_file" DeleteFileToolName = "delete_file"
@@ -31,6 +32,15 @@ var (
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")), mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
) )
GetDirContentTool = mcp.NewTool(
GetDirToolName,
mcp.WithDescription("Get a list of entries in a directory"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("ref", mcp.Required(), mcp.Description("ref can be branch/tag/commit")),
mcp.WithString("filePath", mcp.Required(), mcp.Description("directory path")),
)
CreateFileTool = mcp.NewTool( CreateFileTool = mcp.NewTool(
CreateFileToolName, CreateFileToolName,
mcp.WithDescription("Create file"), mcp.WithDescription("Create file"),
@@ -72,6 +82,10 @@ func init() {
Tool: GetFileContentTool, Tool: GetFileContentTool,
Handler: GetFileContentFn, Handler: GetFileContentFn,
}) })
Tool.RegisterRead(server.ServerTool{
Tool: GetDirContentTool,
Handler: GetDirContentFn,
})
Tool.RegisterWrite(server.ServerTool{ Tool.RegisterWrite(server.ServerTool{
Tool: CreateFileTool, Tool: CreateFileTool,
Handler: CreateFileFn, Handler: CreateFileFn,
@@ -108,6 +122,28 @@ func GetFileContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo
return to.TextResult(content) return to.TextResult(content)
} }
func GetDirContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called GetDirContentFn")
owner, ok := req.GetArguments()["owner"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("owner is required"))
}
repo, ok := req.GetArguments()["repo"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("repo is required"))
}
ref, _ := req.GetArguments()["ref"].(string)
filePath, ok := req.GetArguments()["filePath"].(string)
if !ok {
return to.ErrorResult(fmt.Errorf("filePath is required"))
}
content, _, err := gitea.Client().ListContents(owner, repo, ref, filePath)
if err != nil {
return to.ErrorResult(fmt.Errorf("get dir content err: %v", err))
}
return to.TextResult(content)
}
func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateFileFn") log.Debugf("Called CreateFileFn")
owner, ok := req.GetArguments()["owner"].(string) owner, ok := req.GetArguments()["owner"].(string)

View File

@@ -19,11 +19,9 @@ const (
GetGiteaMCPServerVersion = "get_gitea_mcp_server_version" GetGiteaMCPServerVersion = "get_gitea_mcp_server_version"
) )
var ( var GetGiteaMCPServerVersionTool = mcp.NewTool(
GetGiteaMCPServerVersionTool = mcp.NewTool( GetGiteaMCPServerVersion,
GetGiteaMCPServerVersion, mcp.WithDescription("Get Gitea MCP Server Version"),
mcp.WithDescription("Get Gitea MCP Server Version"),
)
) )
func init() { func init() {

View File

@@ -22,19 +22,20 @@ func Client() *gitea.Client {
if client != nil { if client != nil {
return return
} }
httpClient := &http.Client{
Transport: http.DefaultTransport,
}
opts := []gitea.ClientOption{ opts := []gitea.ClientOption{
gitea.SetToken(flag.Token), gitea.SetToken(flag.Token),
} }
if flag.Insecure { if flag.Insecure {
httpClient := &http.Client{ httpClient.Transport.(*http.Transport).TLSClientConfig = &tls.Config{
Transport: &http.Transport{ InsecureSkipVerify: true,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
} }
opts = append(opts, gitea.SetHTTPClient(httpClient))
} }
opts = append(opts, gitea.SetHTTPClient(httpClient))
if flag.Debug { if flag.Debug {
opts = append(opts, gitea.SetDebugMode()) opts = append(opts, gitea.SetDebugMode())
} }

View File

@@ -32,8 +32,14 @@ func Default() *zap.Logger {
home = os.TempDir() home = os.TempDir()
} }
logDir := fmt.Sprintf("%s/.gitea-mcp", home)
if err := os.MkdirAll(logDir, 0o700); err != nil {
// Fallback to temp directory if creation fails
logDir = os.TempDir()
}
wss = append(wss, zapcore.AddSync(&lumberjack.Logger{ wss = append(wss, zapcore.AddSync(&lumberjack.Logger{
Filename: fmt.Sprintf("%s/.gitea-mcp/gitea-mcp.log", home), Filename: fmt.Sprintf("%s/gitea-mcp.log", logDir),
MaxSize: 100, MaxSize: 100,
MaxBackups: 10, MaxBackups: 10,
MaxAge: 30, MaxAge: 30,