mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 00:46:42 +08:00
feat: add Go MCP server create API (#15260)
## What Implementation for POST /api/v1/mcp/servers #15240
This commit is contained in:
committed by
GitHub
parent
bea8092007
commit
32d5bf9791
65
internal/handler/mcp.go
Normal file
65
internal/handler/mcp.go
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"ragflow/internal/common"
|
||||
"ragflow/internal/service"
|
||||
)
|
||||
|
||||
// MCPHandler handles MCP server requests.
|
||||
type MCPHandler struct {
|
||||
mcpService *service.MCPService
|
||||
}
|
||||
|
||||
// NewMCPHandler creates an MCP handler.
|
||||
func NewMCPHandler(mcpService *service.MCPService) *MCPHandler {
|
||||
return &MCPHandler{
|
||||
mcpService: mcpService,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateMCPServer creates an MCP server for the current user.
|
||||
func (h *MCPHandler) CreateMCPServer(c *gin.Context) {
|
||||
user, errorCode, errorMessage := GetUser(c)
|
||||
if errorCode != common.CodeSuccess {
|
||||
jsonError(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
var req service.CreateMCPServerRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
jsonError(c, common.CodeDataError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
result, code, err := h.mcpService.CreateMCPServer(user.ID, req)
|
||||
if err != nil {
|
||||
jsonError(c, code, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeSuccess,
|
||||
"message": "success",
|
||||
"data": result,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user