Skip to content

Commit 38ea9a4

Browse files
waleedlatif1claude
andcommitted
fix(mcp): allow clearing OAuth credentials in edit + filter deleted servers in callback
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 880a645 commit 38ea9a4

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

apps/sim/app/api/mcp/oauth/callback/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { db } from '@sim/db'
33
import { mcpServers } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
55
import { toError } from '@sim/utils/errors'
6-
import { eq } from 'drizzle-orm'
6+
import { and, eq, isNull } from 'drizzle-orm'
77
import type { NextRequest } from 'next/server'
88
import { NextResponse } from 'next/server'
99
import { getSession } from '@/lib/auth'
@@ -74,7 +74,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
7474
const [server] = await db
7575
.select({ id: mcpServers.id, url: mcpServers.url, workspaceId: mcpServers.workspaceId })
7676
.from(mcpServers)
77-
.where(eq(mcpServers.id, row.mcpServerId))
77+
.where(and(eq(mcpServers.id, row.mcpServerId), isNull(mcpServers.deletedAt)))
7878
.limit(1)
7979
if (!server || !server.url) {
8080
return htmlClose('Server no longer exists.', false)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export const PATCH = withRouteHandler(
6161
? (await encryptSecret(oauthClientSecret)).encrypted
6262
: null
6363
}
64+
if (updateData.oauthClientId !== undefined) {
65+
finalUpdateData.oauthClientId = updateData.oauthClientId || null
66+
}
6467

6568
if (updateData.url) {
6669
try {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,9 @@ export function McpServerFormModal({
536536
url: formData.url!,
537537
headers,
538538
timeout: formData.timeout || 30000,
539-
oauthClientId: oauthClientId || undefined,
540-
oauthClientSecret: oauthClientSecret || undefined,
539+
oauthClientId: mode === 'edit' ? (oauthClientId ?? '') : oauthClientId || undefined,
540+
oauthClientSecret:
541+
mode === 'edit' ? (oauthClientSecret ?? '') : oauthClientSecret || undefined,
541542
})
542543

543544
onOpenChange(false)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ export const createMcpServerBodySchema = z
135135
enabled: z.boolean().optional(),
136136
source: z.string().optional(),
137137
workspaceId: z.string().optional(),
138-
oauthClientId: z.string().optional(),
139-
oauthClientSecret: z.string().optional(),
138+
oauthClientId: z.string().nullable().optional(),
139+
oauthClientSecret: z.string().nullable().optional(),
140140
})
141141
.passthrough()
142142

0 commit comments

Comments
 (0)