From 92963cd715453c6b41d1153411be915b2e544516 Mon Sep 17 00:00:00 2001 From: edmondfrank Date: Thu, 13 Mar 2025 12:34:13 +0800 Subject: [PATCH] feat add get user info tool and Bump version to 0.1.1 Signed-off-by: edmondfrank --- Makefile | 4 ++-- README.md | 1 + README_CN.md | 1 + main.go | 12 ++++++++--- operations/users/get_user_info.go | 34 +++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 operations/users/get_user_info.go diff --git a/Makefile b/Makefile index fabcb7b..0d773e2 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GO = go # Version information -VERSION ?= 0.1.0 +VERSION ?= 0.1.1 # Flags LDFLAGS = -ldflags "-X main.Version=$(VERSION)" @@ -32,4 +32,4 @@ clean: # 显示版本信息 version: - @echo "Version: $(VERSION)" \ No newline at end of file + @echo "Version: $(VERSION)" diff --git a/README.md b/README.md index 6c59e5a..611fa67 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,5 @@ The server provides various tools for interacting with Gitee: | **list_repo_issues** | Issue | List repository issues | | **comment_issue** | Issue | Comment on an issue | | **list_issue_comments** | Issue | List comments on an issue | +| **get_user_info** | User | Get current authenticated user information | | **list_user_notifications** | Notification | List user notifications | diff --git a/README_CN.md b/README_CN.md index 89515d1..5066788 100644 --- a/README_CN.md +++ b/README_CN.md @@ -83,4 +83,5 @@ Gitee MCP 服务器是一个用于 Gitee 的模型上下文协议(Model Contex | **list_repo_issues** | Issue | 列出仓库 Issue | | **comment_issue** | Issue | 评论 Issue | | **list_issue_comments** | Issue | 列出 Issue 的评论 | +| **get_user_info** | 用户 | 获取当前认证用户信息 | | **list_user_notifications** | 通知 | 列出用户通知 | diff --git a/main.go b/main.go index b37d95c..83bf66f 100644 --- a/main.go +++ b/main.go @@ -3,19 +3,22 @@ package main import ( "flag" "fmt" + "log" + "os" + "gitee.com/oschina/mcp-gitee/operations/issues" "gitee.com/oschina/mcp-gitee/operations/notifications" "gitee.com/oschina/mcp-gitee/operations/pulls" "gitee.com/oschina/mcp-gitee/operations/repository" + "gitee.com/oschina/mcp-gitee/operations/users" "gitee.com/oschina/mcp-gitee/utils" + "github.com/mark3labs/mcp-go/server" - "log" - "os" ) var ( // Version gitee mcp server version - Version = "0.1.0" + Version = "0.1.1" ) func newMCPServer() *server.MCPServer { @@ -56,6 +59,9 @@ func addTools(s *server.MCPServer) { // Notifications Tools s.AddTool(notifications.ListUserNotificationsTool, notifications.ListUserNotificationsHandler) + + // Users Tools + s.AddTool(users.GetUserInfoTool, users.GetUserInfoHandleFunc()) } func run(transport, addr string) error { diff --git a/operations/users/get_user_info.go b/operations/users/get_user_info.go new file mode 100644 index 0000000..b654dce --- /dev/null +++ b/operations/users/get_user_info.go @@ -0,0 +1,34 @@ +package users + +import ( + "context" + "gitee.com/oschina/mcp-gitee/operations/types" + "gitee.com/oschina/mcp-gitee/utils" + "github.com/mark3labs/mcp-go/mcp" + "github.com/mark3labs/mcp-go/server" +) + +const ( + // GetUserInfoToolName is the instruction to get authenticated user information + GetUserInfoToolName = "get_user_info" +) + +// GetUserInfoTool defines the tool for getting authorized user information +var GetUserInfoTool = mcp.NewTool( + GetUserInfoToolName, + mcp.WithDescription("This is a tool from the gitee MCP server.\nGet information about the authenticated user"), + // No parameters needed for this endpoint as it uses the authenticated user's token +) + +// GetUserInfoHandler handles the request to get authorized user information +func GetUserInfoHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { + client := utils.NewGiteeClient("GET", "/user") + + var user types.BasicUser + return client.HandleMCPResult(&user) +} + +// GetUserInfoHandleFunc returns a server.ToolHandlerFunc for handling get user info requests +func GetUserInfoHandleFunc() server.ToolHandlerFunc { + return GetUserInfoHandler +} -- Gitee