Skip to content

Commit 7ce442f

Browse files
committed
fix mcp tools
1 parent cf1792e commit 7ce442f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ export class AgentBlockHandler implements BlockHandler {
378378
if (ctx.workflowId) {
379379
params.workflowId = ctx.workflowId
380380
}
381+
if (ctx.userId) {
382+
params.userId = ctx.userId
383+
}
381384

382385
const url = buildAPIUrl('/api/tools/custom', params)
383386
const response = await fetch(url.toString(), {
@@ -488,7 +491,9 @@ export class AgentBlockHandler implements BlockHandler {
488491
usageControl: tool.usageControl || 'auto',
489492
executeFunction: async (callParams: Record<string, any>) => {
490493
const headers = await buildAuthHeaders()
491-
const execUrl = buildAPIUrl('/api/mcp/tools/execute')
494+
const execParams: Record<string, string> = {}
495+
if (ctx.userId) execParams.userId = ctx.userId
496+
const execUrl = buildAPIUrl('/api/mcp/tools/execute', execParams)
492497

493498
const execResponse = await fetch(execUrl.toString(), {
494499
method: 'POST',
@@ -597,6 +602,7 @@ export class AgentBlockHandler implements BlockHandler {
597602
serverId,
598603
workspaceId: ctx.workspaceId,
599604
workflowId: ctx.workflowId,
605+
...(ctx.userId ? { userId: ctx.userId } : {}),
600606
})
601607

602608
const maxAttempts = 2
@@ -671,7 +677,9 @@ export class AgentBlockHandler implements BlockHandler {
671677
usageControl: tool.usageControl || 'auto',
672678
executeFunction: async (callParams: Record<string, any>) => {
673679
const headers = await buildAuthHeaders()
674-
const execUrl = buildAPIUrl('/api/mcp/tools/execute')
680+
const discoverExecParams: Record<string, string> = {}
681+
if (ctx.userId) discoverExecParams.userId = ctx.userId
682+
const execUrl = buildAPIUrl('/api/mcp/tools/execute', discoverExecParams)
675683

676684
const execResponse = await fetch(execUrl.toString(), {
677685
method: 'POST',
@@ -1056,6 +1064,7 @@ export class AgentBlockHandler implements BlockHandler {
10561064
responseFormat: providerRequest.responseFormat,
10571065
workflowId: providerRequest.workflowId,
10581066
workspaceId: ctx.workspaceId,
1067+
userId: ctx.userId,
10591068
stream: providerRequest.stream,
10601069
messages: 'messages' in providerRequest ? providerRequest.messages : undefined,
10611070
environmentVariables: ctx.environmentVariables || {},

apps/sim/executor/handlers/evaluator/evaluator-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class EvaluatorBlockHandler implements BlockHandler {
104104
}
105105

106106
try {
107-
const url = buildAPIUrl('/api/providers')
107+
const url = buildAPIUrl('/api/providers', ctx.userId ? { userId: ctx.userId } : {})
108108

109109
const providerRequest: Record<string, any> = {
110110
provider: providerId,

apps/sim/executor/handlers/router/router-handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class RouterBlockHandler implements BlockHandler {
8080

8181
try {
8282
const url = new URL('/api/providers', getBaseUrl())
83+
if (ctx.userId) url.searchParams.set('userId', ctx.userId)
8384

8485
const messages = [{ role: 'user', content: routerConfig.prompt }]
8586
const systemPrompt = generateRouterPrompt(routerConfig.prompt, targetBlocks)
@@ -209,6 +210,7 @@ export class RouterBlockHandler implements BlockHandler {
209210

210211
try {
211212
const url = new URL('/api/providers', getBaseUrl())
213+
if (ctx.userId) url.searchParams.set('userId', ctx.userId)
212214

213215
const messages = [{ role: 'user', content: routerConfig.context }]
214216
const systemPrompt = generateRouterV2Prompt(routerConfig.context, routes)

apps/sim/tools/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ async function executeMcpTool(
961961

962962
const workspaceId = params._context?.workspaceId || executionContext?.workspaceId
963963
const workflowId = params._context?.workflowId || executionContext?.workflowId
964+
const userId = params._context?.userId || executionContext?.userId
964965

965966
if (!workspaceId) {
966967
return {
@@ -1002,7 +1003,12 @@ async function executeMcpTool(
10021003
hasToolSchema: !!toolSchema,
10031004
})
10041005

1005-
const response = await fetch(`${baseUrl}/api/mcp/tools/execute`, {
1006+
const mcpUrl = new URL('/api/mcp/tools/execute', baseUrl)
1007+
if (userId) {
1008+
mcpUrl.searchParams.set('userId', userId)
1009+
}
1010+
1011+
const response = await fetch(mcpUrl.toString(), {
10061012
method: 'POST',
10071013
headers,
10081014
body,

0 commit comments

Comments
 (0)