Skip to content

Commit 375b21c

Browse files
authored
发布2.9.1版本 (#2189)
* feat: mcp能力调整为 streamhttp的独立服务 不再依赖gva本体 * feat: 增加MCP启动能力,增加AI工作流需求整理能力。 * feat: 增加需求梳理能力 * feat: 清理无用日志 * feat: 移除无用的Dify Chatflow文本和代码生成器按钮
1 parent 324aaa3 commit 375b21c

60 files changed

Lines changed: 6800 additions & 1471 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

server/api/v1/example/enter.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import "github.com/flipped-aurora/gin-vue-admin/server/service"
44

55
type ApiGroup struct {
66
CustomerApi
7-
FileUploadAndDownloadApi
7+
88
AttachmentCategoryApi
9+
FileUploadAndDownloadApi
910
}
1011

1112
var (
12-
customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService
13-
fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService
13+
customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService
14+
1415
attachmentCategoryService = service.ServiceGroupApp.ExampleServiceGroup.AttachmentCategoryService
16+
fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService
1517
)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package system
2+
3+
import (
4+
"github.com/flipped-aurora/gin-vue-admin/server/global"
5+
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
6+
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
7+
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
8+
"github.com/flipped-aurora/gin-vue-admin/server/utils"
9+
"github.com/gin-gonic/gin"
10+
"go.uber.org/zap"
11+
)
12+
13+
type AIWorkflowSessionApi struct{}
14+
15+
func (a *AIWorkflowSessionApi) Save(c *gin.Context) {
16+
var info systemReq.SysAIWorkflowSessionUpsert
17+
if err := c.ShouldBindJSON(&info); err != nil {
18+
response.FailWithMessage(err.Error(), c)
19+
return
20+
}
21+
22+
session, err := aiWorkflowSessionService.Save(c.Request.Context(), utils.GetUserID(c), info)
23+
if err != nil {
24+
global.GVA_LOG.Error("保存 AI 工作流会话失败", zap.Error(err))
25+
response.FailWithMessage("保存会话失败", c)
26+
return
27+
}
28+
29+
response.OkWithDetailed(gin.H{"session": session}, "保存成功", c)
30+
}
31+
32+
func (a *AIWorkflowSessionApi) GetList(c *gin.Context) {
33+
var info systemReq.SysAIWorkflowSessionSearch
34+
if err := c.ShouldBindJSON(&info); err != nil {
35+
response.FailWithMessage(err.Error(), c)
36+
return
37+
}
38+
39+
list, total, err := aiWorkflowSessionService.GetList(c.Request.Context(), utils.GetUserID(c), info)
40+
if err != nil {
41+
global.GVA_LOG.Error("获取 AI 工作流会话列表失败", zap.Error(err))
42+
response.FailWithMessage("获取会话列表失败", c)
43+
return
44+
}
45+
46+
response.OkWithDetailed(response.PageResult{
47+
List: list,
48+
Total: total,
49+
Page: info.Page,
50+
PageSize: info.PageSize,
51+
}, "获取成功", c)
52+
}
53+
54+
func (a *AIWorkflowSessionApi) GetDetail(c *gin.Context) {
55+
var info commonReq.GetById
56+
if err := c.ShouldBindJSON(&info); err != nil {
57+
response.FailWithMessage(err.Error(), c)
58+
return
59+
}
60+
61+
session, err := aiWorkflowSessionService.GetDetail(c.Request.Context(), utils.GetUserID(c), info.Uint())
62+
if err != nil {
63+
global.GVA_LOG.Error("获取 AI 工作流会话详情失败", zap.Error(err))
64+
response.FailWithMessage("获取会话详情失败", c)
65+
return
66+
}
67+
68+
response.OkWithDetailed(gin.H{"session": session}, "获取成功", c)
69+
}
70+
71+
func (a *AIWorkflowSessionApi) Delete(c *gin.Context) {
72+
var info commonReq.GetById
73+
if err := c.ShouldBindJSON(&info); err != nil {
74+
response.FailWithMessage(err.Error(), c)
75+
return
76+
}
77+
78+
if err := aiWorkflowSessionService.Delete(c.Request.Context(), utils.GetUserID(c), info.Uint()); err != nil {
79+
global.GVA_LOG.Error("删除 AI 工作流会话失败", zap.Error(err))
80+
response.FailWithMessage("删除会话失败", c)
81+
return
82+
}
83+
84+
response.OkWithMessage("删除成功", c)
85+
}
86+
87+
func (a *AIWorkflowSessionApi) DumpMarkdown(c *gin.Context) {
88+
var info systemReq.SysAIWorkflowMarkdownDump
89+
if err := c.ShouldBindJSON(&info); err != nil {
90+
response.FailWithMessage(err.Error(), c)
91+
return
92+
}
93+
94+
result, err := aiWorkflowSessionService.DumpMarkdown(c.Request.Context(), utils.GetUserID(c), info)
95+
if err != nil {
96+
global.GVA_LOG.Error("AI 工作流 Markdown 落盘失败", zap.Error(err))
97+
response.FailWithMessage(err.Error(), c)
98+
return
99+
}
100+
101+
response.OkWithDetailed(gin.H{"result": result}, "落盘成功", c)
102+
}
Lines changed: 108 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package system
22

33
import (
4-
"fmt"
4+
"strings"
5+
56
"github.com/flipped-aurora/gin-vue-admin/server/global"
7+
mcpTool "github.com/flipped-aurora/gin-vue-admin/server/mcp"
68
"github.com/flipped-aurora/gin-vue-admin/server/mcp/client"
79
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
810
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
911
"github.com/gin-gonic/gin"
1012
"github.com/mark3labs/mcp-go/mcp"
1113
)
1214

13-
// Create
14-
// @Tags mcp
15-
// @Summary 自动McpTool
16-
// @Security ApiKeyAuth
17-
// @accept application/json
18-
// @Produce application/json
19-
// @Param data body request.AutoMcpTool true "创建自动代码"
20-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
21-
// @Router /autoCode/mcp [post]
2215
func (a *AutoCodeTemplateApi) MCP(c *gin.Context) {
2316
var info request.AutoMcpTool
24-
err := c.ShouldBindJSON(&info)
25-
if err != nil {
17+
if err := c.ShouldBindJSON(&info); err != nil {
2618
response.FailWithMessage(err.Error(), c)
2719
return
2820
}
@@ -36,109 +28,146 @@ func (a *AutoCodeTemplateApi) MCP(c *gin.Context) {
3628
response.OkWithMessage("创建成功,MCP Tool路径:"+toolFilePath, c)
3729
}
3830

39-
// Create
40-
// @Tags mcp
41-
// @Summary 自动McpTool
42-
// @Security ApiKeyAuth
43-
// @accept application/json
44-
// @Produce application/json
45-
// @Param data body request.AutoMcpTool true "创建自动代码"
46-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
47-
// @Router /autoCode/mcpList [post]
48-
func (a *AutoCodeTemplateApi) MCPList(c *gin.Context) {
31+
func (a *AutoCodeTemplateApi) MCPStatus(c *gin.Context) {
32+
response.OkWithData(gin.H{
33+
"status": mcpTool.GetManagedStandaloneStatus(c.Request.Context()),
34+
"mcpServerConfig": buildMCPServerConfig(),
35+
}, c)
36+
}
4937

50-
baseUrl := fmt.Sprintf("http://127.0.0.1:%d%s", global.GVA_CONFIG.System.Addr, global.GVA_CONFIG.MCP.SSEPath)
38+
func (a *AutoCodeTemplateApi) MCPStart(c *gin.Context) {
39+
status, err := mcpTool.StartManagedStandalone(c.Request.Context())
40+
if err != nil {
41+
response.FailWithDetailed(gin.H{
42+
"status": status,
43+
"mcpServerConfig": buildMCPServerConfig(),
44+
}, err.Error(), c)
45+
return
46+
}
5147

52-
testClient, err := client.NewClient(baseUrl, "testClient", "v1.0.0", global.GVA_CONFIG.MCP.Name)
53-
defer testClient.Close()
54-
toolsRequest := mcp.ListToolsRequest{}
48+
response.OkWithDetailed(gin.H{
49+
"status": status,
50+
"mcpServerConfig": buildMCPServerConfig(),
51+
}, "MCP独立服务已启动", c)
52+
}
5553

56-
list, err := testClient.ListTools(c.Request.Context(), toolsRequest)
54+
func (a *AutoCodeTemplateApi) MCPStop(c *gin.Context) {
55+
status, err := mcpTool.StopManagedStandalone(c.Request.Context())
56+
if err != nil {
57+
response.FailWithDetailed(gin.H{
58+
"status": status,
59+
"mcpServerConfig": buildMCPServerConfig(),
60+
}, err.Error(), c)
61+
return
62+
}
5763

64+
response.OkWithDetailed(gin.H{
65+
"status": status,
66+
"mcpServerConfig": buildMCPServerConfig(),
67+
}, "MCP独立服务已停用", c)
68+
}
69+
70+
func (a *AutoCodeTemplateApi) MCPList(c *gin.Context) {
71+
baseURL := mcpTool.ResolveMCPServiceURL()
72+
testClient, err := client.NewClient(baseURL, "testClient", "v1.0.0", mcpServerName(), incomingMCPHeaders(c))
5873
if err != nil {
59-
response.FailWithMessage("创建失败", c)
60-
global.GVA_LOG.Error(err.Error())
74+
response.FailWithDetailed(gin.H{
75+
"status": mcpTool.GetManagedStandaloneStatus(c.Request.Context()),
76+
"mcpServerConfig": buildMCPServerConfig(),
77+
}, "连接MCP服务失败:"+err.Error(), c)
6178
return
6279
}
80+
defer testClient.Close()
6381

64-
mcpServerConfig := map[string]interface{}{
65-
"mcpServers": map[string]interface{}{
66-
global.GVA_CONFIG.MCP.Name: map[string]string{
67-
"url": baseUrl,
68-
},
69-
},
82+
list, err := testClient.ListTools(c.Request.Context(), mcp.ListToolsRequest{})
83+
if err != nil {
84+
response.FailWithDetailed(gin.H{
85+
"status": mcpTool.GetManagedStandaloneStatus(c.Request.Context()),
86+
"mcpServerConfig": buildMCPServerConfig(),
87+
}, "获取工具列表失败:"+err.Error(), c)
88+
return
7089
}
90+
7191
response.OkWithData(gin.H{
72-
"mcpServerConfig": mcpServerConfig,
92+
"status": mcpTool.GetManagedStandaloneStatus(c.Request.Context()),
93+
"mcpServerConfig": buildMCPServerConfig(),
7394
"list": list,
7495
}, c)
7596
}
7697

77-
// Create
78-
// @Tags mcp
79-
// @Summary 测试McpTool
80-
// @Security ApiKeyAuth
81-
// @accept application/json
82-
// @Produce application/json
83-
// @Param data body object true "调用MCP Tool的参数"
84-
// @Success 200 {object} response.Response "{"success":true,"data":{},"msg":"测试成功"}"
85-
// @Router /autoCode/mcpTest [post]
98+
func (a *AutoCodeTemplateApi) MCPRoutes(c *gin.Context) {
99+
response.OkWithData(gin.H{
100+
"routes": global.GVA_ROUTERS,
101+
}, c)
102+
}
103+
86104
func (a *AutoCodeTemplateApi) MCPTest(c *gin.Context) {
87-
// 定义接口请求结构
88105
var testRequest struct {
89-
Name string `json:"name" binding:"required"` // 工具名称
90-
Arguments map[string]interface{} `json:"arguments" binding:"required"` // 工具参数
106+
Name string `json:"name" binding:"required"`
107+
Arguments map[string]interface{} `json:"arguments" binding:"required"`
91108
}
92-
93-
// 绑定JSON请求体
94109
if err := c.ShouldBindJSON(&testRequest); err != nil {
95110
response.FailWithMessage("参数解析失败:"+err.Error(), c)
96111
return
97112
}
98113

99-
// 创建MCP客户端
100-
baseUrl := fmt.Sprintf("http://127.0.0.1:%d%s", global.GVA_CONFIG.System.Addr, global.GVA_CONFIG.MCP.SSEPath)
101-
testClient, err := client.NewClient(baseUrl, "testClient", "v1.0.0", global.GVA_CONFIG.MCP.Name)
114+
baseURL := mcpTool.ResolveMCPServiceURL()
115+
testClient, err := client.NewClient(baseURL, "testClient", "v1.0.0", mcpServerName(), incomingMCPHeaders(c))
102116
if err != nil {
103-
response.FailWithMessage("创建MCP客户端失败:"+err.Error(), c)
117+
response.FailWithMessage("连接MCP服务失败:"+err.Error(), c)
104118
return
105119
}
106120
defer testClient.Close()
107121

108-
ctx := c.Request.Context()
109-
110-
// 初始化MCP连接
111-
initRequest := mcp.InitializeRequest{}
112-
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
113-
initRequest.Params.ClientInfo = mcp.Implementation{
114-
Name: "testClient",
115-
Version: "v1.0.0",
116-
}
117-
118-
_, err = testClient.Initialize(ctx, initRequest)
119-
if err != nil {
120-
response.FailWithMessage("初始化MCP连接失败:"+err.Error(), c)
121-
return
122-
}
123-
124-
// 构建工具调用请求
125-
request := mcp.CallToolRequest{}
126-
request.Params.Name = testRequest.Name
127-
request.Params.Arguments = testRequest.Arguments
122+
callRequest := mcp.CallToolRequest{}
123+
callRequest.Params.Name = testRequest.Name
124+
callRequest.Params.Arguments = testRequest.Arguments
128125

129-
// 调用工具
130-
result, err := testClient.CallTool(ctx, request)
126+
result, err := testClient.CallTool(c.Request.Context(), callRequest)
131127
if err != nil {
132128
response.FailWithMessage("工具调用失败:"+err.Error(), c)
133129
return
134130
}
135-
136-
// 处理响应结果
137131
if len(result.Content) == 0 {
138132
response.FailWithMessage("工具未返回任何内容", c)
139133
return
140134
}
141135

142-
// 返回结果
143136
response.OkWithData(result.Content, c)
144137
}
138+
139+
func incomingMCPHeaders(c *gin.Context) map[string]string {
140+
headerName := mcpTool.ConfiguredAuthHeader()
141+
headerValue := c.GetHeader(headerName)
142+
if headerValue == "" {
143+
return nil
144+
}
145+
146+
return map[string]string{
147+
headerName: headerValue,
148+
}
149+
}
150+
151+
func buildMCPServerConfig() map[string]interface{} {
152+
baseURL := mcpTool.ResolveMCPServiceURL()
153+
authHeader := mcpTool.ConfiguredAuthHeader()
154+
serverName := mcpServerName()
155+
156+
return map[string]interface{}{
157+
"mcpServers": map[string]interface{}{
158+
serverName: map[string]interface{}{
159+
"url": baseURL,
160+
"headers": map[string]string{
161+
authHeader: "${YOUR_GVA_TOKEN}",
162+
},
163+
},
164+
},
165+
}
166+
}
167+
168+
func mcpServerName() string {
169+
if name := strings.TrimSpace(global.GVA_CONFIG.MCP.Name); name != "" {
170+
return name
171+
}
172+
return "gva"
173+
}

0 commit comments

Comments
 (0)