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

This commit is contained in:
Ben Verhees 2025-05-20 01:37:21 +02:00 committed by GitHub
parent 55d52d07f2
commit f8cb0cdcda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}