@@ -166,8 +166,35 @@ export const POST = withRouteHandler(
166166 const oauthCredsChanged = clientIdChanged || clientSecretChanged
167167
168168 const isRevival = existingServer . deletedAt !== null
169- if ( urlChanged || oauthCredsChanged || isRevival ) {
170- await db . delete ( mcpServerOauth ) . where ( eq ( mcpServerOauth . mcpServerId , serverId ) )
169+ const shouldClearOauth = urlChanged || oauthCredsChanged || isRevival
170+
171+ await db . transaction ( async ( tx ) => {
172+ if ( shouldClearOauth ) {
173+ await tx . delete ( mcpServerOauth ) . where ( eq ( mcpServerOauth . mcpServerId , serverId ) )
174+ }
175+ await tx
176+ . update ( mcpServers )
177+ . set ( {
178+ name : body . name ,
179+ description : body . description ,
180+ transport : body . transport ,
181+ url : body . url ,
182+ authType : resolvedAuthType ,
183+ oauthClientId,
184+ oauthClientSecret : oauthClientSecretEncrypted ,
185+ headers : body . headers || { } ,
186+ timeout : body . timeout || 30000 ,
187+ retries : body . retries || 3 ,
188+ enabled : body . enabled !== false ,
189+ connectionStatus : resolvedAuthType === 'oauth' ? 'disconnected' : 'connected' ,
190+ lastConnected : resolvedAuthType === 'oauth' ? null : new Date ( ) ,
191+ updatedAt : new Date ( ) ,
192+ deletedAt : null ,
193+ } )
194+ . where ( eq ( mcpServers . id , serverId ) )
195+ } )
196+
197+ if ( shouldClearOauth ) {
171198 const reason = isRevival
172199 ? 'server revival'
173200 : urlChanged
@@ -178,27 +205,6 @@ export const POST = withRouteHandler(
178205 )
179206 }
180207
181- await db
182- . update ( mcpServers )
183- . set ( {
184- name : body . name ,
185- description : body . description ,
186- transport : body . transport ,
187- url : body . url ,
188- authType : resolvedAuthType ,
189- oauthClientId,
190- oauthClientSecret : oauthClientSecretEncrypted ,
191- headers : body . headers || { } ,
192- timeout : body . timeout || 30000 ,
193- retries : body . retries || 3 ,
194- enabled : body . enabled !== false ,
195- connectionStatus : resolvedAuthType === 'oauth' ? 'disconnected' : 'connected' ,
196- lastConnected : resolvedAuthType === 'oauth' ? null : new Date ( ) ,
197- updatedAt : new Date ( ) ,
198- deletedAt : null ,
199- } )
200- . where ( eq ( mcpServers . id , serverId ) )
201-
202208 await mcpService . clearCache ( workspaceId )
203209
204210 logger . info (
0 commit comments