Files
xiaohongshu-mcp/routes.go
zy 0955723b19 feat: 为视频发布功能新增HTTP API接口和完善文档 (#179)
* 重构 publish tab 选择逻辑,把公共代码提取到同一个函数中

* feat: 为视频发布功能新增HTTP API接口和完善文档

- 新增 /api/v1/publish_video HTTP接口
- 添加 publishVideoHandler 处理函数
- 更新 API.md 增加视频发布接口文档
- 更新 README.md 和 README_EN.md 增加视频发布功能说明
- 在MCP工具列表中补充 publish_with_video 工具说明
2025-09-29 01:08:11 +08:00

54 lines
1.4 KiB
Go

package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
// setupRoutes 设置路由配置
func setupRoutes(appServer *AppServer) *gin.Engine {
// 设置 Gin 模式
gin.SetMode(gin.ReleaseMode)
router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
// 添加中间件
router.Use(errorHandlingMiddleware())
router.Use(corsMiddleware())
// 健康检查
router.GET("/health", healthHandler)
// MCP 端点 - 使用官方 SDK 的 Streamable HTTP Handler
mcpHandler := mcp.NewStreamableHTTPHandler(
func(r *http.Request) *mcp.Server {
return appServer.mcpServer
},
&mcp.StreamableHTTPOptions{
JSONResponse: true, // 支持 JSON 响应
},
)
router.Any("/mcp", gin.WrapH(mcpHandler))
router.Any("/mcp/*path", gin.WrapH(mcpHandler))
// API 路由组
api := router.Group("/api/v1")
{
api.GET("/login/status", appServer.checkLoginStatusHandler)
api.GET("/login/qrcode", appServer.getLoginQrcodeHandler)
api.POST("/publish", appServer.publishHandler)
api.POST("/publish_video", appServer.publishVideoHandler)
api.GET("/feeds/list", appServer.listFeedsHandler)
api.GET("/feeds/search", appServer.searchFeedsHandler)
api.POST("/feeds/detail", appServer.getFeedDetailHandler)
api.POST("/user/profile", appServer.userProfileHandler)
api.POST("/feeds/comment", appServer.postCommentHandler)
}
return router
}