Skip to content

Commit 8158d06

Browse files
tanjuntanjun
authored andcommitted
Merge branch 'feature/product-binding'
2 parents bc7fc86 + 9675190 commit 8158d06

File tree

5 files changed

+304
-7
lines changed

5 files changed

+304
-7
lines changed

mcp_handlers.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
129129
content, _ := args["content"].(string)
130130
imagePathsInterface, _ := args["images"].([]interface{})
131131
tagsInterface, _ := args["tags"].([]interface{})
132+
productsInterface, _ := args["products"].([]interface{})
132133

133134
var imagePaths []string
134135
for _, path := range imagePathsInterface {
@@ -144,14 +145,21 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
144145
}
145146
}
146147

148+
var products []string
149+
for _, p := range productsInterface {
150+
if pStr, ok := p.(string); ok {
151+
products = append(products, pStr)
152+
}
153+
}
154+
147155
// 解析定时发布参数
148156
scheduleAt, _ := args["schedule_at"].(string)
149157
visibility := parseVisibility(args)
150158

151159
// 解析原创参数
152160
isOriginal, _ := args["is_original"].(bool)
153161

154-
logrus.Infof("MCP: 发布内容 - 标题: %s, 图片数量: %d, 标签数量: %d, 定时: %s, 原创: %v, visibility: %s", title, len(imagePaths), len(tags), scheduleAt, isOriginal, visibility)
162+
logrus.Infof("MCP: 发布内容 - 标题: %s, 图片数量: %d, 标签数量: %d, 定时: %s, 原创: %v, visibility: %s, 商品: %v", title, len(imagePaths), len(tags), scheduleAt, isOriginal, visibility, products)
155163

156164
// 构建发布请求
157165
req := &PublishRequest{
@@ -162,6 +170,7 @@ func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]in
162170
ScheduleAt: scheduleAt,
163171
IsOriginal: isOriginal,
164172
Visibility: visibility,
173+
Products: products,
165174
}
166175

167176
// 执行发布
@@ -193,6 +202,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
193202
content, _ := args["content"].(string)
194203
videoPath, _ := args["video"].(string)
195204
tagsInterface, _ := args["tags"].([]interface{})
205+
productsInterface, _ := args["products"].([]interface{})
196206

197207
var tags []string
198208
for _, tag := range tagsInterface {
@@ -201,6 +211,13 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
201211
}
202212
}
203213

214+
var products []string
215+
for _, p := range productsInterface {
216+
if pStr, ok := p.(string); ok {
217+
products = append(products, pStr)
218+
}
219+
}
220+
204221
if videoPath == "" {
205222
return &MCPToolResult{
206223
Content: []MCPContent{{
@@ -215,7 +232,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
215232
scheduleAt, _ := args["schedule_at"].(string)
216233
visibility := parseVisibility(args)
217234

218-
logrus.Infof("MCP: 发布视频 - 标题: %s, 标签数量: %d, 定时: %s, visibility: %s", title, len(tags), scheduleAt, visibility)
235+
logrus.Infof("MCP: 发布视频 - 标题: %s, 标签数量: %d, 定时: %s, visibility: %s, 商品: %v", title, len(tags), scheduleAt, visibility, products)
219236

220237
// 构建发布请求
221238
req := &PublishVideoRequest{
@@ -225,6 +242,7 @@ func (s *AppServer) handlePublishVideo(ctx context.Context, args map[string]inte
225242
Tags: tags,
226243
ScheduleAt: scheduleAt,
227244
Visibility: visibility,
245+
Products: products,
228246
}
229247

230248
// 执行发布

mcp_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type PublishContentArgs struct {
2424
ScheduleAt string `json:"schedule_at,omitempty" jsonschema:"定时发布时间(可选),ISO8601格式如 2024-01-20T10:30:00+08:00,支持1小时至14天内。不填则立即发布"`
2525
IsOriginal bool `json:"is_original,omitempty" jsonschema:"是否声明原创(可选),true为声明原创,false或不填则不声明"`
2626
Visibility string `json:"visibility,omitempty" jsonschema:"可见范围(可选),支持: 公开可见(默认)、仅自己可见、仅互关好友可见。不填则默认公开可见"`
27+
Products []string `json:"products,omitempty" jsonschema:"商品关键词列表(可选),用于绑定带货商品。填写商品名称或商品ID,系统会自动搜索并选择第一个匹配结果。需账号已开通商品功能。示例: [面膜, 防晒霜SPF50]"`
2728
}
2829

2930
// PublishVideoArgs 发布视频的参数(仅支持本地单个视频文件)
@@ -34,6 +35,7 @@ type PublishVideoArgs struct {
3435
Tags []string `json:"tags,omitempty" jsonschema:"话题标签列表(可选参数),如 [美食, 旅行, 生活]"`
3536
ScheduleAt string `json:"schedule_at,omitempty" jsonschema:"定时发布时间(可选),ISO8601格式如 2024-01-20T10:30:00+08:00,支持1小时至14天内。不填则立即发布"`
3637
Visibility string `json:"visibility,omitempty" jsonschema:"可见范围(可选),支持: 公开可见(默认)、仅自己可见、仅互关好友可见。不填则默认公开可见"`
38+
Products []string `json:"products,omitempty" jsonschema:"商品关键词列表(可选),用于绑定带货商品。填写商品名称或商品ID,系统会自动搜索并选择第一个匹配结果。需账号已开通商品功能。示例: [面膜, 防晒霜SPF50]"`
3739
}
3840

3941
// SearchFeedsArgs 搜索内容的参数
@@ -219,6 +221,7 @@ func registerTools(server *mcp.Server, appServer *AppServer) {
219221
"schedule_at": args.ScheduleAt,
220222
"is_original": args.IsOriginal,
221223
"visibility": args.Visibility,
224+
"products": convertStringsToInterfaces(args.Products),
222225
}
223226
result := appServer.handlePublishContent(ctx, argsMap)
224227
return convertToMCPResult(result), nil, nil
@@ -391,6 +394,7 @@ func registerTools(server *mcp.Server, appServer *AppServer) {
391394
"tags": convertStringsToInterfaces(args.Tags),
392395
"schedule_at": args.ScheduleAt,
393396
"visibility": args.Visibility,
397+
"products": convertStringsToInterfaces(args.Products),
394398
}
395399
result := appServer.handlePublishVideo(ctx, argsMap)
396400
return convertToMCPResult(result), nil, nil

service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type PublishRequest struct {
3535
ScheduleAt string `json:"schedule_at,omitempty"` // 定时发布时间,ISO8601格式,为空则立即发布
3636
IsOriginal bool `json:"is_original,omitempty"` // 是否声明原创
3737
Visibility string `json:"visibility,omitempty"` // 可见范围: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
38+
Products []string `json:"products,omitempty"` // 商品关键词列表,用于绑定带货商品
3839
}
3940

4041
// LoginStatusResponse 登录状态响应
@@ -67,6 +68,7 @@ type PublishVideoRequest struct {
6768
Tags []string `json:"tags,omitempty"`
6869
ScheduleAt string `json:"schedule_at,omitempty"` // 定时发布时间,ISO8601格式,为空则立即发布
6970
Visibility string `json:"visibility,omitempty"` // 可见范围: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
71+
Products []string `json:"products,omitempty"` // 商品关键词列表,用于绑定带货商品
7072
}
7173

7274
// PublishVideoResponse 发布视频响应
@@ -217,6 +219,7 @@ func (s *XiaohongshuService) PublishContent(ctx context.Context, req *PublishReq
217219
ScheduleTime: scheduleTime,
218220
IsOriginal: req.IsOriginal,
219221
Visibility: req.Visibility,
222+
Products: req.Products,
220223
}
221224

222225
// 执行发布
@@ -307,6 +310,7 @@ func (s *XiaohongshuService) PublishVideo(ctx context.Context, req *PublishVideo
307310
VideoPath: req.Video,
308311
ScheduleTime: scheduleTime,
309312
Visibility: req.Visibility,
313+
Products: req.Products,
310314
}
311315

312316
// 执行发布

0 commit comments

Comments
 (0)