feat: import mcp server support env#8344
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
| } | ||
| try { | ||
| loading.value = true; | ||
| mcpServer.value.baseUrl = mcpServer.value.protocol + mcpServer.value.url; |
There was a problem hiding this comment.
The changes you provided look generally reasonable but can be optimized and corrected in a few areas:
Optimizations:
- Refactoring Logic: Some of the logic within the
acceptParamsfunction could be simplified. - Error Handling Consistency: Ensuring consistent error handling throughout the functions.
Corrections:
- Variable Initialization: Ensure that all variables used outside their scope are properly initialized (e.g.,
hasWebsite.value = false;). - Type Annotations: It's a good practice to type annotations for clarity, e.g., using TypeScript or Flow types.
Here is an improved version with these considerations:
const rules = ref<Record<string, Rule[]>>({
name: [Rules.requiredInput],
protocol: [Rules.requiredInput],
url: [Rules.requiredInput],
});
const hasWebsite = ref(false);
const acceptParams = async (params: AI.McpServer) => {
// Simplify initializing mode based on presence of params.id
const isNewServer = !params.id;
mode.value = isNewServer ? 'create' : 'edit';
if (!isNewServer && !mcpServer.value.name || !mcpServer.value.protocol || !mcpServer.value.url) {
msgError("All required fields must be filled out.");
return;
}
try {
if (isNewServer) {
mcpServer.value.name = '';
}
loadMcpServers(); // Assuming this fetches server data
if (mode.value === 'edit') {
mcpServer.value = { ...mcpServer.value, id: params.id };
}
mcpServer.value.mode = mode.value;
if (mode.value === 'new') {
saveMcpServer(mcpServer.value); // Assuming this saves new server data
} else {
updateMcpServer(params.id, mcpServer.value); // Assuming this updates existing server data
}
closeModal();
} catch (error) {
msgError(error);
}
};
const submit = async (formEl: FormInstance | undefined) => {
let valid = await formEl?.validate(async () => {
if (formEl && !formEl.valid) {
return Promise.reject(new Error());
}
if (!hasWebsite.value) {
await ElMessageBox.confirm(i18n.global.t('app.installWarn'), i18n.global.t('app.checkTitle'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
}).catch(() => {
throw new Error();
});
}
return true;
});
if (!valid) {
return;
}
try {
loading.value = true;
mcpServer.value.baseUrl = `${mcpServer.value.protocol}${mcpServer.value.url}`;
if (mode.value === 'create') {
createNewServer(mcpServer.value).then(() => closeModal()); // Assuming this creates a new server instance
} else if (mode.value === 'update') {
updateExistingServer(mcpServer.value.id, mcpServer.value).then(closeModal); // Assuming this updates an existing server instance
}
loading.value = false;
} catch (error) {
msgError(error);
}
};Key Changes Made:
- Mode Initialization: Introduced
isNewServervariable to simplify checking if it's a new server. - Validation and Submission Errors: Added validation checks before showing confirmation dialogs for submitting forms.
- Function Calls: Clarified which methods like
saveMcpServer, etc., should be called (loadMcpServers,saveMcpServer, ...) - Code Clarity: Minor improvements to make the code easier to read and understand.
These optimizations help improve maintainability and readability without introducing unnecessary changes.
| environments: config.env ? Object.entries(config.env).map(([key, value]) => ({ key, value })) : [], | ||
| ssePath: '/' + name, | ||
| containerName: name, | ||
| })); |
There was a problem hiding this comment.
There is no apparent issue with this code. However, one small suggestion could be to make the object entries more explicit:
const onConfirm = async () => {
mcpServerConfig.value = Object.entries(data.mcpServers).map(([name, config]) => ({
name,
command: [config.command, ...config.args].join(' '),
environments: config.env ?
{ // Explicitly specify that it's an object containing key-value pairs
...(Object.entries(config.env))
}.envs : [], // Assuming `config.env` might have property `.env`
ssePath: '/' + name,
containerName: name,
}));
};This way, you're making clear what kind of objects we expect to encounter within config.env.
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



No description provided.