mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-07 05:05:15 -05:00
fix mcp tools
This commit is contained in:
@@ -378,6 +378,9 @@ export class AgentBlockHandler implements BlockHandler {
|
||||
if (ctx.workflowId) {
|
||||
params.workflowId = ctx.workflowId
|
||||
}
|
||||
if (ctx.userId) {
|
||||
params.userId = ctx.userId
|
||||
}
|
||||
|
||||
const url = buildAPIUrl('/api/tools/custom', params)
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -488,7 +491,9 @@ export class AgentBlockHandler implements BlockHandler {
|
||||
usageControl: tool.usageControl || 'auto',
|
||||
executeFunction: async (callParams: Record<string, any>) => {
|
||||
const headers = await buildAuthHeaders()
|
||||
const execUrl = buildAPIUrl('/api/mcp/tools/execute')
|
||||
const execParams: Record<string, string> = {}
|
||||
if (ctx.userId) execParams.userId = ctx.userId
|
||||
const execUrl = buildAPIUrl('/api/mcp/tools/execute', execParams)
|
||||
|
||||
const execResponse = await fetch(execUrl.toString(), {
|
||||
method: 'POST',
|
||||
@@ -597,6 +602,7 @@ export class AgentBlockHandler implements BlockHandler {
|
||||
serverId,
|
||||
workspaceId: ctx.workspaceId,
|
||||
workflowId: ctx.workflowId,
|
||||
...(ctx.userId ? { userId: ctx.userId } : {}),
|
||||
})
|
||||
|
||||
const maxAttempts = 2
|
||||
@@ -671,7 +677,9 @@ export class AgentBlockHandler implements BlockHandler {
|
||||
usageControl: tool.usageControl || 'auto',
|
||||
executeFunction: async (callParams: Record<string, any>) => {
|
||||
const headers = await buildAuthHeaders()
|
||||
const execUrl = buildAPIUrl('/api/mcp/tools/execute')
|
||||
const discoverExecParams: Record<string, string> = {}
|
||||
if (ctx.userId) discoverExecParams.userId = ctx.userId
|
||||
const execUrl = buildAPIUrl('/api/mcp/tools/execute', discoverExecParams)
|
||||
|
||||
const execResponse = await fetch(execUrl.toString(), {
|
||||
method: 'POST',
|
||||
@@ -1056,6 +1064,7 @@ export class AgentBlockHandler implements BlockHandler {
|
||||
responseFormat: providerRequest.responseFormat,
|
||||
workflowId: providerRequest.workflowId,
|
||||
workspaceId: ctx.workspaceId,
|
||||
userId: ctx.userId,
|
||||
stream: providerRequest.stream,
|
||||
messages: 'messages' in providerRequest ? providerRequest.messages : undefined,
|
||||
environmentVariables: ctx.environmentVariables || {},
|
||||
|
||||
@@ -104,7 +104,7 @@ export class EvaluatorBlockHandler implements BlockHandler {
|
||||
}
|
||||
|
||||
try {
|
||||
const url = buildAPIUrl('/api/providers')
|
||||
const url = buildAPIUrl('/api/providers', ctx.userId ? { userId: ctx.userId } : {})
|
||||
|
||||
const providerRequest: Record<string, any> = {
|
||||
provider: providerId,
|
||||
|
||||
@@ -80,6 +80,7 @@ export class RouterBlockHandler implements BlockHandler {
|
||||
|
||||
try {
|
||||
const url = new URL('/api/providers', getBaseUrl())
|
||||
if (ctx.userId) url.searchParams.set('userId', ctx.userId)
|
||||
|
||||
const messages = [{ role: 'user', content: routerConfig.prompt }]
|
||||
const systemPrompt = generateRouterPrompt(routerConfig.prompt, targetBlocks)
|
||||
@@ -209,6 +210,7 @@ export class RouterBlockHandler implements BlockHandler {
|
||||
|
||||
try {
|
||||
const url = new URL('/api/providers', getBaseUrl())
|
||||
if (ctx.userId) url.searchParams.set('userId', ctx.userId)
|
||||
|
||||
const messages = [{ role: 'user', content: routerConfig.context }]
|
||||
const systemPrompt = generateRouterV2Prompt(routerConfig.context, routes)
|
||||
|
||||
@@ -961,6 +961,7 @@ async function executeMcpTool(
|
||||
|
||||
const workspaceId = params._context?.workspaceId || executionContext?.workspaceId
|
||||
const workflowId = params._context?.workflowId || executionContext?.workflowId
|
||||
const userId = params._context?.userId || executionContext?.userId
|
||||
|
||||
if (!workspaceId) {
|
||||
return {
|
||||
@@ -1002,7 +1003,12 @@ async function executeMcpTool(
|
||||
hasToolSchema: !!toolSchema,
|
||||
})
|
||||
|
||||
const response = await fetch(`${baseUrl}/api/mcp/tools/execute`, {
|
||||
const mcpUrl = new URL('/api/mcp/tools/execute', baseUrl)
|
||||
if (userId) {
|
||||
mcpUrl.searchParams.set('userId', userId)
|
||||
}
|
||||
|
||||
const response = await fetch(mcpUrl.toString(), {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
|
||||
Reference in New Issue
Block a user