Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/locales/lang/en-US/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default {
},
mcpNode: {
label: 'MCP Server',
text: 'Call MCP Tools',
text: 'Call MCP Tools through SSE',
getToolsSuccess: 'Get Tools Successfully',
getTool: 'Get Tools',
tool: 'Tool',
Expand Down
4 changes: 2 additions & 2 deletions ui/src/locales/lang/zh-CN/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export default {
assign: '赋值'
},
mcpNode: {
label: 'MCP 节点',
text: '调用 MCP 工具',
label: 'MCP 调用',
text: '通过 SSE 方式执行 MCP 服务中的工具',
getToolsSuccess: '获取工具成功',
getTool: '获取工具',
tool: '工具',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code looks clean overall but can be enhanced for clarity and maintainability. Here are some suggestions:

  1. Consistent Label/Text Usage: Since both the label and text use "MCP", consider using label consistently throughout to avoid redundancy.

  2. Code Formatting: Ensure consistent indentation and spacing within objects and arrays.

  3. Comments: Add comments to explain complex logic or sections of code that might not be immediately self-explanatory.

  4. Documentation: If this code is part of an application or library, ensure it includes documentation or JSDoc to describe its purpose and usage.

Here's with these improvements applied:

export default {
  assignment: '赋值',

  mcpNode: {
    // Use a single key for label and text to improve consistency
    label: 'MCP调用',
    text: '通过 SSE方式执行 MCP服务中的工具',

    getToolsSuccess: '获取工具成功',
    getTool: '获取工具',
    tool: '工具',
  },
};

Key Changes:

  • Consistency in labeling (all keys starting with mcpNode)
  • Improved readability due to consistent indentation

These changes make the code more readable and maintainable while preserving the intended functionality.

Expand Down
4 changes: 2 additions & 2 deletions ui/src/locales/lang/zh-Hant/views/application-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export default {
assign: '賦值'
},
mcpNode: {
label: 'MCP 節點',
text: '呼叫 MCP 工具',
label: 'MCP 調用',
text: '透過SSE方式執行MCP服務中的工具',
getToolsSuccess: '獲取工具成功',
getTool: '獲取工具',
tool: '工具',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code has a small error in the text property of the mcpNode object. The correct phrase should be "透過SSE方式執行MCP服務中的工具" instead of "呼叫 MCP 工具". Here is the corrected code:

export default {
  assign: '賦值',
},
mcpNode: {
  label: 'MCP 調用',
  text: '透過 SSE 方式執行 MCP 服務中的工具', // Corrected here
  getToolsSuccess: '獲取工具成功',
  getTool: '獲取工具',
  tool: '工具'
}

This change ensures clarity and accuracy in describing the functionality described as "through SSE method to execute tools within the MCP service."

Expand Down
20 changes: 15 additions & 5 deletions ui/src/workflow/nodes/mcp-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,21 @@ const validate = async () => {

if (requiredFields.length > 0) {
for (const item of requiredFields) {
if (!form_data.value.tool_params[form_data.value.params_nested][item]) {
return Promise.reject({
node: props.nodeModel,
errMessage: item + t('dynamicsForm.tip.requiredMessage')
})
if (form_data.value.params_nested) {
if (!form_data.value.tool_params[form_data.value.params_nested][item]) {
return Promise.reject({
node: props.nodeModel,
errMessage: item + t('dynamicsForm.tip.requiredMessage')
})
}
} else {
// 这里是没有嵌套的情况
if (!form_data.value.tool_params[item]) {
return Promise.reject({
node: props.nodeModel,
errMessage: item + t('dynamicsForm.tip.requiredMessage')
})
}
}
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Your code is generally clean, but there are a few areas that could be improved:

  1. Check for empty form_data.value.tool_params: It's good to ensure that tool_params is not undefined before attempting to access its nested properties. Adding a nullish coalescing operator (??) can help avoid errors in case this happens.

  2. Consistent use of variables: The variable name node_model is used twice; you might want to standardize it or explain its usage better.

  3. Use meaningful comments: While your existing comments are helpful, adding some additional explanations like what each section does would make the code even clearer.

Here’s the refactored version with these improvements:

const validate = async () => {
  if (requiredFields.length > 0) {
    for (const item of requiredFields) {
      // Check if form_data.value.tools_params exists and contains the specified item
      if (form_data && form_data.tool_params && form_data.tool_params.form_data_nested && !form_data.tool_params.form_data_nested[item]) {
        return Promise.reject({
          node: props.nodeModel,
          errMessage: item + t('dynamicsForm.tip.requiredMessage')
        });
      }

      // For non-nested params
      if (form_data && form_data.tool_params && !form_data.tool_params[item]) {
        return Promise.reject({
          node: props.nodeModel,
          errMessage: item + t('dynamicsForm.tip.requiredMessage')
        });
      }
    }
  }
};

This code includes checks for both nested and non-nested cases, ensuring that the application handles scenarios where either structure might be missing.

Expand Down