Skip to content

Commit ea7a148

Browse files
committed
fix(mcp): reset connectionStatus when a server is switched to OAuth
An authType flip to oauth (via a plain authType change or an implicit oauthClientId) cleared the cache but left connectionStatus='connected', so a server that had not completed its OAuth flow falsely read as connected and the OAuth-authorization-required prompt never showed. Reset to disconnected on any switch to oauth, matching the create path. Adds the missing test assertion.
1 parent 99e235a commit ea7a148

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

apps/sim/lib/mcp/orchestration/server-lifecycle.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ describe('MCP server lifecycle orchestration', () => {
8888

8989
expect(result.success).toBe(true)
9090
expect(dbChainMockFns.set).toHaveBeenCalledWith(expect.objectContaining({ authType: 'oauth' }))
91+
// Flipping to OAuth must reset the server to disconnected — it hasn't
92+
// completed an auth flow, so it can't remain 'connected'.
93+
expect(dbChainMockFns.set).toHaveBeenCalledWith(
94+
expect.objectContaining({ connectionStatus: 'disconnected', lastConnected: null })
95+
)
9196
expect(mockClearCache).toHaveBeenCalledWith('workspace-1')
9297
})
9398
})

apps/sim/lib/mcp/orchestration/server-lifecycle.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ export async function performUpdateMcpServer(
352352
const shouldClearOauth = urlChanged || credsChanged
353353
const resolvedAuthType = (updateData.authType ?? currentServer.authType) as McpAuthType
354354
const authTypeChanged = resolvedAuthType !== currentServer.authType
355-
if (shouldClearOauth && resolvedAuthType === 'oauth') {
355+
// Switching a server to OAuth (via creds/URL change or a plain authType flip)
356+
// must reset it to disconnected: an OAuth server has not completed its auth
357+
// flow, so it can't legitimately remain 'connected' (matches the create path).
358+
if ((shouldClearOauth || authTypeChanged) && resolvedAuthType === 'oauth') {
356359
updateData.connectionStatus = 'disconnected'
357360
updateData.lastConnected = null
358361
}

0 commit comments

Comments
 (0)