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:
Hz_
2026-06-18 11:09:22 +08:00
committed by GitHub
parent f59332bc37
commit 69dbc44983
5 changed files with 206 additions and 2 deletions

View File

@@ -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)