diff --git a/server/cmd/api/main.go b/server/cmd/api/main.go index bd60df7..79b97f4 100644 --- a/server/cmd/api/main.go +++ b/server/cmd/api/main.go @@ -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)) diff --git a/server/docs/docs.go b/server/docs/docs.go index 9d11be1..565738b 100644 --- a/server/docs/docs.go +++ b/server/docs/docs.go @@ -1166,6 +1166,177 @@ const docTemplate = `{ } } }, + "/mcp/add": { + "post": { + "description": "创建新的MCP工具配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "创建MCP", + "parameters": [ + { + "description": "MCP信息", + "name": "mcp", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.MCP" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/mcp/list": { + "get": { + "description": "获取所有MCP工具配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "获取MCP列表", + "parameters": [ + { + "type": "string", + "description": "分类", + "name": "category", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/mcp/{id}": { + "get": { + "description": "根据ID获取MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "获取MCP详情", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "description": "更新MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "更新MCP", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "MCP信息", + "name": "mcp", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.MCP" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "description": "删除MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "删除MCP", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/model/add": { "post": { "description": "添加新的AI模型配置", @@ -2007,6 +2178,292 @@ const docTemplate = `{ } } } + }, + "/tool/add": { + "post": { + "description": "创建新的工具", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "创建工具", + "parameters": [ + { + "description": "工具信息", + "name": "tool", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.Tool" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/list": { + "get": { + "description": "获取所有工具列表,支持按分类和状态筛选", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "获取工具列表", + "parameters": [ + { + "type": "string", + "description": "工具分类", + "name": "category", + "in": "query" + }, + { + "type": "string", + "description": "工具状态", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/sync": { + "get": { + "description": "从代码中的默认配置同步工具到数据库", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "手动同步工具", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/{id}": { + "get": { + "description": "根据ID获取工具详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "获取工具详情", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "description": "更新工具信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "更新工具", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "工具信息", + "name": "tool", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.Tool" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "description": "删除工具", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "删除工具", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/user/list": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "获取所有用户列表(需要管理员权限)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "用户管理" + ], + "summary": "获取所有用户", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/user/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据ID获取用户详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "用户管理" + ], + "summary": "获取用户详情", + "parameters": [ + { + "type": "string", + "description": "用户ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } } }, "definitions": { @@ -2363,6 +2820,54 @@ const docTemplate = `{ } } }, + "model.MCP": { + "type": "object", + "properties": { + "args": { + "description": "参数,JSON数组格式", + "type": "string" + }, + "category": { + "description": "分类", + "type": "string" + }, + "command": { + "description": "启动命令", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "description": { + "description": "英文描述", + "type": "string" + }, + "description_cn": { + "description": "中文描述", + "type": "string" + }, + "env": { + "description": "环境变量,JSON对象格式", + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "status": { + "type": "string" + }, + "transport": { + "description": "stdio, http, sse", + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "model.MemoryInfo": { "type": "object", "properties": { @@ -2772,6 +3277,67 @@ const docTemplate = `{ } } }, + "model.Tool": { + "type": "object", + "properties": { + "args": { + "description": "参数,JSON数组格式", + "type": "string" + }, + "category": { + "type": "string" + }, + "command": { + "description": "启动命令", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "description": { + "description": "英文描述", + "type": "string" + }, + "description_cn": { + "description": "中文描述", + "type": "string" + }, + "env": { + "description": "环境变量,JSON对象格式", + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "parameters": { + "description": "JSON格式存储", + "type": "string" + }, + "provider": { + "type": "string" + }, + "require_approval": { + "type": "boolean" + }, + "security_level": { + "type": "string" + }, + "status": { + "description": "状态", + "type": "string" + }, + "transport": { + "description": "MCP 特有字段", + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "model.UpdateDatabaseRequest": { "type": "object", "properties": { diff --git a/server/docs/swagger.json b/server/docs/swagger.json index a3cf274..7d92a49 100644 --- a/server/docs/swagger.json +++ b/server/docs/swagger.json @@ -1155,6 +1155,177 @@ } } }, + "/mcp/add": { + "post": { + "description": "创建新的MCP工具配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "创建MCP", + "parameters": [ + { + "description": "MCP信息", + "name": "mcp", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.MCP" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/mcp/list": { + "get": { + "description": "获取所有MCP工具配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "获取MCP列表", + "parameters": [ + { + "type": "string", + "description": "分类", + "name": "category", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/mcp/{id}": { + "get": { + "description": "根据ID获取MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "获取MCP详情", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "description": "更新MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "更新MCP", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "MCP信息", + "name": "mcp", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.MCP" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "description": "删除MCP配置", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MCP管理" + ], + "summary": "删除MCP", + "parameters": [ + { + "type": "string", + "description": "MCP ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/model/add": { "post": { "description": "添加新的AI模型配置", @@ -1996,6 +2167,292 @@ } } } + }, + "/tool/add": { + "post": { + "description": "创建新的工具", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "创建工具", + "parameters": [ + { + "description": "工具信息", + "name": "tool", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.Tool" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/list": { + "get": { + "description": "获取所有工具列表,支持按分类和状态筛选", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "获取工具列表", + "parameters": [ + { + "type": "string", + "description": "工具分类", + "name": "category", + "in": "query" + }, + { + "type": "string", + "description": "工具状态", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/sync": { + "get": { + "description": "从代码中的默认配置同步工具到数据库", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "手动同步工具", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/tool/{id}": { + "get": { + "description": "根据ID获取工具详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "获取工具详情", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "description": "更新工具信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "更新工具", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "工具信息", + "name": "tool", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.Tool" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "description": "删除工具", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "工具管理" + ], + "summary": "删除工具", + "parameters": [ + { + "type": "string", + "description": "工具ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/user/list": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "获取所有用户列表(需要管理员权限)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "用户管理" + ], + "summary": "获取所有用户", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/user/{id}": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据ID获取用户详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "用户管理" + ], + "summary": "获取用户详情", + "parameters": [ + { + "type": "string", + "description": "用户ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } } }, "definitions": { @@ -2352,6 +2809,54 @@ } } }, + "model.MCP": { + "type": "object", + "properties": { + "args": { + "description": "参数,JSON数组格式", + "type": "string" + }, + "category": { + "description": "分类", + "type": "string" + }, + "command": { + "description": "启动命令", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "description": { + "description": "英文描述", + "type": "string" + }, + "description_cn": { + "description": "中文描述", + "type": "string" + }, + "env": { + "description": "环境变量,JSON对象格式", + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "status": { + "type": "string" + }, + "transport": { + "description": "stdio, http, sse", + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "model.MemoryInfo": { "type": "object", "properties": { @@ -2761,6 +3266,67 @@ } } }, + "model.Tool": { + "type": "object", + "properties": { + "args": { + "description": "参数,JSON数组格式", + "type": "string" + }, + "category": { + "type": "string" + }, + "command": { + "description": "启动命令", + "type": "string" + }, + "created_at": { + "type": "string" + }, + "description": { + "description": "英文描述", + "type": "string" + }, + "description_cn": { + "description": "中文描述", + "type": "string" + }, + "env": { + "description": "环境变量,JSON对象格式", + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "parameters": { + "description": "JSON格式存储", + "type": "string" + }, + "provider": { + "type": "string" + }, + "require_approval": { + "type": "boolean" + }, + "security_level": { + "type": "string" + }, + "status": { + "description": "状态", + "type": "string" + }, + "transport": { + "description": "MCP 特有字段", + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "model.UpdateDatabaseRequest": { "type": "object", "properties": { diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml index 273524b..65a979f 100644 --- a/server/docs/swagger.yaml +++ b/server/docs/swagger.yaml @@ -245,6 +245,40 @@ definitions: description: 中文映射名 type: string type: object + model.MCP: + properties: + args: + description: 参数,JSON数组格式 + type: string + category: + description: 分类 + type: string + command: + description: 启动命令 + type: string + created_at: + type: string + description: + description: 英文描述 + type: string + description_cn: + description: 中文描述 + type: string + env: + description: 环境变量,JSON对象格式 + type: string + id: + type: string + name: + type: string + status: + type: string + transport: + description: stdio, http, sse + type: string + updated_at: + type: string + type: object model.MemoryInfo: properties: available: @@ -536,6 +570,49 @@ definitions: - model_type - provider type: object + model.Tool: + properties: + args: + description: 参数,JSON数组格式 + type: string + category: + type: string + command: + description: 启动命令 + type: string + created_at: + type: string + description: + description: 英文描述 + type: string + description_cn: + description: 中文描述 + type: string + env: + description: 环境变量,JSON对象格式 + type: string + id: + type: string + name: + type: string + parameters: + description: JSON格式存储 + type: string + provider: + type: string + require_approval: + type: boolean + security_level: + type: string + status: + description: 状态 + type: string + transport: + description: MCP 特有字段 + type: string + updated_at: + type: string + type: object model.UpdateDatabaseRequest: properties: charset: @@ -1399,6 +1476,120 @@ paths: summary: 获取数据库列表 tags: - 数据库管理 + /mcp/{id}: + delete: + consumes: + - application/json + description: 删除MCP配置 + parameters: + - description: MCP ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 删除MCP + tags: + - MCP管理 + get: + consumes: + - application/json + description: 根据ID获取MCP配置 + parameters: + - description: MCP ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 获取MCP详情 + tags: + - MCP管理 + put: + consumes: + - application/json + description: 更新MCP配置 + parameters: + - description: MCP ID + in: path + name: id + required: true + type: string + - description: MCP信息 + in: body + name: mcp + required: true + schema: + $ref: '#/definitions/model.MCP' + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 更新MCP + tags: + - MCP管理 + /mcp/add: + post: + consumes: + - application/json + description: 创建新的MCP工具配置 + parameters: + - description: MCP信息 + in: body + name: mcp + required: true + schema: + $ref: '#/definitions/model.MCP' + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 创建MCP + tags: + - MCP管理 + /mcp/list: + get: + consumes: + - application/json + description: 获取所有MCP工具配置 + parameters: + - description: 分类 + in: query + name: category + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 获取MCP列表 + tags: + - MCP管理 /model/{id}: delete: consumes: @@ -1957,4 +2148,192 @@ paths: summary: 获取系统信息 tags: - 系统 + /tool/{id}: + delete: + consumes: + - application/json + description: 删除工具 + parameters: + - description: 工具ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 删除工具 + tags: + - 工具管理 + get: + consumes: + - application/json + description: 根据ID获取工具详情 + parameters: + - description: 工具ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 获取工具详情 + tags: + - 工具管理 + put: + consumes: + - application/json + description: 更新工具信息 + parameters: + - description: 工具ID + in: path + name: id + required: true + type: string + - description: 工具信息 + in: body + name: tool + required: true + schema: + $ref: '#/definitions/model.Tool' + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 更新工具 + tags: + - 工具管理 + /tool/add: + post: + consumes: + - application/json + description: 创建新的工具 + parameters: + - description: 工具信息 + in: body + name: tool + required: true + schema: + $ref: '#/definitions/model.Tool' + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 创建工具 + tags: + - 工具管理 + /tool/list: + get: + consumes: + - application/json + description: 获取所有工具列表,支持按分类和状态筛选 + parameters: + - description: 工具分类 + in: query + name: category + type: string + - description: 工具状态 + in: query + name: status + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 获取工具列表 + tags: + - 工具管理 + /tool/sync: + get: + consumes: + - application/json + description: 从代码中的默认配置同步工具到数据库 + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + summary: 手动同步工具 + tags: + - 工具管理 + /user/{id}: + get: + consumes: + - application/json + description: 根据ID获取用户详情 + parameters: + - description: 用户ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "404": + description: Not Found + schema: + additionalProperties: + type: string + type: object + security: + - BearerAuth: [] + summary: 获取用户详情 + tags: + - 用户管理 + /user/list: + get: + consumes: + - application/json + description: 获取所有用户列表(需要管理员权限) + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "401": + description: Unauthorized + schema: + additionalProperties: + type: string + type: object + security: + - BearerAuth: [] + summary: 获取所有用户 + tags: + - 用户管理 swagger: "2.0" diff --git a/server/internal/model/tool.go b/server/internal/model/tool.go index e55ee5a..e20e7e4 100644 --- a/server/internal/model/tool.go +++ b/server/internal/model/tool.go @@ -11,15 +11,22 @@ import ( type Tool struct { ID string `json:"id" gorm:"primaryKey"` Name string `json:"name" gorm:"uniqueIndex;size:100;not null"` - Description string `json:"description" gorm:"type:text"` + Description string `json:"description" gorm:"type:text"` // 英文描述 + DescriptionCN string `json:"description_cn" gorm:"type:text"` // 中文描述 Category string `json:"category" gorm:"size:50;not null"` Provider string `json:"provider" gorm:"size:100"` SecurityLevel string `json:"security_level" gorm:"size:20;default:'safe'"` RequireApproval bool `json:"require_approval" gorm:"default:false"` Parameters string `json:"parameters" gorm:"type:text"` // JSON格式存储 - Status string `json:"status" gorm:"size:20;default:'active'"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + // MCP 特有字段 + Transport string `json:"transport" gorm:"size:20;default:'stdio'"` // stdio, http, sse + Command string `json:"command" gorm:"size:500"` // 启动命令 + Args string `json:"args" gorm:"type:text"` // 参数,JSON数组格式 + Env string `json:"env" gorm:"type:text"` // 环境变量,JSON对象格式 + // 状态 + Status string `json:"status" gorm:"size:20;default:'active'"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // BeforeCreate 创建前自动生成ID diff --git a/server/internal/service/auth_service.go b/server/internal/service/auth_service.go index 71930d8..c2097b7 100644 --- a/server/internal/service/auth_service.go +++ b/server/internal/service/auth_service.go @@ -193,8 +193,8 @@ func (s *AuthService) createUserWorkspace(username string) error { return err } - // 创建子目录 - subDirs := []string{"projects", "files", "temp"} + // 创建子目录: skills(技能), scripts(脚本), sandbox(沙盒), files(文件), temp(临时) + subDirs := []string{"skills", "scripts", "sandbox", "files", "temp"} for _, dir := range subDirs { if err := os.MkdirAll(filepath.Join(workspacePath, dir), 0755); err != nil { return err diff --git a/server/internal/service/tool_service.go b/server/internal/service/tool_service.go index b0be55f..1031ba0 100644 --- a/server/internal/service/tool_service.go +++ b/server/internal/service/tool_service.go @@ -58,12 +58,12 @@ func (s *ToolService) DeleteTool(id string) error { func (s *ToolService) InitDefaultTools() error { log.Println("[ToolService] Starting init default tools...") - // 获取默认工具 - tools := s.getDefaultTools() - // 删除现有的系统工具,重新插入 s.toolRepo.DB().Where("provider = ?", "system").Delete(&model.Tool{}) - log.Printf("[ToolService] Deleted existing system tools, inserting %d default tools...", len(tools)) + + // 插入默认工具 + tools := s.getDefaultTools() + log.Printf("[ToolService] Inserting %d default tools...", len(tools)) for _, tool := range tools { if err := s.toolRepo.Create(&tool); err != nil { @@ -83,6 +83,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "read_file", Description: "Read the contents of a file from the filesystem.", + DescriptionCN: "读取文件系统的文件内容。", Category: "file", SecurityLevel: "safe", RequireApproval: false, @@ -93,6 +94,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "write_file", Description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does.", + DescriptionCN: "写入内容到文件。如果文件不存在则创建,存在则覆盖。", Category: "file", SecurityLevel: "review", RequireApproval: true, @@ -103,6 +105,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "list_dir", Description: "List the contents of a directory.", + DescriptionCN: "列出目录的内容。", Category: "file", SecurityLevel: "safe", RequireApproval: false, @@ -113,6 +116,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "delete_file", Description: "Delete a file or directory.", + DescriptionCN: "删除文件或目录。", Category: "file", SecurityLevel: "danger", RequireApproval: true, @@ -123,6 +127,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "search_files", Description: "Search for files by name pattern or content.", + DescriptionCN: "按文件名模式或内容搜索文件。", Category: "file", SecurityLevel: "safe", RequireApproval: false, @@ -134,6 +139,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "execute_python", Description: "Execute Python code in a sandboxed environment.", + DescriptionCN: "在沙盒环境中执行Python代码。", Category: "executor", SecurityLevel: "review", RequireApproval: true, @@ -144,6 +150,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "execute_javascript", Description: "Execute JavaScript code in a sandboxed environment.", + DescriptionCN: "在沙盒环境中执行JavaScript代码。", Category: "executor", SecurityLevel: "review", RequireApproval: true, @@ -154,6 +161,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "execute_bash", Description: "Execute a bash command in a sandboxed environment.", + DescriptionCN: "在沙盒环境中执行Bash命令。", Category: "executor", SecurityLevel: "danger", RequireApproval: true, @@ -165,6 +173,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "web_fetch", Description: "Fetch content from a web URL.", + DescriptionCN: "从网页URL获取内容。", Category: "web", SecurityLevel: "safe", RequireApproval: false, @@ -175,6 +184,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "web_search", Description: "Search the web for information.", + DescriptionCN: "在网络上搜索信息。", Category: "web", SecurityLevel: "safe", RequireApproval: false, @@ -186,6 +196,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "http_request", Description: "Make HTTP requests to APIs.", + DescriptionCN: "向API发送HTTP请求。", Category: "http", SecurityLevel: "safe", RequireApproval: false, @@ -197,6 +208,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "send_notification", Description: "Send notifications via email, webhook, dingtalk, or slack.", + DescriptionCN: "通过邮件、webhook、钉钉或Slack发送通知。", Category: "notification", SecurityLevel: "safe", RequireApproval: false, @@ -208,6 +220,7 @@ func (s *ToolService) getDefaultTools() []model.Tool { { Name: "get_current_time", Description: "Get the current date and time.", + DescriptionCN: "获取当前日期和时间。", Category: "system", SecurityLevel: "safe", RequireApproval: false,