Files
ai-agent/internal/handlers/dashboard/mcp_handler.go
T
mlogclub 5d7c10aeab refactor: rename agent widget references to AI agent for consistency
- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__.
- Changed message types in support host bridge from "cs-agent" to "cs-ai-agent".
- Minified SDK script updated to reflect new AI agent naming conventions.
- Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
2026-05-30 21:19:36 +08:00

106 lines
3.0 KiB
Go

package dashboard
import (
"context"
"cs-ai-agent/internal/pkg/httpx"
"cs-ai-agent/internal/pkg/constants"
"cs-ai-agent/internal/pkg/dto/request"
"cs-ai-agent/internal/pkg/dto/response"
"cs-ai-agent/internal/pkg/i18nx"
"cs-ai-agent/internal/services"
"cs-ai-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
)
func MCPAnyList_servers(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionMCPView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, response.BuildMCPServerInfoResponses(services.MCPDebugService.ListServers()))
}
func MCPAnyCatalog(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionMCPView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
items, err := services.ToolCatalogService.ListMCPToolsWithLocale(context.Background(), i18nx.Locale(ctx))
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
ret := make([]response.MCPToolCatalogResponse, 0, len(items))
for _, item := range items {
ret = append(ret, response.MCPToolCatalogResponse{
ToolCode: item.ToolCode,
ServerCode: item.ServerCode,
ToolName: item.ToolName,
SourceType: item.SourceType,
AutoInjected: item.AutoInjected,
Title: item.Title,
Description: item.Description,
InputSchema: item.InputSchema,
OutputSchema: item.OutputSchema,
})
}
httpx.WriteJSON(ctx, ret)
}
func MCPPostTest_connection(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionMCPView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.MCPServerDebugRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
result, err := services.MCPDebugService.TestConnection(context.Background(), req.ServerCode)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, response.BuildMCPConnectionResponse(result))
}
func MCPPostList_tools(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionMCPView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.MCPServerDebugRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
result, err := services.MCPDebugService.ListTools(context.Background(), req.ServerCode)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, response.BuildMCPToolInfoResponses(result))
}
func MCPPostCall_tool(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionMCPCall); err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.MCPCallToolRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
result, err := services.MCPDebugService.CallTool(context.Background(), req.ServerCode, req.ToolName, req.Arguments)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, response.BuildMCPCallToolResponse(result))
}