Skip to content

Commit 08fe845

Browse files
waleedlatif1claude
andcommitted
fix(mcp): strip secret from create mutation result, dedupe oauth row mapping
- useCreateMcpServer was returning the raw serverData (including plaintext oauthClientSecret) as mutation.data; strip the secret to match the equivalent fix applied to useUpdateMcpServer. - Extract the McpOauthRow mapping/decryption from loadOauthRow and loadOauthRowByState into a shared mapOauthRow helper. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8310051 commit 08fe845

2 files changed

Lines changed: 15 additions & 30 deletions

File tree

apps/sim/hooks/queries/mcp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ export function useCreateMcpServer() {
156156
: `Created MCP server: ${config.name} (ID: ${serverId})`
157157
)
158158

159+
const { oauthClientSecret: _omitSecret, ...safeServerData } = serverData
159160
return {
160-
...serverData,
161+
...safeServerData,
161162
id: serverId,
162163
connectionStatus: authType === 'oauth' ? ('disconnected' as const) : ('connected' as const),
163164
serverId,

apps/sim/lib/mcp/oauth/storage.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,9 @@ export async function getOrCreateOauthRow(params: {
101101
}
102102
}
103103

104-
export async function loadOauthRow(params: { mcpServerId: string }): Promise<McpOauthRow | null> {
105-
const [row] = await db
106-
.select()
107-
.from(mcpServerOauth)
108-
.where(eq(mcpServerOauth.mcpServerId, params.mcpServerId))
109-
.limit(1)
110-
if (!row) return null
104+
type RawOauthRow = typeof mcpServerOauth.$inferSelect
111105

106+
async function mapOauthRow(row: RawOauthRow): Promise<McpOauthRow> {
112107
return {
113108
id: row.id,
114109
mcpServerId: row.mcpServerId,
@@ -133,6 +128,16 @@ export async function loadOauthRow(params: { mcpServerId: string }): Promise<Mcp
133128
}
134129
}
135130

131+
export async function loadOauthRow(params: { mcpServerId: string }): Promise<McpOauthRow | null> {
132+
const [row] = await db
133+
.select()
134+
.from(mcpServerOauth)
135+
.where(eq(mcpServerOauth.mcpServerId, params.mcpServerId))
136+
.limit(1)
137+
if (!row) return null
138+
return mapOauthRow(row)
139+
}
140+
136141
export async function setOauthRowUser(rowId: string, userId: string): Promise<void> {
137142
await db
138143
.update(mcpServerOauth)
@@ -152,28 +157,7 @@ export async function loadOauthRowByState(state: string): Promise<McpOauthRow |
152157
)
153158
.limit(1)
154159
if (!row) return null
155-
return {
156-
id: row.id,
157-
mcpServerId: row.mcpServerId,
158-
userId: row.userId,
159-
workspaceId: row.workspaceId,
160-
clientInformation: row.clientInformation
161-
? await safeDecrypt(
162-
row.id,
163-
'clientInformation',
164-
row.clientInformation,
165-
(d) => JSON.parse(d) as OAuthClientInformationMixed
166-
)
167-
: null,
168-
tokens: row.tokens
169-
? await safeDecrypt(row.id, 'tokens', row.tokens, (d) => JSON.parse(d) as OAuthTokens)
170-
: null,
171-
codeVerifier: row.codeVerifier
172-
? await safeDecrypt(row.id, 'codeVerifier', row.codeVerifier, (d) => d)
173-
: null,
174-
state: row.state,
175-
updatedAt: row.updatedAt,
176-
}
160+
return mapOauthRow(row)
177161
}
178162

179163
export async function saveClientInformation(

0 commit comments

Comments
 (0)