MCPcopy Index your code
hub / github.com/simstudioai/sim / getOrCreateOauthRow

Function getOrCreateOauthRow

apps/sim/lib/mcp/oauth/storage.ts:72–106  ·  view source on GitHub ↗
(params: {
  mcpServerId: string
  userId: string
  workspaceId: string
})

Source from the content-addressed store, hash-verified

70}
71
72export async function getOrCreateOauthRow(params: {
73 mcpServerId: string
74 userId: string
75 workspaceId: string
76}): Promise<McpOauthRow> {
77 const existing = await loadOauthRow(params)
78 if (existing) return existing
79
80 const id = generateId()
81 try {
82 await db.insert(mcpServerOauth).values({
83 id,
84 mcpServerId: params.mcpServerId,
85 userId: params.userId,
86 workspaceId: params.workspaceId,
87 })
88 } catch (error) {
89 const winner = await loadOauthRow(params)
90 if (winner) return winner
91 throw error
92 }
93
94 return {
95 id,
96 mcpServerId: params.mcpServerId,
97 userId: params.userId,
98 workspaceId: params.workspaceId,
99 clientInformation: null,
100 tokens: null,
101 codeVerifier: null,
102 state: null,
103 stateCreatedAt: null,
104 updatedAt: new Date(),
105 }
106}
107
108type RawOauthRow = typeof mcpServerOauth.$inferSelect
109

Callers 4

createClientMethod · 0.90
connectMethod · 0.90
storage.test.tsFile · 0.90
route.tsFile · 0.90

Calls 2

generateIdFunction · 0.90
loadOauthRowFunction · 0.85

Tested by

no test coverage detected