From f8cb0cdcda470518454a719697be6b6ecfed516f Mon Sep 17 00:00:00 2001 From: Ben Verhees Date: Tue, 20 May 2025 01:37:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=97=20feat:=20Support=20Environment=20?= =?UTF-8?q?Variables=20in=20MCP=20URL=20Config=20(#7424)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data-provider/src/mcp.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/data-provider/src/mcp.ts b/packages/data-provider/src/mcp.ts index 8f406fd391..258eb15ae3 100644 --- a/packages/data-provider/src/mcp.ts +++ b/packages/data-provider/src/mcp.ts @@ -53,9 +53,10 @@ export const WebSocketOptionsSchema = BaseOptionsSchema.extend({ type: z.literal('websocket').optional(), url: z .string() - .url() + .transform((val: string) => extractEnvVariable(val)) + .pipe(z.string().url()) .refine( - (val) => { + (val: string) => { const protocol = new URL(val).protocol; return protocol === 'ws:' || protocol === 'wss:'; }, @@ -70,9 +71,10 @@ export const SSEOptionsSchema = BaseOptionsSchema.extend({ headers: z.record(z.string(), z.string()).optional(), url: z .string() - .url() + .transform((val: string) => extractEnvVariable(val)) + .pipe(z.string().url()) .refine( - (val) => { + (val: string) => { const protocol = new URL(val).protocol; return protocol !== 'ws:' && protocol !== 'wss:'; }, @@ -87,9 +89,10 @@ export const StreamableHTTPOptionsSchema = BaseOptionsSchema.extend({ headers: z.record(z.string(), z.string()).optional(), url: z .string() - .url() + .transform((val: string) => extractEnvVariable(val)) + .pipe(z.string().url()) .refine( - (val) => { + (val: string) => { const protocol = new URL(val).protocol; return protocol !== 'ws:' && protocol !== 'wss:'; }, @@ -141,5 +144,9 @@ export function processMCPEnv(obj: Readonly, userId?: string): MCPOp newObj.headers = processedHeaders; } + if ('url' in newObj && newObj.url) { + newObj.url = extractEnvVariable(newObj.url); + } + return newObj; }