Files
ai-agent/internal/controllers/console/mcp_controller.go
T
mlogclub 1370e4b675 feat: enhance AI agent functionality with tool management and logging improvements
- Added AllowedToolCodes field to Context for managing tool access.
- Introduced ResumeSource in aiReplyTraceData to track resume points.
- Enhanced logging with additional fields: PlannedSkillName, SkillRouteTrace, InterruptType, ResumeSource, and FinalStatus.
- Implemented functions to parse and resolve allowed tool codes for agents and skills.
- Refactored skill definition creation and update logic to streamline request handling.
- Updated MCP tool catalog to include source type and integrated built-in tools.
- Improved UI components to display additional tool information and enhance user experience.
2026-04-10 14:43:57 +08:00

95 lines
2.9 KiB
Go

package console
import (
"context"
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type MCPController struct {
Ctx iris.Context
}
func (c *MCPController) AnyList_servers() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionMCPView); err != nil {
return web.JsonError(err)
}
return web.JsonData(response.BuildMCPServerInfoResponses(services.MCPDebugService.ListServers()))
}
func (c *MCPController) AnyCatalog() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionMCPView); err != nil {
return web.JsonError(err)
}
items, err := services.ToolCatalogService.ListMCPTools(context.Background())
if err != nil {
return web.JsonError(err)
}
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,
Title: item.Title,
Description: item.Description,
InputSchema: item.InputSchema,
OutputSchema: item.OutputSchema,
})
}
return web.JsonData(ret)
}
func (c *MCPController) PostTest_connection() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionMCPView); err != nil {
return web.JsonError(err)
}
req := request.MCPServerDebugRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
result, err := services.MCPDebugService.TestConnection(context.Background(), req.ServerCode)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(response.BuildMCPConnectionResponse(result))
}
func (c *MCPController) PostList_tools() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionMCPView); err != nil {
return web.JsonError(err)
}
req := request.MCPServerDebugRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
result, err := services.MCPDebugService.ListTools(context.Background(), req.ServerCode)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(response.BuildMCPToolInfoResponses(result))
}
func (c *MCPController) PostCall_tool() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionMCPCall); err != nil {
return web.JsonError(err)
}
req := request.MCPCallToolRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
result, err := services.MCPDebugService.CallTool(context.Background(), req.ServerCode, req.ToolName, req.Arguments)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(response.BuildMCPCallToolResponse(result))
}