Skip to content

feat: import mcp server support env#8344

Merged
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@mcp
Apr 8, 2025
Merged

feat: import mcp server support env#8344
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@mcp

Conversation

@zhengkunwang223
Copy link
Copy Markdown
Member

No description provided.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

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.

Details

Instructions 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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2025

}
try {
loading.value = true;
mcpServer.value.baseUrl = mcpServer.value.protocol + mcpServer.value.url;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes you provided look generally reasonable but can be optimized and corrected in a few areas:

Optimizations:

  1. Refactoring Logic: Some of the logic within the acceptParams function could be simplified.
  2. Error Handling Consistency: Ensuring consistent error handling throughout the functions.

Corrections:

  1. Variable Initialization: Ensure that all variables used outside their scope are properly initialized (e.g., hasWebsite.value = false;).
  2. 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:

  1. Mode Initialization: Introduced isNewServer variable to simplify checking if it's a new server.
  2. Validation and Submission Errors: Added validation checks before showing confirmation dialogs for submitting forms.
  3. Function Calls: Clarified which methods like saveMcpServer, etc., should be called (loadMcpServers, saveMcpServer, ...)
  4. 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,
}));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Copy Markdown
Member

/approve

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot added the approved label Apr 8, 2025
@f2c-ci-robot f2c-ci-robot Bot merged commit 8196c11 into dev Apr 8, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev@mcp branch April 8, 2025 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants