feat: add reply comment functionality for Xiaohongshu feeds

- Implemented handleReplyComment method in mcp_handlers.go to manage replying to comments on feeds.
- Introduced ReplyCommentArgs struct in mcp_server.go for handling parameters related to comment replies.
- Registered a new MCP tool for replying to comments in the registerTools function.
- Added ReplyCommentToFeed method in service.go to interact with the Xiaohongshu platform for comment replies.
- Enhanced error handling for missing parameters in the reply process.
This commit is contained in:
chekayo
2025-10-09 23:49:40 +08:00
parent 408c641959
commit cff1705c5b
3 changed files with 130 additions and 3 deletions

View File

@@ -524,3 +524,87 @@ func (s *AppServer) handlePostComment(ctx context.Context, args map[string]inter
}},
}
}
// handleReplyComment 处理回复评论
func (s *AppServer) handleReplyComment(ctx context.Context, args map[string]interface{}) *MCPToolResult {
logrus.Info("MCP: 回复评论")
// 解析参数
feedID, ok := args["feed_id"].(string)
if !ok || feedID == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: 缺少feed_id参数",
}},
IsError: true,
}
}
xsecToken, ok := args["xsec_token"].(string)
if !ok || xsecToken == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: 缺少xsec_token参数",
}},
IsError: true,
}
}
commentID, ok := args["comment_id"].(string)
if !ok || commentID == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: 缺少comment_id参数",
}},
IsError: true,
}
}
userID, ok := args["user_id"].(string)
if !ok || userID == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: 缺少user_id参数",
}},
IsError: true,
}
}
content, ok := args["content"].(string)
if !ok || content == "" {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: 缺少content参数",
}},
IsError: true,
}
}
logrus.Infof("MCP: 回复评论 - Feed ID: %s, Comment ID: %s, User ID: %s, 内容长度: %d", feedID, commentID, userID, len(content))
// 回复评论
result, err := s.xiaohongshuService.ReplyCommentToFeed(ctx, feedID, xsecToken, commentID, userID, content)
if err != nil {
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: "回复评论失败: " + err.Error(),
}},
IsError: true,
}
}
// 返回成功结果
resultText := fmt.Sprintf("回复评论成功 - Feed ID: %s", result.FeedID)
return &MCPToolResult{
Content: []MCPContent{{
Type: "text",
Text: resultText,
}},
}
}