Skip to content

Commit f96119f

Browse files
waleedlatif1claude
andcommitted
chore(mcp): cleanup pass; unique OAuth popup name per server
- use mcp-oauth-${serverId} window target so concurrent OAuth flows on different servers don't reuse and clobber the same popup - drop redundant setQueryData before invalidate in useForceRefreshMcpTools - replace hardcoded text-red-500 with text-[var(--text-error)] token - normalize Plus icon to default h-[14px] w-[14px] - drop useMemo on cheap toolsByServer/selectedServer derivations Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 155afe2 commit f96119f

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

  • apps/sim
    • app/workspace/[workspaceId]/settings/components/mcp
    • hooks/queries

apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useEffect, useMemo, useRef, useState } from 'react'
3+
import { useEffect, useRef, useState } from 'react'
44
import { createLogger } from '@sim/logger'
55
import { toError } from '@sim/utils/errors'
66
import { useQueryClient } from '@tanstack/react-query'
@@ -105,7 +105,10 @@ function ServerListItem({
105105
<span className='text-[var(--text-secondary)] text-sm'>({transportLabel})</span>
106106
</div>
107107
<p
108-
className={`truncate text-sm ${isError ? 'text-red-500 dark:text-red-400' : 'text-[var(--text-muted)]'}`}
108+
className={cn(
109+
'truncate text-sm',
110+
isError ? 'text-[var(--text-error)]' : 'text-[var(--text-muted)]'
111+
)}
109112
>
110113
{isRefreshing
111114
? 'Refreshing...'
@@ -300,19 +303,17 @@ export function MCP({ initialServerId }: MCPProps) {
300303
}
301304
}
302305

303-
const toolsByServer = useMemo(() => {
304-
return (mcpToolsData || []).reduce(
305-
(acc, tool) => {
306-
if (!tool?.serverId) return acc
307-
if (!acc[tool.serverId]) {
308-
acc[tool.serverId] = []
309-
}
310-
acc[tool.serverId].push(tool)
311-
return acc
312-
},
313-
{} as Record<string, typeof mcpToolsData>
314-
)
315-
}, [mcpToolsData])
306+
const toolsByServer = (mcpToolsData || []).reduce(
307+
(acc, tool) => {
308+
if (!tool?.serverId) return acc
309+
if (!acc[tool.serverId]) {
310+
acc[tool.serverId] = []
311+
}
312+
acc[tool.serverId].push(tool)
313+
return acc
314+
},
315+
{} as Record<string, typeof mcpToolsData>
316+
)
316317

317318
const filteredServers = (servers || []).filter((server) =>
318319
server.name?.toLowerCase().includes(searchTerm.toLowerCase())
@@ -413,13 +414,13 @@ export function MCP({ initialServerId }: MCPProps) {
413414
setShowEditModal(true)
414415
}
415416

416-
const selectedServer = useMemo(() => {
417+
const selectedServer = (() => {
417418
if (!selectedServerId) return null
418419
const server = servers.find((s) => s.id === selectedServerId) as McpServer | undefined
419420
if (!server) return null
420421
const serverTools = (toolsByServer[selectedServerId] || []) as McpTool[]
421422
return { server, tools: serverTools }
422-
}, [selectedServerId, servers, toolsByServer])
423+
})()
423424

424425
const getStoredToolIssues = (
425426
serverId: string,
@@ -498,7 +499,7 @@ export function MCP({ initialServerId }: MCPProps) {
498499
{server.connectionStatus === 'error' && (
499500
<div className='flex flex-col gap-2'>
500501
<span className='font-medium text-[var(--text-primary)] text-sm'>Status</span>
501-
<p className='text-base text-red-500 dark:text-red-400'>
502+
<p className='text-[var(--text-error)] text-base'>
502503
{server.lastError || 'Unable to connect'}
503504
</p>
504505
</div>
@@ -716,7 +717,7 @@ export function MCP({ initialServerId }: MCPProps) {
716717
/>
717718
</div>
718719
<Button onClick={() => setShowAddModal(true)} variant='primary' disabled={serversLoading}>
719-
<Plus className='mr-1.5 h-[13px] w-[13px]' />
720+
<Plus className='mr-1.5 h-[14px] w-[14px]' />
720721
Add
721722
</Button>
722723
</div>

apps/sim/hooks/queries/mcp.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ export function useForceRefreshMcpTools() {
116116

117117
return useMutation({
118118
mutationFn: (workspaceId: string) => fetchMcpTools(workspaceId, true),
119-
onSettled: (tools, _error, workspaceId) => {
120-
if (tools) queryClient.setQueryData(mcpKeys.toolsList(workspaceId), tools)
119+
onSettled: (_data, _error, workspaceId) => {
121120
queryClient.invalidateQueries({ queryKey: mcpKeys.toolsList(workspaceId) })
122121
},
123122
})
@@ -194,7 +193,7 @@ export function useStartMcpOauth() {
194193
}
195194
const popup = window.open(
196195
result.authorizationUrl,
197-
'mcp-oauth',
196+
`mcp-oauth-${serverId}`,
198197
'width=560,height=720,resizable=yes,scrollbars=yes'
199198
)
200199
if (!popup) {

0 commit comments

Comments
 (0)