Skip to content

Commit c0212e5

Browse files
committed
Address PR review feedback (#5754)
- Preserve OAuth-pending state when a status reread is stale - Keep concrete refresh errors sanitized and visible
1 parent 75bb19c commit c0212e5

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ describe('MCP server refresh route', () => {
116116
)
117117
})
118118

119+
it('preserves OAuth pending when the status reread is still stale connected', async () => {
120+
mockDiscoverServerTools.mockRejectedValueOnce(
121+
new McpOauthAuthorizationRequiredError('server-1', 'OAuth Server')
122+
)
123+
mockSelect.mockReturnValueOnce(selectRows([initialServer]))
124+
125+
const request = new Request('http://localhost/api/mcp/servers/server-1/refresh', {
126+
method: 'POST',
127+
}) as NextRequest
128+
const response = await POST(request, { params: Promise.resolve({ id: 'server-1' }) })
129+
const body = await response.json()
130+
131+
expect(body.data).toEqual(
132+
expect.objectContaining({
133+
status: 'disconnected',
134+
error: null,
135+
toolCount: 0,
136+
workflowsUpdated: 0,
137+
})
138+
)
139+
})
140+
119141
it('reports a sanitized discovery timeout when persistence leaves disconnected without an error', async () => {
120142
mockDiscoverServerTools.mockRejectedValueOnce(new Error('upstream request timeout'))
121143

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export const POST = withRouteHandler(
289289

290290
if (!newerSuccessWonRace) {
291291
connectionStatus = 'disconnected'
292-
lastError = discoveryError
292+
lastError = oauthAuthorizationRequired ? null : discoveryError
293293
toolCount = 0
294294
}
295295
} else if (

0 commit comments

Comments
 (0)