(singleTenant bool)
| 752 | } |
| 753 | |
| 754 | func createEnvironmentFileWriteTool(singleTenant bool) *Tool { |
| 755 | return &Tool{ |
| 756 | Definition: newEnvironmentTool( |
| 757 | envToolOptions{ |
| 758 | name: "environment_file_write", |
| 759 | description: "Write the contents of a file.", |
| 760 | useCurrentEnvironment: singleTenant, |
| 761 | }, |
| 762 | mcp.WithString("target_file", |
| 763 | mcp.Description("Path of the file to write, absolute or relative to the workdir."), |
| 764 | mcp.Required(), |
| 765 | ), |
| 766 | mcp.WithString("contents", |
| 767 | mcp.Description("Full text content of the file you want to write."), |
| 768 | mcp.Required(), |
| 769 | ), |
| 770 | ), |
| 771 | Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 772 | repo, env, err := openEnvironment(ctx, request) |
| 773 | if err != nil { |
| 774 | return nil, err |
| 775 | } |
| 776 | |
| 777 | targetFile, err := request.RequireString("target_file") |
| 778 | if err != nil { |
| 779 | return nil, err |
| 780 | } |
| 781 | contents, err := request.RequireString("contents") |
| 782 | if err != nil { |
| 783 | return nil, err |
| 784 | } |
| 785 | |
| 786 | if err := env.FileWrite(ctx, request.GetString("explanation", ""), targetFile, contents); err != nil { |
| 787 | return nil, fmt.Errorf("failed to write file: %w", err) |
| 788 | } |
| 789 | |
| 790 | if err := repo.Update(ctx, env, request.GetString("explanation", "")); err != nil { |
| 791 | return nil, fmt.Errorf("unable to update the environment: %w", err) |
| 792 | } |
| 793 | |
| 794 | return mcp.NewToolResultText(fmt.Sprintf("file %s written successfully and committed to container-use/%s remote ref", targetFile, env.ID)), nil |
| 795 | }, |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | func createEnvironmentFileDeleteTool(singleTenant bool) *Tool { |
| 800 | return &Tool{ |
no test coverage detected