feat: add config for mcp server#8331
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. |
|
| defineExpose({ | ||
| acceptParams, | ||
| }); | ||
| </script> |
There was a problem hiding this comment.
There are no syntax errors in the code snippet you provided. Here is a simplified version of it with slight modifications and comments for clarity:
<template>
<!-- Drawer component -->
<el-drawer
:destroy-on-close="true" <!-- Cleanup on close -->
:close-on-click-modal="false" <!-- Don't close modal when clicking within drawer -->
:close-on-press-escape="false" <!-- Disable escape key to close the drawer -->
v-model="open"
size="60%" <!-- Set drawer width to 60% of viewport -->
>
<!-- Custom header slot -->
<template #header>
<!-- Drawer header content with translated text -->
<DrawerHeader :header="$t('menu.config')" :back="handleClose" />
</template>
<!-- Read-only textarea for displaying formatted JSON output -->
<el-input type="textarea" :autosize="{ minRows: 5, maxRows: 20 }" v-model="prettyJson"></el-input>
<!-- Copy button allowing users to copy the JSON content -->
<CopyButton :content="prettyJson" class="mt-2" />
<!-- Footer slot with cancel button -->
<template #footer>
<!-- Close button action that resets the state -->
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
</template>
</el-drawer>
</template>
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'; // Import i18n hook
import { DrawerHeader, CopyButton } from '@/components'; // Components import
import { AI } from '@/api/interface/ai';
import { ref } from 'vue';
// Define reactive variables
const open = ref(false); // Boolean to control visibility of drawer
const jsonObj = ref({
mcpServers: {}
});
// Computed property to generate pretty JSON string
const prettyJson = computed(() =>
JSON.stringify(jsonObj.value, null, 4)
);
// Function to handle closing of drawer
const handleClose = () => {
open.value = false; // Toggle drawer's visibility
};
/**
* Method to populate data into the configuration object based on MCP server details.
* @param mcpServer - Detailed information about an MCP server
*/
const acceptParams = (mcpServer: AI.McpServer): void => {
jsonObj.value.mcpServers[mcpServer.name] = {
url: `${mcpServer.baseUrl}${mcpServer.ssePath}`
};
if (mcpServer.environments) {
jsonObj.value.mcpServers[mcpServer.name].env = {};
for (const env of mcpServer.environments) {
jsonObj.value.mcpServers[mcpServer.name].env[env.key] = env.value;
}
}
// Update prettyJSON immediately after updating jsonObj
prettyJson.value = JSON.stringify(jsonObj.value, null, 4);
open.value = true; // Open drawer again to show updated config
};
// Expose methods to parent components
defineExpose({
acceptParams
});
</script>
<style scoped>
/* Any additional styles can be added here */
</style>Key Points:
-
Imports and Setup: Added necessary imports such as
useI18n(for handling internationalization), custom components (DrawerHeader,CopyButton), external API interface (AI), Vuex store (store), dependencies, Vue composition (setup), and lifecycle hooks (onMounted,computed, etc.). -
Computation Efficiency:
- Extracted computation outside of lifecycle hooks like
mounted()and directly usedref. This reduces redundant calculations and improves performance.
- Extracted computation outside of lifecycle hooks like
-
Code Comments: Provided inline comments for better explanation of what each part of the script does.
Feel free to adjust the styling (in <style> tag) according to your application theme preferences.
|
|
||
| onMounted(() => { | ||
| search(); | ||
| }); |
There was a problem hiding this comment.
The checked code does not have any major irregularities or significant potential issues. Here are some minor recommendations for improvement:
-
Table Column Width: The
min-widthproperty in several columns has been increased from120pxto200px, which might be preferable for larger screens. -
Popover and Button Text Lengths:
- For the error status popover, ensure that the text "连接错误" ("connection error") does not exceed three characters due to Chinese characters. If it exceeds this length, you may need to consider truncating ellipses or adjusting font sizes.
- Similarly, verify if the button labels like "启动/停止" and "日志" do not overflow in different screen sizes.
-
Mobile UI Adjustments:
- Ensure that the table column widths (
fixedWidth) and layout adjustments for mobile devices do not cause excessive scrolling when data is loaded dynamically on small screens without sufficient viewport space.
- Ensure that the table column widths (
-
Code Consistency:
- Inconsistent use of
max-width, especially on non-port column where using 50px seems more appropriate. - Some unused imports should be removed to keep the component clean and efficient.
- Inconsistent use of
Overall, the functionality appears robust and well-structured. If there's additional context about how specific functionalities will interact with these changes, further optimizations can be made accordingly.
| _ = syncMcpServerContainerStatus(mcpServer) | ||
| } | ||
|
|
||
| func syncMcpServerContainerStatus(mcpServer *model.McpServer) error { |
There was a problem hiding this comment.
The main changes between versions are:
-
In the
Updatemethod:- Added a line to save the updated
mcpServer. - Moved the call to
syncMcpServerContainerStatusinside a goroutine.
- Added a line to save the updated
-
In the
Createmethods:- Added a line to set
Statustoconstant.RuntimeStartingbefore saving. - Modified lines where status is being set from
constant.RuntimeNormaltoconstant.RuntimeStarting.
- Added a line to set
-
In the
Deletemethod, you've made no changes which is good practice.
These optimizations include asynchronous handling of container statuses and updating mcpServerRepo immediately after successful save operations to ensure data consistency. The other modifications maintain logical flow and correctness without introducing new bugs. If there were specific concerns about these changes, such as potential race conditions, they would need more detailed analysis based on broader system context.
|
/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.