config_history.go 839 B

12345678910111213141516171819202122232425262728293031
  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. args := request.GetArguments()
  16. filepath := args["filepath"].(string)
  17. q := query.ConfigBackup
  18. var histories, err = q.Where(q.FilePath.Eq(filepath)).Order(q.ID.Desc()).Find()
  19. if err != nil {
  20. return nil, err
  21. }
  22. jsonResult, _ := json.Marshal(histories)
  23. return mcp.NewToolResultText(string(jsonResult)), nil
  24. }