feat: 后端工具和 MCP 模块更新
- main.go: 更新工作空间目录,添加 MCP 模型迁移 - tool.go: 添加 description_cn 字段 - auth_service, tool_service: 优化 - 更新 Swagger 文档 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -128,8 +128,8 @@ func ensureAdminWorkspace() {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建子目录
|
||||
for _, dir := range []string{"projects", "files", "temp"} {
|
||||
// 创建子目录: skills(技能), scripts(脚本), sandbox(沙盒), files(文件), temp(临时)
|
||||
for _, dir := range []string{"skills", "scripts", "sandbox", "files", "temp"} {
|
||||
os.MkdirAll(filepath.Join(workspacePath, dir), 0755)
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func main() {
|
||||
}
|
||||
|
||||
// 3. 自动迁移表
|
||||
db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{}, &model.ModelInfo{}, &model.KnowledgeBase{}, &model.KnowledgeDocument{}, &model.User{}, &model.Role{}, &model.Tool{})
|
||||
db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{}, &model.ModelInfo{}, &model.KnowledgeBase{}, &model.KnowledgeDocument{}, &model.User{}, &model.Role{}, &model.Tool{}, &model.MCP{})
|
||||
|
||||
// 3.1 确保 users 和 roles 表存在(使用 SQL 强制创建)
|
||||
db.Exec(`
|
||||
@@ -209,6 +209,22 @@ func main() {
|
||||
if !migrator.HasColumn(&model.Tool{}, "parameters") {
|
||||
migrator.AddColumn(&model.Tool{}, "parameters")
|
||||
}
|
||||
if !migrator.HasColumn(&model.Tool{}, "description_cn") {
|
||||
migrator.AddColumn(&model.Tool{}, "description_cn")
|
||||
}
|
||||
// MCP 相关字段
|
||||
if !migrator.HasColumn(&model.Tool{}, "transport") {
|
||||
migrator.AddColumn(&model.Tool{}, "transport")
|
||||
}
|
||||
if !migrator.HasColumn(&model.Tool{}, "command") {
|
||||
migrator.AddColumn(&model.Tool{}, "command")
|
||||
}
|
||||
if !migrator.HasColumn(&model.Tool{}, "args") {
|
||||
migrator.AddColumn(&model.Tool{}, "args")
|
||||
}
|
||||
if !migrator.HasColumn(&model.Tool{}, "env") {
|
||||
migrator.AddColumn(&model.Tool{}, "env")
|
||||
}
|
||||
|
||||
log.Println("Database tables verified/created")
|
||||
|
||||
@@ -219,6 +235,7 @@ func main() {
|
||||
knowledgeRepo := repository.NewKnowledgeRepository(db)
|
||||
userRepo := repository.NewUserRepository(db)
|
||||
toolRepo := repository.NewToolRepository(db)
|
||||
mcpRepo := repository.NewMCPRepository(db)
|
||||
|
||||
// 4.1 初始化默认管理员用户
|
||||
initDefaultAdmin(userRepo)
|
||||
@@ -235,6 +252,7 @@ func main() {
|
||||
knowledgeService := service.NewKnowledgeService(knowledgeRepo, modelRepo, uploadService, cfg.PythonServiceURL, cfg.AICoreServiceAddr, cfg.MarkdownLocalPath)
|
||||
authService := service.NewAuthService(cfg.JWTSecret, userRepo)
|
||||
toolService := service.NewToolService(toolRepo)
|
||||
mcpService := service.NewMCPService(mcpRepo)
|
||||
|
||||
// 4.2 初始化默认工具
|
||||
if err := toolService.InitDefaultTools(); err != nil {
|
||||
@@ -252,6 +270,7 @@ func main() {
|
||||
knowledgeHandler := handler.NewKnowledgeHandler(knowledgeService)
|
||||
authHandler := handler.NewAuthHandler(authService)
|
||||
toolHandler := handler.NewToolHandler(toolService)
|
||||
mcpHandler := handler.NewMCPHandler(mcpService)
|
||||
var uploadHandler *handler.UploadHandler
|
||||
if uploadService != nil {
|
||||
uploadHandler = handler.NewUploadHandler(uploadService, knowledgeRepo)
|
||||
@@ -396,6 +415,16 @@ func main() {
|
||||
toolGroup.DELETE("/:id", toolHandler.Delete)
|
||||
}
|
||||
|
||||
// MCP管理模块
|
||||
mcpGroup := r.Group("/mcp")
|
||||
{
|
||||
mcpGroup.GET("/list", mcpHandler.List)
|
||||
mcpGroup.GET("/:id", mcpHandler.GetByID)
|
||||
mcpGroup.POST("/add", mcpHandler.Create)
|
||||
mcpGroup.PUT("/:id", mcpHandler.Update)
|
||||
mcpGroup.DELETE("/:id", mcpHandler.Delete)
|
||||
}
|
||||
|
||||
// Swagger 文档
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user