Skip to content

Commit 8cb7f34

Browse files
authored
🚀 feat: Add Code API Proxy Support and Update MCP SDK (#6203)
* chore: bump mcp sdk * feat: Add proxy support for file download and upload in Code Environment CRUD operations * chore: remove unused files * chore: change output format from CommonJS to ES module in server rollup config
1 parent 780fdf7 commit 8cb7f34

File tree

6 files changed

+476
-133
lines changed

6 files changed

+476
-133
lines changed

api/server/services/Files/Code/crud.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Code Files
21
const axios = require('axios');
32
const FormData = require('form-data');
43
const { getCodeBaseURL } = require('@librechat/agents');
@@ -16,7 +15,8 @@ const MAX_FILE_SIZE = 150 * 1024 * 1024;
1615
async function getCodeOutputDownloadStream(fileIdentifier, apiKey) {
1716
try {
1817
const baseURL = getCodeBaseURL();
19-
const response = await axios({
18+
/** @type {import('axios').AxiosRequestConfig} */
19+
const options = {
2020
method: 'get',
2121
url: `${baseURL}/download/${fileIdentifier}`,
2222
responseType: 'stream',
@@ -25,10 +25,22 @@ async function getCodeOutputDownloadStream(fileIdentifier, apiKey) {
2525
'X-API-Key': apiKey,
2626
},
2727
timeout: 15000,
28-
});
28+
};
29+
30+
if (process.env.PROXY) {
31+
options.proxy = {
32+
host: process.env.PROXY,
33+
protocol: process.env.PROXY.startsWith('https') ? 'https' : 'http',
34+
};
35+
}
2936

37+
const response = await axios(options);
3038
return response;
3139
} catch (error) {
40+
logAxiosError({
41+
message: `Error downloading code environment file stream: ${error.message}`,
42+
error,
43+
});
3244
throw new Error(`Error downloading file: ${error.message}`);
3345
}
3446
}
@@ -54,7 +66,8 @@ async function uploadCodeEnvFile({ req, stream, filename, apiKey, entity_id = ''
5466
form.append('file', stream, filename);
5567

5668
const baseURL = getCodeBaseURL();
57-
const response = await axios.post(`${baseURL}/upload`, form, {
69+
/** @type {import('axios').AxiosRequestConfig} */
70+
const options = {
5871
headers: {
5972
...form.getHeaders(),
6073
'Content-Type': 'multipart/form-data',
@@ -64,7 +77,16 @@ async function uploadCodeEnvFile({ req, stream, filename, apiKey, entity_id = ''
6477
},
6578
maxContentLength: MAX_FILE_SIZE,
6679
maxBodyLength: MAX_FILE_SIZE,
67-
});
80+
};
81+
82+
if (process.env.PROXY) {
83+
options.proxy = {
84+
host: process.env.PROXY,
85+
protocol: process.env.PROXY.startsWith('https') ? 'https' : 'http',
86+
};
87+
}
88+
89+
const response = await axios.post(`${baseURL}/upload`, form, options);
6890

6991
/** @type {{ message: string; session_id: string; files: Array<{ fileId: string; filename: string }> }} */
7092
const result = response.data;

0 commit comments

Comments
 (0)