Skip to content

Commit 9a47033

Browse files
committed
Update block
1 parent c086912 commit 9a47033

File tree

4 files changed

+320
-258
lines changed

4 files changed

+320
-258
lines changed

apps/sim/lib/copilot/orchestrator/tool-executor/deployment-tools/deploy.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@sim/db'
33
import { chat, workflowMcpTool } from '@sim/db/schema'
44
import { and, eq } from 'drizzle-orm'
55
import type { ExecutionContext, ToolCallResult } from '@/lib/copilot/orchestrator/types'
6+
import { getBaseUrl } from '@/lib/core/utils/urls'
67
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
78
import { deployWorkflow, undeployWorkflow } from '@/lib/workflows/persistence/utils'
89
import { checkChatAccess, checkWorkflowAccessForChatCreation } from '@/app/api/chat/utils'
@@ -38,13 +39,16 @@ export async function executeDeployApi(
3839
return { success: false, error: result.error || 'Failed to deploy workflow' }
3940
}
4041

42+
const baseUrl = getBaseUrl()
4143
return {
4244
success: true,
4345
output: {
4446
workflowId,
4547
isDeployed: true,
4648
deployedAt: result.deployedAt,
4749
version: result.version,
50+
apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`,
51+
baseUrl,
4852
},
4953
}
5054
} catch (error) {
@@ -177,9 +181,18 @@ export async function executeDeployChat(
177181
})
178182
}
179183

184+
const baseUrl = getBaseUrl()
180185
return {
181186
success: true,
182-
output: { success: true, action: 'deploy', isDeployed: true, identifier },
187+
output: {
188+
success: true,
189+
action: 'deploy',
190+
isDeployed: true,
191+
identifier,
192+
chatUrl: `${baseUrl}/chat/${identifier}`,
193+
apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`,
194+
baseUrl,
195+
},
183196
}
184197
} catch (error) {
185198
return { success: false, error: error instanceof Error ? error.message : String(error) }
@@ -234,6 +247,9 @@ export async function executeDeployMcp(
234247
`Execute ${workflowRecord.name} workflow`
235248
const parameterSchema = params.parameterSchema || {}
236249

250+
const baseUrl = getBaseUrl()
251+
const mcpServerUrl = `${baseUrl}/api/mcp/serve/${serverId}`
252+
237253
if (existingTool.length > 0) {
238254
const toolId = existingTool[0].id
239255
await db
@@ -245,7 +261,10 @@ export async function executeDeployMcp(
245261
updatedAt: new Date(),
246262
})
247263
.where(eq(workflowMcpTool.id, toolId))
248-
return { success: true, output: { toolId, toolName, toolDescription, updated: true } }
264+
return {
265+
success: true,
266+
output: { toolId, toolName, toolDescription, updated: true, mcpServerUrl, baseUrl },
267+
}
249268
}
250269

251270
const toolId = crypto.randomUUID()
@@ -260,7 +279,10 @@ export async function executeDeployMcp(
260279
updatedAt: new Date(),
261280
})
262281

263-
return { success: true, output: { toolId, toolName, toolDescription, updated: false } }
282+
return {
283+
success: true,
284+
output: { toolId, toolName, toolDescription, updated: false, mcpServerUrl, baseUrl },
285+
}
264286
} catch (error) {
265287
return { success: false, error: error instanceof Error ? error.message : String(error) }
266288
}
@@ -278,9 +300,16 @@ export async function executeRedeploy(context: ExecutionContext): Promise<ToolCa
278300
if (!result.success) {
279301
return { success: false, error: result.error || 'Failed to redeploy workflow' }
280302
}
303+
const baseUrl = getBaseUrl()
281304
return {
282305
success: true,
283-
output: { workflowId, deployedAt: result.deployedAt || null, version: result.version },
306+
output: {
307+
workflowId,
308+
deployedAt: result.deployedAt || null,
309+
version: result.version,
310+
apiEndpoint: `${baseUrl}/api/workflows/${workflowId}/run`,
311+
baseUrl,
312+
},
284313
}
285314
} catch (error) {
286315
return { success: false, error: error instanceof Error ? error.message : String(error) }

apps/sim/lib/copilot/orchestrator/tool-executor/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
} from '@/lib/copilot/orchestrator/types'
1111
import { routeExecution } from '@/lib/copilot/tools/server/router'
1212
import { env } from '@/lib/core/config/env'
13+
import { getBaseUrl } from '@/lib/core/utils/urls'
1314
import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
1415
import { getTool, resolveToolId } from '@/tools/utils'
1516
import {
@@ -134,6 +135,32 @@ const SIM_WORKFLOW_TOOL_HANDLERS: Record<
134135
executeListWorkspaceMcpServers(p as ListWorkspaceMcpServersParams, c),
135136
create_workspace_mcp_server: (p, c) =>
136137
executeCreateWorkspaceMcpServer(p as CreateWorkspaceMcpServerParams, c),
138+
oauth_get_auth_link: async (p, _c) => {
139+
const providerName = (p.providerName || p.provider_name || 'the provider') as string
140+
try {
141+
const baseUrl = getBaseUrl()
142+
const settingsUrl = `${baseUrl}/workspace`
143+
return {
144+
success: true,
145+
output: {
146+
message: `To connect ${providerName}, the user must authorize via their browser.`,
147+
oauth_url: settingsUrl,
148+
instructions: `Open ${settingsUrl} in a browser and go to the workflow editor to connect ${providerName} credentials.`,
149+
provider: providerName,
150+
baseUrl,
151+
},
152+
}
153+
} catch {
154+
return {
155+
success: true,
156+
output: {
157+
message: `To connect ${providerName}, the user must authorize via their browser.`,
158+
instructions: `Open the Sim workspace in a browser and go to the workflow editor to connect ${providerName} credentials.`,
159+
provider: providerName,
160+
},
161+
}
162+
}
163+
},
137164
}
138165

139166
/**

apps/sim/lib/copilot/tools/mcp/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Supports full and partial execution:
567567
name: 'sim_auth',
568568
agentId: 'auth',
569569
description:
570-
'Check OAuth connection status, list connected services, and initiate new OAuth connections. Use when a workflow needs third-party service access (Google, Slack, GitHub, etc.).',
570+
'Check OAuth connection status, list connected services, and initiate new OAuth connections. Use when a workflow needs third-party service access (Google, Slack, GitHub, etc.). In MCP/headless mode, returns an authorization URL the user must open in their browser to complete the OAuth flow.',
571571
inputSchema: {
572572
type: 'object',
573573
properties: {

0 commit comments

Comments
 (0)