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:
2026-03-11 14:45:49 +08:00
parent cab6488d71
commit 298ff7c79d
7 changed files with 1573 additions and 13 deletions

View File

@@ -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": {

View File

@@ -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": {

View File

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