Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure tool parameters are properly handled by reloading JSON #2698

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: ensure tool parameters are properly handled by reloading JSON --bug=1053980 --user=刘瑞斌 【应用】MCP节点的工具参数引用参数时,对话过程中参数值发生变化,MCP节点没有获取最新的参数值 https://www.tapd.cn/57709429/s/1676830

--bug=1053980 --user=刘瑞斌 【应用】MCP节点的工具参数引用参数时,对话过程中参数值发生变化,MCP节点没有获取最新的参数值 https://www.tapd.cn/57709429/s/1676830
Copy link

f2c-ci-robot bot commented Mar 26, 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.

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.

Copy link

f2c-ci-robot bot commented Mar 26, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

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

@@ -18,7 +18,8 @@ def save_context(self, details, workflow_manage):

def execute(self, mcp_servers, mcp_server, mcp_tool, tool_params, **kwargs) -> NodeResult:
servers = json.loads(mcp_servers)
params = self.handle_variables(tool_params)
params = json.loads(json.dumps(tool_params))
params = self.handle_variables(params)

async def call_tool(s, session, t, a):
async with MultiServerMCPClient(s) as client:
Copy link
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 is generally well-written and follows standard Python conventions, but there are a few improvements and suggestions to enhance clarity and performance:

  1. Unnecessary JSON Conversion: The line params = json.loads(json.dumps(tool_params)) does not add significant value because it converts the input to a string and then back to an object. This can introduce additional processing time.

  2. Variable Naming: Use descriptive variable names instead of single characters (s, session, etc.) to improve readability.

  3. Function Parameter Order: Ensure that function parameters are ordered consistently within their definitions.

  4. Asynchronous Function Usage: Since call_tool uses await, make sure all asynchronous operations (like json.loads) are awaited properly.

Here's a revised version of the code with these improvements:

@@ -18,7 +18,7 @@ def save_context(self, details, workflow_manage):
 
     async def execute(
         self,
         mcp_servers_json_str: str,
-        tool_params_dict: dict,
+        tool_params_json_str: str,
         **kwargs,
     ) -> NodeResult:
         try:
             # Load MCP server list from JSON string
             servers = json.loads(mcp_servers_json_str)

Additional Recommendations:

  • Error Handling: Consider adding error handling around JSON parsing and other operations to manage unexpected inputs gracefully.
  • Logging: Implement logging to track the execution flow and any errors encountered during operation.

These changes should help ensure better understanding and maintainability of the code.

@liuruibin liuruibin merged commit 601b03d into main Mar 26, 2025
4 of 5 checks passed
@liuruibin liuruibin deleted the pr@main@fix_deepcopy branch March 26, 2025 11:15
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.

2 participants