Skip to content

Commit 5930f11

Browse files
authored
Chore/Add CUSTOM_MCP_PROTOCOL (#5003)
add CUSTOM_MCP_PROTOCOL
1 parent 8aa2507 commit 5930f11

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

packages/components/nodes/tools/MCP/CustomMCP/CustomMCP.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Tool } from '@langchain/core/tools'
22
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../../src/Interface'
3-
import { MCPToolkit, validateMCPServerSecurity } from '../core'
3+
import { MCPToolkit } from '../core'
44
import { getVars, prepareSandboxVars } from '../../../../src/utils'
55
import { DataSource } from 'typeorm'
66
import hash from 'object-hash'
@@ -173,13 +173,11 @@ class Custom_MCP implements INode {
173173
serverParams = JSON.parse(serverParamsString)
174174
}
175175

176-
if (process.env.CUSTOM_MCP_SECURITY_CHECK === 'true') {
177-
validateMCPServerSecurity(serverParams)
178-
}
179-
180176
// Compatible with stdio and SSE
181177
let toolkit: MCPToolkit
182-
if (serverParams?.command === undefined) {
178+
if (process.env.CUSTOM_MCP_PROTOCOL === 'sse') {
179+
toolkit = new MCPToolkit(serverParams, 'sse')
180+
} else if (serverParams?.command === undefined) {
183181
toolkit = new MCPToolkit(serverParams, 'sse')
184182
} else {
185183
toolkit = new MCPToolkit(serverParams, 'stdio')

packages/components/nodes/tools/MCP/core.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,32 +174,6 @@ function createSchemaModel(
174174
return z.object(schemaProperties)
175175
}
176176

177-
/**
178-
* TODO: To be removed and only allow Remote MCP for Cloud
179-
* Validates MCP server configuration to only allow whitelisted commands
180-
*/
181-
export function validateMCPServerSecurity(serverParams: Record<string, any>): void {
182-
// Whitelist of allowed commands - only these are permitted
183-
const allowedCommands = ['npx', 'node']
184-
185-
if (serverParams.command) {
186-
const cmd = serverParams.command.toLowerCase()
187-
const baseCmd = cmd
188-
189-
if (!allowedCommands.includes(baseCmd)) {
190-
throw new Error(`Only allowed: ${allowedCommands.join(', ')}`)
191-
}
192-
}
193-
194-
if (serverParams.env) {
195-
for (const [key, value] of Object.entries(serverParams.env)) {
196-
if (typeof value === 'string' && (value.includes('$(') || value.includes('`'))) {
197-
throw new Error(`Environment variable "${key}" contains command substitution: "${value}"`)
198-
}
199-
}
200-
}
201-
}
202-
203177
export const validateArgsForLocalFileAccess = (args: string[]): void => {
204178
const dangerousPatterns = [
205179
// Absolute paths

0 commit comments

Comments
 (0)