Skip to content

Commit e098ef7

Browse files
authored
🔗 feat: Support Environment Variables in MCP URL Config (danny-avila#7424)
1 parent ff3b41f commit e098ef7

File tree

1 file changed

+13
-6
lines changed
  • packages/data-provider/src

1 file changed

+13
-6
lines changed

‎packages/data-provider/src/mcp.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ export const WebSocketOptionsSchema = BaseOptionsSchema.extend({
5353
type: z.literal('websocket').optional(),
5454
url: z
5555
.string()
56-
.url()
56+
.transform((val: string) => extractEnvVariable(val))
57+
.pipe(z.string().url())
5758
.refine(
58-
(val) => {
59+
(val: string) => {
5960
const protocol = new URL(val).protocol;
6061
return protocol === 'ws:' || protocol === 'wss:';
6162
},
@@ -70,9 +71,10 @@ export const SSEOptionsSchema = BaseOptionsSchema.extend({
7071
headers: z.record(z.string(), z.string()).optional(),
7172
url: z
7273
.string()
73-
.url()
74+
.transform((val: string) => extractEnvVariable(val))
75+
.pipe(z.string().url())
7476
.refine(
75-
(val) => {
77+
(val: string) => {
7678
const protocol = new URL(val).protocol;
7779
return protocol !== 'ws:' && protocol !== 'wss:';
7880
},
@@ -87,9 +89,10 @@ export const StreamableHTTPOptionsSchema = BaseOptionsSchema.extend({
8789
headers: z.record(z.string(), z.string()).optional(),
8890
url: z
8991
.string()
90-
.url()
92+
.transform((val: string) => extractEnvVariable(val))
93+
.pipe(z.string().url())
9194
.refine(
92-
(val) => {
95+
(val: string) => {
9396
const protocol = new URL(val).protocol;
9497
return protocol !== 'ws:' && protocol !== 'wss:';
9598
},
@@ -141,5 +144,9 @@ export function processMCPEnv(obj: Readonly<MCPOptions>, userId?: string): MCPOp
141144
newObj.headers = processedHeaders;
142145
}
143146

147+
if ('url' in newObj && newObj.url) {
148+
newObj.url = extractEnvVariable(newObj.url);
149+
}
150+
144151
return newObj;
145152
}

0 commit comments

Comments
 (0)