Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/nodes/agentflow/Agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ class Agent_Agentflow implements INode {
}
const componentNode = options.componentNodes[agentSelectedTool]

const jsonSchema = zodToJsonSchema(tool.schema as any)
const jsonSchema: any = (tool.schema as any)?._def ? zodToJsonSchema(tool.schema as any) : { ...(tool.schema as any) }
if (jsonSchema.$schema) {
delete jsonSchema.$schema
}
Expand Down
12 changes: 10 additions & 2 deletions packages/components/nodes/agentflow/Tool/Tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,23 @@ class Tool_Agentflow implements INode {
// Combine schemas from all tools in the array
const allProperties = toolInstance.reduce((acc, tool) => {
if (tool?.schema) {
const schema: Record<string, any> = zodToJsonSchema(tool.schema)
const schema: Record<string, any> = (tool.schema as any)?._def
? zodToJsonSchema(tool.schema)
: { ...(tool.schema as any) }
return { ...acc, ...(schema.properties || {}) }
}
return acc
}, {})
toolInputArgs = { properties: allProperties }
} else {
// Handle single tool instance
toolInputArgs = toolInstance.schema ? zodToJsonSchema(toolInstance.schema as any) : {}
if (!toolInstance.schema) {
toolInputArgs = {}
} else if ((toolInstance.schema as any)?._def) {
toolInputArgs = zodToJsonSchema(toolInstance.schema as any)
} else {
toolInputArgs = { ...(toolInstance.schema as any) }
}
}

if (toolInputArgs && Object.keys(toolInputArgs).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ interface JSONSchema {
}

const formatToOpenAIAssistantTool = (tool: any): OpenAI.Beta.FunctionTool => {
const parameters = zodToJsonSchema(tool.schema) as JSONSchema
const parameters = (tool.schema?._def ? zodToJsonSchema(tool.schema) : { ...tool.schema }) as JSONSchema
Comment thread
HenryHengZJ marked this conversation as resolved.
Outdated

// For strict tools, we need to:
// 1. Set additionalProperties to false
Expand Down
14 changes: 1 addition & 13 deletions packages/components/nodes/tools/MCP/Pipedream/PipedreamMCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getCredentialData, getCredentialParam, getVars, prepareSandboxVars } fr
import { DataSource } from 'typeorm'
import { MCPToolkit } from '../core'
import axios from 'axios'
import { z, ZodTypeAny } from 'zod'
import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js'
import type { CallToolRequest, CallToolResult, TextContent, Tool as McpTool } from '@modelcontextprotocol/sdk/types.js'

Expand Down Expand Up @@ -40,17 +39,6 @@ Once the user has connected their account, retry the original request.`
return text
}

function createSchemaModel(inputSchema: { type: string; properties?: Record<string, any> }): z.ZodObject<any> {
if (inputSchema.type !== 'object' || !inputSchema.properties) {
throw new Error('Invalid schema type or missing properties')
}
const schemaProperties = Object.entries(inputSchema.properties).reduce((acc, [key]) => {
acc[key] = z.any()
return acc
}, {} as Record<string, ZodTypeAny>)
return z.object(schemaProperties)
}

async function createPipedreamTool(toolkit: MCPToolkit, name: string, description: string, argsSchema: any): Promise<Tool> {
return tool(
async (input): Promise<string> => {
Expand Down Expand Up @@ -345,7 +333,7 @@ class Pipedream_MCP implements INode {
}

const toolPromises = rawTools.map((t: McpTool) =>
createPipedreamTool(toolkit, t.name, t.description || t.name, createSchemaModel(t.inputSchema))
createPipedreamTool(toolkit, t.name, t.description || t.name, t.inputSchema ?? { type: 'object', properties: {} })
)
const settled = await Promise.allSettled(toolPromises)
const tools = settled.filter((r): r is PromiseFulfilledResult<Tool> => r.status === 'fulfilled').map((r) => r.value)
Expand Down
22 changes: 2 additions & 20 deletions packages/components/nodes/tools/MCP/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CallToolRequest, CallToolResultSchema, ListToolsResult, ListToolsResult
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
import { StdioClientTransport, StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js'
import { BaseToolkit, tool, Tool } from '@langchain/core/tools'
import { z, type ZodTypeAny } from 'zod/v3'
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
import { checkDenyList, secureFetch } from '../../../src/httpSecurity'
Expand Down Expand Up @@ -124,11 +123,12 @@ export class MCPToolkit extends BaseToolkit {
if (this.client === null) {
throw new Error('Client is not initialized')
}
const argsSchema = tool.inputSchema ?? { type: 'object', properties: {} }
return await MCPTool({
toolkit: this,
name: tool.name,
description: tool.description || tool.name,
argsSchema: createSchemaModel(tool.inputSchema)
argsSchema
})
})
const res = await Promise.allSettled(toolsPromises)
Expand Down Expand Up @@ -177,24 +177,6 @@ export async function MCPTool({
)
}

function createSchemaModel(
inputSchema: {
type: 'object'
properties?: Record<string, unknown>
} & { [k: string]: unknown }
): z.ZodObject<Record<string, ZodTypeAny>> {
if (inputSchema.type !== 'object' || !inputSchema.properties) {
throw new Error('Invalid schema type or missing properties')
}

const schemaProperties = Object.entries(inputSchema.properties).reduce((acc, [key]) => {
acc[key] = z.any()
return acc
}, {} as Record<string, ZodTypeAny>)

return z.object(schemaProperties)
}

export const validateArgsForLocalFileAccess = (args: string[]): void => {
const dangerousPatterns = [
// Absolute paths
Expand Down
Loading