()
| 209 | } |
| 210 | |
| 211 | func (c *MCPController) MCPCommentsHandler() func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 212 | return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 213 | if err := c.ensureMCPEnabled(ctx); err != nil { |
| 214 | return nil, err |
| 215 | } |
| 216 | cond := schema.NewMCPSearchCommentCond(request) |
| 217 | |
| 218 | siteGeneral, err := c.siteInfoService.GetSiteGeneral(ctx) |
| 219 | if err != nil { |
| 220 | log.Errorf("get site general info failed: %v", err) |
| 221 | return nil, err |
| 222 | } |
| 223 | |
| 224 | dto := &comment.CommentQuery{ |
| 225 | PageCond: pager.PageCond{Page: 1, PageSize: 5}, |
| 226 | QueryCond: "newest", |
| 227 | ObjectID: cond.ObjectID, |
| 228 | } |
| 229 | commentList, total, err := c.commentRepo.GetCommentPage(ctx, dto) |
| 230 | if err != nil { |
| 231 | return nil, err |
| 232 | } |
| 233 | if total == 0 { |
| 234 | return mcp.NewToolResultText("No comments found."), nil |
| 235 | } |
| 236 | |
| 237 | resp := make([]*schema.MCPSearchCommentInfoResp, 0) |
| 238 | for _, comment := range commentList { |
| 239 | t := &schema.MCPSearchCommentInfoResp{ |
| 240 | CommentID: comment.ID, |
| 241 | Content: comment.OriginalText, |
| 242 | ObjectID: comment.ObjectID, |
| 243 | Link: fmt.Sprintf("%s/comments/%s", siteGeneral.SiteUrl, comment.ID), |
| 244 | } |
| 245 | resp = append(resp, t) |
| 246 | } |
| 247 | data, _ := json.Marshal(resp) |
| 248 | return mcp.NewToolResultText(string(data)), nil |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | func (c *MCPController) MCPTagsHandler() func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 253 | return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
no test coverage detected