mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-13 20:03:07 +00:00
efcbdbb17f
## Summary Replace `github.com/mark3labs/mcp-go` with the official `github.com/modelcontextprotocol/go-sdk v1.7.0`. All 54 existing tools, scopes, CLI, `stdio` and HTTP (`/mcp`) modes, and per-request authentication remain supported. This PR is limited to the SDK equivalence migration; the stateless 2026 HTTP transport is deferred to a follow-up PR. ## Verification - Tool definitions were compared with `main` and matched for all 54 tools. - `make lint`, `make fmt`, `go test -count=1 -race ./...`, `make build`, and `make tidy` pass. --------- Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/223 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com> Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.com/gitea/gitea-mcp/pkg/annotation"
|
|
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
|
"gitea.com/gitea/gitea-mcp/pkg/params"
|
|
"gitea.com/gitea/gitea-mcp/pkg/slim"
|
|
"gitea.com/gitea/gitea-mcp/pkg/to"
|
|
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
|
|
|
gitea_sdk "gitea.dev/sdk"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
const (
|
|
GetMyUserInfoToolName = "get_me"
|
|
GetUserOrgsToolName = "get_user_orgs"
|
|
)
|
|
|
|
var Tool = tool.New("user")
|
|
|
|
var (
|
|
GetMyUserInfoTool = tool.NewDefinition(
|
|
GetMyUserInfoToolName,
|
|
"Get current user",
|
|
annotation.ReadOnly("Get current user information"),
|
|
)
|
|
|
|
GetUserOrgsTool = tool.NewDefinition(
|
|
GetUserOrgsToolName,
|
|
"List current user's organizations",
|
|
annotation.ReadOnly("Get user organizations"),
|
|
tool.Number("page", tool.Description(params.PageDesc), tool.Default(1)),
|
|
tool.Number("per_page", tool.Description(params.PaginationDesc), tool.Default(30)),
|
|
)
|
|
)
|
|
|
|
func init() {
|
|
Tool.RegisterRead(tool.ServerTool{Tool: GetMyUserInfoTool, Handler: GetUserInfoFn})
|
|
Tool.RegisterRead(tool.ServerTool{Tool: GetUserOrgsTool, Handler: GetUserOrgsFn})
|
|
}
|
|
|
|
func GetUserInfoFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
user, _, err := client.Users.GetMyUserInfo(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get user info err: %v", err))
|
|
}
|
|
return to.TextResult(slim.UserDetail(user))
|
|
}
|
|
|
|
func GetUserOrgsFn(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error) {
|
|
page, pageSize := params.GetPagination(args, 30)
|
|
|
|
opt := gitea_sdk.ListOrgsOptions{
|
|
ListOptions: gitea_sdk.ListOptions{
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
},
|
|
}
|
|
client, err := gitea.ClientFromContext(ctx)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
|
}
|
|
orgs, _, err := client.Organizations.ListMyOrgs(ctx, opt)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("get user orgs err: %v", err))
|
|
}
|
|
return to.TextResult(slimOrgs(orgs))
|
|
}
|