Skip to content

Commit 78cbbec

Browse files
waleedlatif1claude
andcommitted
fix(mcp): promote authType + clear OAuth tokens on credential change
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f587e82 commit 78cbbec

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

  • apps/sim/app/api/mcp/servers/[id]

apps/sim/app/api/mcp/servers/[id]/route.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ export const PATCH = withRouteHandler(
8585
}
8686
}
8787

88-
// Get the current server to check if URL is changing
88+
// Get the current server to check if URL or OAuth credentials are changing
8989
const [currentServer] = await db
90-
.select({ url: mcpServers.url })
90+
.select({
91+
url: mcpServers.url,
92+
authType: mcpServers.authType,
93+
oauthClientId: mcpServers.oauthClientId,
94+
oauthClientSecret: mcpServers.oauthClientSecret,
95+
})
9196
.from(mcpServers)
9297
.where(
9398
and(
@@ -98,6 +103,17 @@ export const PATCH = withRouteHandler(
98103
)
99104
.limit(1)
100105

106+
// Adding OAuth client credentials to a non-OAuth server promotes it
107+
// to OAuth so the connect-with-OAuth UI becomes reachable.
108+
if (
109+
body.oauthClientId &&
110+
currentServer &&
111+
currentServer.authType !== 'oauth' &&
112+
finalUpdateData.authType === undefined
113+
) {
114+
finalUpdateData.authType = 'oauth'
115+
}
116+
101117
const [updatedServer] = await db
102118
.update(mcpServers)
103119
.set({
@@ -122,16 +138,25 @@ export const PATCH = withRouteHandler(
122138
}
123139

124140
const urlChanged = body.url !== undefined && currentServer?.url !== body.url
125-
126-
if (urlChanged) {
141+
const clientIdChanged =
142+
body.oauthClientId !== undefined && currentServer?.oauthClientId !== body.oauthClientId
143+
const clientSecretChanged =
144+
oauthClientSecret !== undefined &&
145+
(oauthClientSecret
146+
? finalUpdateData.oauthClientSecret !== currentServer?.oauthClientSecret
147+
: currentServer?.oauthClientSecret !== null)
148+
const oauthCredsChanged = clientIdChanged || clientSecretChanged
149+
150+
if (urlChanged || oauthCredsChanged) {
127151
await db.delete(mcpServerOauth).where(eq(mcpServerOauth.mcpServerId, serverId))
128152
logger.info(
129-
`[${requestId}] Cleared OAuth credentials for server ${serverId} due to URL change`
153+
`[${requestId}] Cleared OAuth credentials for server ${serverId} due to ${urlChanged ? 'URL' : 'OAuth credential'} change`
130154
)
131155
}
132156

133157
const shouldClearCache =
134158
urlChanged ||
159+
oauthCredsChanged ||
135160
body.enabled !== undefined ||
136161
body.headers !== undefined ||
137162
body.timeout !== undefined ||

0 commit comments

Comments
 (0)