Skip to content

Commit ccac764

Browse files
committed
cleanup & remove unused dep
1 parent cb243ff commit ccac764

12 files changed

Lines changed: 50 additions & 159 deletions

File tree

apps/sim/executor/consts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export enum BlockType {
1010
FUNCTION = 'function',
1111
AGENT = 'agent',
1212
API = 'api',
13-
MCP = 'mcp',
1413
EVALUATOR = 'evaluator',
1514
RESPONSE = 'response',
1615
WORKFLOW = 'workflow',

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

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ export class AgentBlockHandler implements BlockHandler {
8383
streaming: streamingConfig.shouldUseStreaming ?? false,
8484
})
8585

86-
this.logRequestDetails(providerRequest, messages, streamingConfig)
87-
8886
return this.executeProviderRequest(providerRequest, block, responseFormat, context)
8987
}
9088

@@ -153,16 +151,6 @@ export class AgentBlockHandler implements BlockHandler {
153151
private async formatTools(inputTools: ToolInput[], context: ExecutionContext): Promise<any[]> {
154152
if (!Array.isArray(inputTools)) return []
155153

156-
logger.info(`[AgentHandler] formatTools called with ${inputTools.length} tools`, {
157-
tools: inputTools.map((t) => ({
158-
type: t.type,
159-
usageControl: t.usageControl,
160-
params: t.params,
161-
})),
162-
hasWorkspaceId: !!context.workspaceId,
163-
workspaceId: context.workspaceId,
164-
})
165-
166154
const tools = await Promise.all(
167155
inputTools
168156
.filter((tool) => {
@@ -235,7 +223,7 @@ export class AgentBlockHandler implements BlockHandler {
235223
isCustomTool: true,
236224
_context: {
237225
workflowId: context.workflowId,
238-
workspaceId: context.workspaceId, // Include workspaceId for MCP tools
226+
workspaceId: context.workspaceId,
239227
},
240228
},
241229
false, // skipProxy
@@ -254,20 +242,16 @@ export class AgentBlockHandler implements BlockHandler {
254242
}
255243

256244
private async createMcpTool(tool: ToolInput, context: ExecutionContext): Promise<any> {
257-
// Extract MCP tool information from the tool input
258245
const { serverId, toolName, params } = tool.params || {}
259246

260247
if (!serverId || !toolName) {
261248
logger.error('MCP tool missing required parameters:', { serverId, toolName })
262249
return null
263250
}
264251

265-
// Fetch tool schema from MCP server via API
266252
try {
267-
// Prepare headers with internal authentication
268253
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
269254

270-
// Add internal authorization for server-side calls
271255
if (typeof window === 'undefined') {
272256
try {
273257
const { generateInternalToken } = await import('@/lib/auth/internal')
@@ -279,15 +263,13 @@ export class AgentBlockHandler implements BlockHandler {
279263
}
280264
}
281265

282-
// Add workspaceId and workflowId to the URL for workspace scoping (required by MCP API)
283266
const url = new URL(`${process.env.NEXT_PUBLIC_APP_URL}/api/mcp/tools/discover`)
284267
url.searchParams.set('serverId', serverId)
285268
if (context.workspaceId) {
286269
url.searchParams.set('workspaceId', context.workspaceId)
287270
} else {
288271
throw new Error('workspaceId is required for MCP tool discovery')
289272
}
290-
// Add workflowId for internal JWT authentication context
291273
if (context.workflowId) {
292274
url.searchParams.set('workflowId', context.workflowId)
293275
} else {
@@ -312,8 +294,6 @@ export class AgentBlockHandler implements BlockHandler {
312294
throw new Error(`MCP tool ${toolName} not found on server ${serverId}`)
313295
}
314296

315-
// Transform MCP tool schema to agent-compatible format
316-
// Don't double-prefix if serverId already starts with 'mcp-'
317297
const toolId = serverId.startsWith('mcp-')
318298
? `${serverId}-${toolName}`
319299
: `mcp-${serverId}-${toolName}`
@@ -327,10 +307,8 @@ export class AgentBlockHandler implements BlockHandler {
327307
executeFunction: async (callParams: Record<string, any>) => {
328308
logger.info(`Executing MCP tool ${toolName} on server ${serverId}`)
329309

330-
// Prepare headers with internal authentication
331310
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
332311

333-
// Add internal authorization for server-side calls
334312
if (typeof window === 'undefined') {
335313
try {
336314
const { generateInternalToken } = await import('@/lib/auth/internal')
@@ -342,7 +320,6 @@ export class AgentBlockHandler implements BlockHandler {
342320
}
343321
}
344322

345-
// Call MCP tool execution API
346323
const execResponse = await fetch(
347324
`${process.env.NEXT_PUBLIC_APP_URL}/api/mcp/tools/execute`,
348325
{
@@ -352,7 +329,7 @@ export class AgentBlockHandler implements BlockHandler {
352329
serverId,
353330
toolName,
354331
arguments: { ...params, ...callParams },
355-
workspaceId: context.workspaceId, // Pass workspace context for scoping
332+
workspaceId: context.workspaceId,
356333
}),
357334
}
358335
)
@@ -368,7 +345,6 @@ export class AgentBlockHandler implements BlockHandler {
368345
throw new Error(result.error || 'MCP tool execution failed')
369346
}
370347

371-
// Transform MCP result to standard tool output format
372348
return {
373349
success: true,
374350
output: result.data.output || {},
@@ -558,7 +534,7 @@ export class AgentBlockHandler implements BlockHandler {
558534
azureApiVersion: inputs.azureApiVersion,
559535
responseFormat,
560536
workflowId: context.workflowId,
561-
workspaceId: context.workspaceId, // Include workspaceId for MCP tools
537+
workspaceId: context.workspaceId,
562538
stream: streaming,
563539
messages,
564540
environmentVariables: context.environmentVariables || {},
@@ -586,12 +562,6 @@ export class AgentBlockHandler implements BlockHandler {
586562
)
587563
}
588564

589-
private logRequestDetails(
590-
providerRequest: any,
591-
messages: Message[] | undefined,
592-
_streamingConfig: StreamingConfig
593-
) {}
594-
595565
private async executeProviderRequest(
596566
providerRequest: any,
597567
block: SerializedBlock,
@@ -655,7 +625,7 @@ export class AgentBlockHandler implements BlockHandler {
655625
azureApiVersion: providerRequest.azureApiVersion,
656626
responseFormat: providerRequest.responseFormat,
657627
workflowId: providerRequest.workflowId,
658-
workspaceId: providerRequest.workspaceId, // Include workspaceId for MCP tools
628+
workspaceId: providerRequest.workspaceId,
659629
stream: providerRequest.stream,
660630
messages: 'messages' in providerRequest ? providerRequest.messages : undefined,
661631
environmentVariables: context.environmentVariables || {},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class ApiBlockHandler implements BlockHandler {
9999
...processedInputs,
100100
_context: {
101101
workflowId: context.workflowId,
102-
workspaceId: context.workspaceId, // Include workspaceId for MCP tools
102+
workspaceId: context.workspaceId,
103103
},
104104
},
105105
false, // skipProxy

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class FunctionBlockHandler implements BlockHandler {
6868
blockNameMapping: blockNameMapping, // Pass block name to ID mapping
6969
_context: {
7070
workflowId: context.workflowId,
71-
workspaceId: context.workspaceId, // Include workspaceId for MCP tools
71+
workspaceId: context.workspaceId,
7272
},
7373
},
7474
false, // skipProxy

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const logger = createLogger('GenericBlockHandler')
1313
*/
1414
export class GenericBlockHandler implements BlockHandler {
1515
canHandle(block: SerializedBlock): boolean {
16-
// This handler can handle any block type as a fallback
16+
// This handler can handle any block type
1717
// It should be the last handler checked.
1818
return true
1919
}
@@ -25,7 +25,7 @@ export class GenericBlockHandler implements BlockHandler {
2525
): Promise<any> {
2626
logger.info(`Executing block: ${block.id} (Type: ${block.metadata?.id})`)
2727

28-
// Handle MCP tools specially - they're not in the static tools registry
28+
// Handle MCP tools
2929
const isMcpTool = block.config.tool?.startsWith('mcp-')
3030
let tool = null
3131

@@ -45,7 +45,7 @@ export class GenericBlockHandler implements BlockHandler {
4545
const blockConfig = getBlock(blockType)
4646
if (blockConfig?.tools?.config?.params) {
4747
try {
48-
// Apply the block's parameter transformation function
48+
// Apply the block's parameter transformation
4949
const transformedParams = blockConfig.tools.config.params(inputs)
5050
finalInputs = { ...transformedParams }
5151
logger.info(`Applied parameter transformation for block type: ${blockType}`, {
@@ -56,7 +56,6 @@ export class GenericBlockHandler implements BlockHandler {
5656
logger.warn(`Failed to apply parameter transformation for block type ${blockType}:`, {
5757
error: error instanceof Error ? error.message : String(error),
5858
})
59-
// Continue with original inputs if transformation fails
6059
}
6160
}
6261
}
@@ -68,7 +67,7 @@ export class GenericBlockHandler implements BlockHandler {
6867
...finalInputs,
6968
_context: {
7069
workflowId: context.workflowId,
71-
workspaceId: context.workspaceId, // Include workspaceId for MCP tools
70+
workspaceId: context.workspaceId,
7271
},
7372
},
7473
false, // skipProxy
@@ -85,10 +84,8 @@ export class GenericBlockHandler implements BlockHandler {
8584
? errorDetails.join(' - ')
8685
: `Block execution of ${tool?.name || block.config.tool} failed with no error message`
8786

88-
// Create a detailed error object with formatted message
8987
const error = new Error(errorMessage)
9088

91-
// Add additional properties for debugging
9289
Object.assign(error, {
9390
toolId: block.config.tool,
9491
toolName: tool?.name || 'Unknown tool',
@@ -101,16 +98,13 @@ export class GenericBlockHandler implements BlockHandler {
10198
throw error
10299
}
103100

104-
// Extract cost information from tool response if available
105101
const output = result.output
106102
let cost = null
107103

108-
// Check if the tool is a knowledge tool and has cost information
109104
if (block.config.tool?.startsWith('knowledge_') && output?.cost) {
110105
cost = output.cost
111106
}
112107

113-
// Return the output with cost information if available
114108
if (cost) {
115109
return {
116110
...output,
@@ -126,25 +120,20 @@ export class GenericBlockHandler implements BlockHandler {
126120

127121
return output
128122
} catch (error: any) {
129-
// Ensure we have a meaningful error message
130123
if (!error.message || error.message === 'undefined (undefined)') {
131-
// Construct a detailed error message with available information
132124
let errorMessage = `Block execution of ${tool?.name || block.config.tool} failed`
133125

134-
// Add block name if available
135126
if (block.metadata?.name) {
136127
errorMessage += `: ${block.metadata.name}`
137128
}
138129

139-
// Add status code if available
140130
if (error.status) {
141131
errorMessage += ` (Status: ${error.status})`
142132
}
143133

144134
error.message = errorMessage
145135
}
146136

147-
// Add additional context to the error
148137
if (typeof error === 'object' && error !== null) {
149138
if (!error.toolId) error.toolId = block.config.tool
150139
if (!error.blockName) error.blockName = block.metadata?.name || 'Unnamed Block'

apps/sim/hooks/use-mcp-tools.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface McpToolForUI {
2323
type: 'mcp'
2424
inputSchema: any
2525
bgColor: string
26-
icon: React.ComponentType<any> // React component for MCP tools
26+
icon: React.ComponentType<any>
2727
}
2828

2929
export interface UseMcpToolsResult {
@@ -40,16 +40,15 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
4040
const [isLoading, setIsLoading] = useState(false)
4141
const [error, setError] = useState<string | null>(null)
4242

43-
// Subscribe to server changes to refresh tools when servers are modified
4443
const servers = useMcpServersStore((state) => state.servers)
4544

46-
// Track the last fingerprint we processed to prevent infinite loops
45+
// Track the last fingerprint
4746
const lastProcessedFingerprintRef = useRef<string>('')
4847

49-
// Create a stable server fingerprint to detect meaningful changes
48+
// Create a stable server fingerprint
5049
const serversFingerprint = useMemo(() => {
5150
return servers
52-
.filter((s) => s.enabled && !s.deletedAt) // Only consider active servers
51+
.filter((s) => s.enabled && !s.deletedAt)
5352
.map((s) => `${s.id}-${s.enabled}-${s.updatedAt}`)
5453
.sort()
5554
.join('|')
@@ -86,8 +85,8 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
8685
serverName: tool.serverName,
8786
type: 'mcp' as const,
8887
inputSchema: tool.inputSchema,
89-
bgColor: '#6366F1', // Indigo color to match MCP block
90-
icon: WrenchIcon, // Standard icon for MCP tools
88+
bgColor: '#6366F1',
89+
icon: WrenchIcon,
9190
}))
9291

9392
setMcpTools(transformedTools)
@@ -99,7 +98,7 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
9998
const errorMessage = err instanceof Error ? err.message : 'Failed to discover MCP tools'
10099
logger.error('Error discovering MCP tools:', err)
101100
setError(errorMessage)
102-
setMcpTools([]) // Clear tools on error
101+
setMcpTools([])
103102
} finally {
104103
setIsLoading(false)
105104
}
@@ -121,27 +120,24 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
121120
[mcpTools]
122121
)
123122

124-
// Initial load on mount
125123
useEffect(() => {
126124
refreshTools()
127-
}, []) // Remove refreshTools dependency
125+
}, [])
128126

129-
// Refresh tools when servers change (added/removed/updated)
127+
// Refresh tools when servers change
130128
useEffect(() => {
131-
// Skip if no active servers or we already processed this fingerprint
132129
if (!serversFingerprint || serversFingerprint === lastProcessedFingerprintRef.current) return
133130

134131
logger.info('Active servers changed, refreshing MCP tools', {
135132
serverCount: servers.filter((s) => s.enabled && !s.deletedAt).length,
136133
fingerprint: serversFingerprint,
137134
})
138135

139-
// Update the ref to track this fingerprint as processed
140136
lastProcessedFingerprintRef.current = serversFingerprint
141137
refreshTools()
142-
}, [serversFingerprint]) // Only watch for fingerprint changes
138+
}, [serversFingerprint])
143139

144-
// Auto-refresh every 5 minutes to keep tools up-to-date
140+
// Auto-refresh every 5 minutes
145141
useEffect(() => {
146142
const interval = setInterval(
147143
() => {
@@ -150,10 +146,10 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
150146
}
151147
},
152148
5 * 60 * 1000
153-
) // 5 minutes
149+
)
154150

155151
return () => clearInterval(interval)
156-
}, [isLoading]) // Remove refreshTools dependency
152+
}, [isLoading])
157153

158154
return {
159155
mcpTools,
@@ -165,12 +161,6 @@ export function useMcpTools(workspaceId: string): UseMcpToolsResult {
165161
}
166162
}
167163

168-
/**
169-
* Hook for executing MCP tools
170-
*
171-
* This provides a consistent interface for executing MCP tools
172-
* that matches the existing tool execution patterns
173-
*/
174164
export function useMcpToolExecution(workspaceId: string) {
175165
const executeTool = useCallback(
176166
async (serverId: string, toolName: string, args: Record<string, any>) => {
@@ -212,9 +202,3 @@ export function useMcpToolExecution(workspaceId: string) {
212202

213203
return { executeTool }
214204
}
215-
216-
/**
217-
* Hook for MCP server management
218-
*
219-
* Provides functions to manage MCP server connections
220-
*/

0 commit comments

Comments
 (0)