Skip to content

Commit c7b73cb

Browse files
Added optional override for URL (#185)
* Added optional override for URL * Lint fixes * Update nodes/McpClient/McpClient.node.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Added validation --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent d0bcfd9 commit c7b73cb

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

nodes/McpClient/McpClient.node.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ export class McpClient implements INodeType {
9090
default: 'cmd',
9191
description: 'Choose the transport type to connect to MCP server',
9292
},
93+
{
94+
displayName: 'Uri Override',
95+
name: 'uriOverride',
96+
type: 'string',
97+
displayOptions: {
98+
show: {
99+
connectionType: ['sse', 'http'],
100+
},
101+
},
102+
default: '',
103+
description: 'Override the URL from credentials with a custom URL',
104+
},
93105
{
94106
displayName: 'Operation',
95107
name: 'operation',
@@ -220,7 +232,21 @@ export class McpClient implements INodeType {
220232
// Dynamically import the HTTP client
221233
const { StreamableHTTPClientTransport } = await import('@modelcontextprotocol/sdk/client/streamableHttp.js');
222234

223-
const httpStreamUrl = httpCredentials.httpStreamUrl as string;
235+
// Get URI override or use credentials URL
236+
const uriOverride = this.getNodeParameter('uriOverride', 0) as string;
237+
let httpStreamUrl: string;
238+
239+
if (uriOverride && uriOverride.trim()) {
240+
try {
241+
// Validate URL format
242+
new URL(uriOverride.trim());
243+
httpStreamUrl = uriOverride.trim();
244+
} catch (error) {
245+
throw new NodeOperationError(this.getNode(), `Invalid URI override format: ${uriOverride}`);
246+
}
247+
} else {
248+
httpStreamUrl = httpCredentials.httpStreamUrl as string;
249+
}
224250
const messagesPostEndpoint = (httpCredentials.messagesPostEndpoint as string) || '';
225251
timeout = httpCredentials.httpTimeout as number || 60000;
226252

@@ -258,7 +284,20 @@ export class McpClient implements INodeType {
258284
// Dynamically import the SSE client to avoid TypeScript errors
259285
const { SSEClientTransport } = await import('@modelcontextprotocol/sdk/client/sse.js');
260286

261-
const sseUrl = sseCredentials.sseUrl as string;
287+
// Get URI override or use credentials URL
288+
const uriOverride = this.getNodeParameter('uriOverride', 0) as string;
289+
let sseUrl: string;
290+
if (uriOverride && uriOverride.trim()) {
291+
try {
292+
// Validate URL format
293+
new URL(uriOverride.trim());
294+
sseUrl = uriOverride.trim();
295+
} catch (error) {
296+
throw new NodeOperationError(this.getNode(), `Invalid URI override format: ${uriOverride}`);
297+
}
298+
} else {
299+
sseUrl = sseCredentials.sseUrl as string;
300+
}
262301
const messagesPostEndpoint = (sseCredentials.messagesPostEndpoint as string) || '';
263302
timeout = sseCredentials.sseTimeout as number || 60000;
264303

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n8n-nodes-mcp",
3-
"version": "0.1.29",
3+
"version": "0.1.30",
44
"description": "MCP nodes for n8n ",
55
"keywords": [
66
"n8n-community-node-package",

0 commit comments

Comments
 (0)