(singleTenant bool)
| 690 | } |
| 691 | |
| 692 | func createEnvironmentFileEditTool(singleTenant bool) *Tool { |
| 693 | return &Tool{ |
| 694 | Definition: newEnvironmentTool( |
| 695 | envToolOptions{ |
| 696 | name: "environment_file_edit", |
| 697 | description: "Find and replace text in a file.", |
| 698 | useCurrentEnvironment: singleTenant, |
| 699 | }, |
| 700 | mcp.WithString("target_file", |
| 701 | mcp.Description("Path of the file to write, absolute or relative to the workdir."), |
| 702 | mcp.Required(), |
| 703 | ), |
| 704 | mcp.WithString("search_text", |
| 705 | mcp.Description("The text to find and replace."), |
| 706 | mcp.Required(), |
| 707 | ), |
| 708 | mcp.WithString("replace_text", |
| 709 | mcp.Description("The text to insert."), |
| 710 | mcp.Required(), |
| 711 | ), |
| 712 | mcp.WithString("which_match", |
| 713 | mcp.Description("The ID of the match to replace, if there were multiple matches."), |
| 714 | ), |
| 715 | ), |
| 716 | Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 717 | repo, env, err := openEnvironment(ctx, request) |
| 718 | if err != nil { |
| 719 | return mcp.NewToolResultErrorFromErr("unable to open the environment", err), nil |
| 720 | } |
| 721 | |
| 722 | targetFile, err := request.RequireString("target_file") |
| 723 | if err != nil { |
| 724 | return nil, err |
| 725 | } |
| 726 | search, err := request.RequireString("search_text") |
| 727 | if err != nil { |
| 728 | return nil, err |
| 729 | } |
| 730 | replace, err := request.RequireString("replace_text") |
| 731 | if err != nil { |
| 732 | return nil, err |
| 733 | } |
| 734 | |
| 735 | if err := env.FileEdit(ctx, |
| 736 | request.GetString("explanation", ""), |
| 737 | targetFile, |
| 738 | search, |
| 739 | replace, |
| 740 | request.GetString("which_match", ""), |
| 741 | ); err != nil { |
| 742 | return mcp.NewToolResultErrorFromErr("failed to write file", err), nil |
| 743 | } |
| 744 | |
| 745 | if err := repo.Update(ctx, env, request.GetString("explanation", "")); err != nil { |
| 746 | return mcp.NewToolResultErrorFromErr("unable to update the environment", err), nil |
| 747 | } |
| 748 | |
| 749 | return mcp.NewToolResultText(fmt.Sprintf("file %s edited successfully and committed to container-use/%s remote ref", targetFile, env.ID)), nil |
no test coverage detected