Rename the fork from gitea-mcp to gitea-mcp-extended to reflect the significantly expanded tool coverage (299 vs upstream's 93 tools). - Rename Go module path and all import references - Rename binary to gitea-mcp-extended in Makefile, Dockerfile, .gitignore - Point .goreleaser.yaml gitea_urls to git.lethalbits.com - Replace release-tag workflow with goreleaser + Generic Package Registry publishing - Replace release-nightly workflow with cross-platform build + nightly package publishing - Update CLAUDE.md project description and tool count
105 lines
3.3 KiB
Go
105 lines
3.3 KiB
Go
package settings
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.lethalbits.com/lethalbits/gitea-mcp-extended/pkg/gitea"
|
|
"git.lethalbits.com/lethalbits/gitea-mcp-extended/pkg/log"
|
|
"git.lethalbits.com/lethalbits/gitea-mcp-extended/pkg/to"
|
|
"git.lethalbits.com/lethalbits/gitea-mcp-extended/pkg/tool"
|
|
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
"github.com/mark3labs/mcp-go/server"
|
|
)
|
|
|
|
var Tool = tool.New()
|
|
|
|
const (
|
|
GetAPISettingsToolName = "get_api_settings"
|
|
GetAttachmentSettingsToolName = "get_attachment_settings"
|
|
GetRepoSettingsToolName = "get_repo_settings"
|
|
GetUISettingsToolName = "get_ui_settings"
|
|
)
|
|
|
|
var (
|
|
GetAPISettingsTool = mcp.NewTool(
|
|
GetAPISettingsToolName,
|
|
mcp.WithDescription("Get the global API settings of the Gitea instance"),
|
|
)
|
|
|
|
GetAttachmentSettingsTool = mcp.NewTool(
|
|
GetAttachmentSettingsToolName,
|
|
mcp.WithDescription("Get the global attachment settings"),
|
|
)
|
|
|
|
GetRepoSettingsTool = mcp.NewTool(
|
|
GetRepoSettingsToolName,
|
|
mcp.WithDescription("Get the global repository settings"),
|
|
)
|
|
|
|
GetUISettingsTool = mcp.NewTool(
|
|
GetUISettingsToolName,
|
|
mcp.WithDescription("Get the global UI settings"),
|
|
)
|
|
)
|
|
|
|
func init() {
|
|
Tool.RegisterRead(server.ServerTool{Tool: GetAPISettingsTool, Handler: GetAPISettingsFn})
|
|
Tool.RegisterRead(server.ServerTool{Tool: GetAttachmentSettingsTool, Handler: GetAttachmentSettingsFn})
|
|
Tool.RegisterRead(server.ServerTool{Tool: GetRepoSettingsTool, Handler: GetRepoSettingsFn})
|
|
Tool.RegisterRead(server.ServerTool{Tool: GetUISettingsTool, Handler: GetUISettingsFn})
|
|
}
|
|
|
|
func GetAPISettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
log.Debugf("Called GetAPISettingsFn")
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
settings, _, err := client.GetGlobalAPISettings()
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get API settings err: %v", err))
|
|
}
|
|
return to.TextResult(settings)
|
|
}
|
|
|
|
func GetAttachmentSettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
log.Debugf("Called GetAttachmentSettingsFn")
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
settings, _, err := client.GetGlobalAttachmentSettings()
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get attachment settings err: %v", err))
|
|
}
|
|
return to.TextResult(settings)
|
|
}
|
|
|
|
func GetRepoSettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
log.Debugf("Called GetRepoSettingsFn")
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
settings, _, err := client.GetGlobalRepoSettings()
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get repo settings err: %v", err))
|
|
}
|
|
return to.TextResult(settings)
|
|
}
|
|
|
|
func GetUISettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
log.Debugf("Called GetUISettingsFn")
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
settings, _, err := client.GetGlobalUISettings()
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get UI settings err: %v", err))
|
|
}
|
|
return to.TextResult(settings)
|
|
}
|