feat:获取用户主页功能 (#122)

增加读取用户的个人主页的信息
This commit is contained in:
CooperGuo
2025-09-20 22:20:58 +08:00
committed by GitHub
parent eafd973d75
commit 5f412a6bc5
8 changed files with 243 additions and 0 deletions

View File

@@ -233,6 +233,66 @@ func (s *AppServer) handleGetFeedDetail(ctx context.Context, args map[string]any
}
}
// handleUserProfile 获取用户主页
func (s *AppServer) handleUserProfile(ctx context.Context, args map[string]any) *MCPToolResult {
logrus.Info("MCP: 获取用户主页")
// 解析参数
userID, ok := args["user_id"].(string)
if !ok || userID == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "获取用户主页失败: 缺少user_id参数",
}},
IsError: true,
}
}
xsecToken, ok := args["xsec_token"].(string)
if !ok || xsecToken == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "获取用户主页失败: 缺少xsec_token参数",
}},
IsError: true,
}
}
logrus.Infof("MCP: 获取用户主页 - User ID: %s", userID)
result, err := s.xiaohongshuService.UserProfile(ctx, userID, xsecToken)
if err != nil {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "获取用户主页失败: " + err.Error(),
}},
IsError: true,
}
}
// 格式化输出转换为JSON字符串
jsonData, err := json.MarshalIndent(result, "", " ")
if err != nil {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: fmt.Sprintf("获取用户主页,但序列化失败: %v", err),
}},
IsError: true,
}
}
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: string(jsonData),
}},
}
}
// handlePostComment 处理发表评论到Feed
func (s *AppServer) handlePostComment(ctx context.Context, args map[string]interface{}) *MCPToolResult {
logrus.Info("MCP: 发表评论到Feed")