Support read only mode (#36)

Fix: #35
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/36
Co-authored-by: hiifong <f@ilo.nz>
Co-committed-by: hiifong <f@ilo.nz>
This commit is contained in:
hiifong
2025-04-20 09:09:29 +00:00
committed by hiifong
parent 59e699aac7
commit 70b9ac5b80
19 changed files with 294 additions and 65 deletions

View File

@@ -7,12 +7,15 @@ import (
"gitea.com/gitea/gitea-mcp/pkg/gitea"
"gitea.com/gitea/gitea-mcp/pkg/log"
"gitea.com/gitea/gitea-mcp/pkg/to"
"gitea.com/gitea/gitea-mcp/pkg/tool"
gitea_sdk "code.gitea.io/sdk/gitea"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
var Tool = tool.New()
const (
GetPullRequestByIndexToolName = "get_pull_request_by_index"
ListRepoPullRequestsToolName = "list_repo_pull_requests"
@@ -52,10 +55,19 @@ var (
)
)
func RegisterTool(s *server.MCPServer) {
s.AddTool(GetPullRequestByIndexTool, GetPullRequestByIndexFn)
s.AddTool(ListRepoPullRequestsTool, ListRepoPullRequestsFn)
s.AddTool(CreatePullRequestTool, CreatePullRequestFn)
func init() {
Tool.RegisterRead(server.ServerTool{
Tool: GetPullRequestByIndexTool,
Handler: GetPullRequestByIndexFn,
})
Tool.RegisterRead(server.ServerTool{
Tool: ListRepoPullRequestsTool,
Handler: ListRepoPullRequestsFn,
})
Tool.RegisterWrite(server.ServerTool{
Tool: CreatePullRequestTool,
Handler: CreatePullRequestFn,
})
}
func GetPullRequestByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {