@@ -6,7 +6,7 @@ import { toError } from '@sim/utils/errors'
66import { and , eq , isNull } from 'drizzle-orm'
77import type { NextRequest } from 'next/server'
88import { updateMcpServerBodySchema } from '@/lib/api/contracts/mcp'
9- import { encryptSecret } from '@/lib/core/security/encryption'
9+ import { decryptSecret , encryptSecret } from '@/lib/core/security/encryption'
1010import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1111import {
1212 McpDnsResolutionError ,
@@ -140,11 +140,18 @@ export const PATCH = withRouteHandler(
140140 const urlChanged = body . url !== undefined && currentServer ?. url !== body . url
141141 const clientIdChanged =
142142 body . oauthClientId !== undefined && currentServer ?. oauthClientId !== body . oauthClientId
143- const clientSecretChanged =
144- oauthClientSecret !== undefined &&
145- ( oauthClientSecret
146- ? finalUpdateData . oauthClientSecret !== currentServer ?. oauthClientSecret
147- : currentServer ?. oauthClientSecret !== null )
143+ let clientSecretChanged = false
144+ if ( oauthClientSecret !== undefined ) {
145+ if ( ! oauthClientSecret ) {
146+ clientSecretChanged = currentServer ?. oauthClientSecret != null
147+ } else if ( ! currentServer ?. oauthClientSecret ) {
148+ clientSecretChanged = true
149+ } else {
150+ const currentPlaintext = ( await decryptSecret ( currentServer . oauthClientSecret ) )
151+ . decrypted
152+ clientSecretChanged = currentPlaintext !== oauthClientSecret
153+ }
154+ }
148155 const oauthCredsChanged = clientIdChanged || clientSecretChanged
149156
150157 if ( urlChanged || oauthCredsChanged ) {
0 commit comments