@@ -81,7 +81,7 @@ func (req CreateAndDeployFunctionRequest) ToSDK(
8181 Seconds : int64 (timeout .Seconds ()),
8282 },
8383 Description : & req .Description ,
84- Tags : setCreatedByTagIfAbsent (req .Tags ),
84+ Tags : setCreatedByTag (req .Tags ),
8585 EnvironmentVariables : & req .EnvironmentVariables ,
8686 SecretEnvironmentVariables : secrets ,
8787 MinScale : req .MinScale ,
@@ -90,6 +90,7 @@ func (req CreateAndDeployFunctionRequest) ToSDK(
9090 }, nil
9191}
9292
93+ //nolint:funlen
9394func (t * Tools ) CreateAndDeployFunction (
9495 ctx context.Context ,
9596 req * mcp.CallToolRequest ,
@@ -107,6 +108,8 @@ func (t *Tools) CreateAndDeployFunction(
107108 return nil , Function {}, fmt .Errorf ("converting to SDK request: %w" , err )
108109 }
109110
111+ // We always create the function first before zipping the code archive for
112+ // faster feedback to the user in case of errors.
110113 fun , err := t .functionsAPI .CreateFunction (createReq , scw .WithContext (ctx ))
111114 if err != nil {
112115 return nil , Function {}, fmt .Errorf ("creating function: %w" , err )
@@ -119,6 +122,23 @@ func (t *Tools) CreateAndDeployFunction(
119122 return nil , Function {}, fmt .Errorf ("creating archive: %w" , err )
120123 }
121124
125+ tags := setCodeArchiveDigestTag (fun .Tags , archive .Digest )
126+
127+ // However, as a side-effect of doing creation first, we need to
128+ // update the function to add the code archive digest tag (which helps
129+ // avoid redeploying the same code in future updates).
130+ fun , err = t .functionsAPI .UpdateFunction (& function.UpdateFunctionRequest {
131+ FunctionID : fun .ID ,
132+ Redeploy : scw .BoolPtr (false ),
133+ Tags : scw .StringsPtr (tags ),
134+ }, scw .WithContext (ctx ))
135+ if err != nil {
136+ return nil , Function {}, fmt .Errorf (
137+ "updating function with code archive digest tag: %w" ,
138+ err ,
139+ )
140+ }
141+
122142 presignedURLResp , err := t .functionsAPI .GetFunctionUploadURL (
123143 & function.GetFunctionUploadURLRequest {
124144 FunctionID : fun .ID ,
0 commit comments