Skip to content

Commit 2224f93

Browse files
waleedlatif1claude
andcommitted
fix(mcp): pass workspaceId to OAuth start + preserve client secret on edit
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 38ea9a4 commit 2224f93

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/settings/components/mcp/components/mcp-server-form-modal/mcp-server-form-modal.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export function McpServerFormModal({
328328
const [headerScrollLeft, setHeaderScrollLeft] = useState<Record<string, number>>({})
329329

330330
const [showAdvanced, setShowAdvanced] = useState(false)
331+
const [oauthClientSecretTouched, setOauthClientSecretTouched] = useState(false)
331332

332333
const [prevOpen, setPrevOpen] = useState(false)
333334
if (open && !prevOpen) {
@@ -345,6 +346,7 @@ export function McpServerFormModal({
345346
setUrlScrollLeft(0)
346347
setHeaderScrollLeft({})
347348
setShowAdvanced(!!(data.oauthClientId || data.oauthClientSecret))
349+
setOauthClientSecretTouched(false)
348350
}
349351
if (open !== prevOpen) {
350352
setPrevOpen(open)
@@ -538,7 +540,11 @@ export function McpServerFormModal({
538540
timeout: formData.timeout || 30000,
539541
oauthClientId: mode === 'edit' ? (oauthClientId ?? '') : oauthClientId || undefined,
540542
oauthClientSecret:
541-
mode === 'edit' ? (oauthClientSecret ?? '') : oauthClientSecret || undefined,
543+
mode === 'edit'
544+
? oauthClientSecretTouched
545+
? (oauthClientSecret ?? '')
546+
: undefined
547+
: oauthClientSecret || undefined,
542548
})
543549

544550
onOpenChange(false)
@@ -549,7 +555,17 @@ export function McpServerFormModal({
549555
} finally {
550556
setIsSubmitting(false)
551557
}
552-
}, [formData, isFormValid, isDomainBlocked, testConnection, workspaceId, onSubmit, onOpenChange])
558+
}, [
559+
formData,
560+
isFormValid,
561+
isDomainBlocked,
562+
testConnection,
563+
workspaceId,
564+
onSubmit,
565+
onOpenChange,
566+
mode,
567+
oauthClientSecretTouched,
568+
])
553569

554570
const handleSubmitJson = useCallback(async () => {
555571
const config = parseJsonConfig(jsonInput)
@@ -735,6 +751,7 @@ export function McpServerFormModal({
735751
onChange={(e) => {
736752
if (testResult) clearTestResult()
737753
if (submitError) setSubmitError(null)
754+
setOauthClientSecretTouched(true)
738755
setFormData((prev) => ({ ...prev, oauthClientSecret: e.target.value }))
739756
}}
740757
className='h-9'

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ export function MCP({ initialServerId }: MCPProps) {
467467
onClick={async () => {
468468
setConnectingOauthServers((prev) => new Set(prev).add(server.id))
469469
try {
470-
await startOauthMutation.mutateAsync({ serverId: server.id })
470+
await startOauthMutation.mutateAsync({
471+
serverId: server.id,
472+
workspaceId,
473+
})
471474
} catch (e) {
472475
logger.error('Failed to start MCP OAuth', e)
473476
toast.error(

apps/sim/hooks/queries/mcp.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ export function useCreateMcpServer() {
179179
* `data.status === 'already_authorized'` means valid tokens already exist.
180180
*/
181181
export function useStartMcpOauth() {
182-
return useMutation<StartMcpOauthResult, Error, { serverId: string }>({
183-
mutationFn: async ({ serverId }) => {
184-
const result = await requestJson(startMcpOauthContract, { query: { serverId } })
182+
return useMutation<StartMcpOauthResult, Error, { serverId: string; workspaceId: string }>({
183+
mutationFn: async ({ serverId, workspaceId }) => {
184+
const result = await requestJson(startMcpOauthContract, {
185+
query: { serverId, workspaceId },
186+
})
185187
if (result.status === 'redirect') {
186188
const popup = window.open(
187189
result.authorizationUrl,

apps/sim/lib/api/contracts/mcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export const testMcpServerConnectionContract = defineRouteContract({
400400

401401
export const startMcpOauthQuerySchema = z.object({
402402
serverId: z.string().min(1, 'serverId is required'),
403+
workspaceId: z.string().min(1, 'workspaceId is required'),
403404
})
404405

405406
export const startMcpOauthResultSchema = z.discriminatedUnion('status', [

0 commit comments

Comments
 (0)