mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-08 00:18:12 +08:00
feat(go-api): migrate MCP server detail and download API to Go (#16113)
### What problem does this PR solve? - Migrated MCP server detail and export (download) API from Python to Go. - Registered route: `GET /api/v1/mcp/servers/:mcp_id` (supporting `?mode=download` query parameter).
This commit is contained in:
@@ -139,6 +139,56 @@ func (h *MCPHandler) ListMCPServers(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MCPHandler) GetMCPServer(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
mcpID := c.Param("mcp_id")
|
||||
if c.Query("mode") == "download" {
|
||||
result, code, err := h.mcpService.ExportMCPServer(user.ID, mcpID)
|
||||
if err != nil {
|
||||
mcpDetailError(c, code, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"message": "success",
|
||||
"data": result,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
result, code, err := h.mcpService.GetMCPServer(user.ID, mcpID)
|
||||
if err != nil {
|
||||
mcpDetailError(c, code, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"message": "success",
|
||||
"data": newMCPServerResponse(result),
|
||||
})
|
||||
}
|
||||
|
||||
func mcpDetailError(c *gin.Context, code common.ErrorCode, err error) {
|
||||
if code == common.CodeDataError {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": code,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeExceptionError,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// UpdateMCPServer updates an MCP server for the current user.
|
||||
func (h *MCPHandler) UpdateMCPServer(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
|
||||
Reference in New Issue
Block a user