Skip to content

Commit 880a645

Browse files
waleedlatif1claude
andcommitted
fix(mcp): treat UnauthorizedError as disconnected in service discovery paths
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e2de153 commit 880a645

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

apps/sim/lib/mcp/service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* MCP Service - Clean stateless service for MCP operations
33
*/
44

5+
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
56
import { db } from '@sim/db'
67
import { mcpServers } from '@sim/db/schema'
78
import { createLogger } from '@sim/logger'
@@ -407,8 +408,11 @@ class McpService {
407408
result.value.tools.length
408409
)
409410
)
410-
} else if (result.reason instanceof McpOauthAuthorizationRequiredError) {
411-
// Pending user authorization — not a failure. Leave status as-is.
411+
} else if (
412+
result.reason instanceof McpOauthAuthorizationRequiredError ||
413+
result.reason instanceof UnauthorizedError
414+
) {
415+
// Pending user authorization or expired refresh — not a hard failure.
412416
logger.info(`[${requestId}] Skipping server ${server.name}: OAuth authorization pending`)
413417
} else {
414418
failedCount++
@@ -539,7 +543,10 @@ class McpService {
539543
error: undefined,
540544
})
541545
} catch (error) {
542-
if (error instanceof McpOauthAuthorizationRequiredError) {
546+
if (
547+
error instanceof McpOauthAuthorizationRequiredError ||
548+
error instanceof UnauthorizedError
549+
) {
543550
summaries.push({
544551
id: config.id,
545552
name: config.name,

0 commit comments

Comments
 (0)