config_history.go 827 B

123456789101112131415161718192021222324252627282930
  1. package config
  2. import (
  3. "context"
  4. "encoding/json"
  5. "github.com/0xJacky/Nginx-UI/query"
  6. "github.com/mark3labs/mcp-go/mcp"
  7. )
  8. const nginxConfigHistoryToolName = "nginx_config_history"
  9. var nginxConfigHistoryTool = mcp.NewTool(
  10. nginxConfigHistoryToolName,
  11. mcp.WithDescription("Get history of Nginx configuration changes"),
  12. mcp.WithString("filepath", mcp.Description("The file path to get history for")),
  13. )
  14. func handleNginxConfigHistory(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
  15. filepath := request.Params.Arguments["filepath"].(string)
  16. q := query.ConfigBackup
  17. var histories, err = q.Where(q.FilePath.Eq(filepath)).Order(q.ID.Desc()).Find()
  18. if err != nil {
  19. return nil, err
  20. }
  21. jsonResult, _ := json.Marshal(histories)
  22. return mcp.NewToolResultText(string(jsonResult)), nil
  23. }