Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔗 feat: Support Environment Variables in MCP URL Config (#7424)

Ben Verheesf8cb0cdcda47
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<MCPOptions>, userId?: string): MCPOp
newObj.headers = processedHeaders;
}
+ if ('url' in newObj && newObj.url) {
+ newObj.url = extractEnvVariable(newObj.url);
+ }
+
return newObj;
}